0 Replies Latest reply on Dec 19, 2013 7:32 AM by Vladimir Belyakof

    The signal from one process to another

    Vladimir Belyakof Newbie

      Hello. I have the following problem. I need to implement a mechanism that one process can send a signal to other processes. I use this code.

      But get an error.

      Please tell me how I can implement this mechanism.

       

      Error:

      ERROR [org.jboss.as.ejb3.invocation] (http-/0.0.0.0:8080-3) JBAS014134: EJB Invocation failed on component ProcessBean for method public abstract void ru.koronalift.ejb.ProcessLocal.signal(java.lang.String,java.lang.Object,long) throws java.lang.Exception: javax.ejb.EJBException: java.lang.RuntimeException: Process instance 1[Первое_приближение] is disconnected.


      Code:

      public class SignalHandler implements WorkItemHandler {

         

          @Override

          public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

              InitialContext context = null;

             

              try {

                  context = new InitialContext();

                  BdService bdService = (BdService) context.lookup(StringData.JNDI_NAME_BDSERVISE);

                  Long idCurrentBid = Long.parseLong((String) workItem.getParameters().get(StringData.ID_CURRENT_BID));

       

                  final Bid bid = bdService.get(Bid.class, idCurrentBid);

                  idCurrentBid = bid.getProcessId();

       

                  final Map<String, Object> response = new HashMap<String, Object>();

                 

                  // Thread to access the signal servlet (process).

                  new Thread(new Runnable() {

                     

                      @Override

                      public void run() {

                          URL url;

                          String lineUrl = BaseBd.getUrlPath() + PROCESS_SCRIPT_PAGE;

                          String lineParameters = PARAM_NAME_SIGNAL_NAME + PARAMETR_ASSIGNMENT + PARAMETER_SIGNAL_TYPE_INNER_CALL + PARAMETR_SEPARATOR +

                                  PARAM_NAME_PROC_START_SIGNAL + PARAMETR_ASSIGNMENT + bid.getProcessId();

       

                          try {

                              url = new URL(lineUrl);

                              HttpURLConnection connection = (HttpURLConnection)url.openConnection();

                              connection.setInstanceFollowRedirects(false);

                              connection.setDoOutput(true);

                              OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());

                              writer.write(lineParameters);

                              writer.flush();

                              String line;

                              BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

                              StringBuilder strBuffer = new StringBuilder();

                              while ((line = reader.readLine()) != null) {

                                strBuffer.append(line);

                              }

                              response.put(StringData.RESPONSE, strBuffer);

                              writer.close();

                              reader.close();

                          } catch (MalformedURLException e) {

                              System.err.println(e.getMessage() + COLON + MESSAGE_INCORRECT_URL + lineUrl);

                              e.printStackTrace();

                          } catch (IOException e) {

                              System.err.println(e.getMessage() + COLON + lineParameters);

                              e.printStackTrace();

                          }

                      }

                  }).start();

                 

                  manager.completeWorkItem(workItem.getId(), null);

              } catch (NamingException e) {

                  new Throwable(e);

              }

         }

       

          @Override

          public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {

          }

       

      }


      public class ProcessBean implements ProcessLocal {

       

           .................

       

          @Override

          public void signal(String type, Object event, long procId) throws Exception {

              RuntimeEngine runtime = singletonManager.getRuntimeEngine(EmptyContext.get());

              KieSession ksession = runtime.getKieSession();

              ksession.signalEvent(type, event, procId);

              InitServlet.сurrentServlet.log("-------------- SIgnal send. Type: " + type + ", event: " + event +  ", procId: " + procId);

          }

      }