Package org.jbpm

Examples of org.jbpm.JbpmContext


      "</jbpm-configuration>"
    );
  }
 
  public void testAllServices() {
    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
    try {
      jbpmContext.getServices().getService("two");
      jbpmContext.getServices().getService("four");
      jbpmContext.getServices().getService("one");
      jbpmContext.getServices().getService("three");
    } finally {
      jbpmContext.close();
    }
   
    assertEquals("one", closedServices.get(0));
    assertEquals("two", closedServices.get(1));
    assertEquals("three", closedServices.get(2));
View Full Code Here


    assertEquals("three", closedServices.get(2));
    assertEquals("four", closedServices.get(3));
  }

  public void testTwoOutOfFour() {
    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
    try {
      jbpmContext.getServices().getService("three");
      jbpmContext.getServices().getService("two");
    } finally {
      jbpmContext.close();
    }
   
    assertEquals("two", closedServices.get(0));
    assertEquals("three", closedServices.get(1));
  }
View Full Code Here

  }

  public boolean executeCommand() throws Throwable {
    boolean checkForMoreMessages = false;
    Message message = null;
    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(jbpmContextName);
    try {
      // get a command from the queue
      DbMessageService dbMessageService = null;
      try {
        dbMessageService = (DbMessageService) jbpmContext.getServices().getMessageService();
      } catch (ClassCastException e) {
        throw new ConfigurationException("CommandExecutorThread only works with the DbMessageService implementation of the MessageService. please, configure jbpm.cfg.xml accordingly.");
      }
      if (dbMessageService==null) {
        throw new ConfigurationException("no messaging service available");
      }
      message = dbMessageService.receiveNoWait(destination);
     
      if (message!=null) {
        checkForMoreMessages = true;
        Command command = (Command) message;
        log.trace("executing command '"+command+"'");
        command.execute();
      }
     
    } catch (Throwable t) {
      // rollback the transaction
      log.debug("command '"+message+"' threw exception. rolling back transaction", t);
      jbpmContext.setRollbackOnly();
     
      if (message!=null) {
        throw new MessageProcessingException(message, t);
      } else {
        throw t;
      }
    } finally {
      jbpmContext.close();
    }
   
    return checkForMoreMessages;
  }
View Full Code Here

   
    return checkForMoreMessages;
  }
 
  void handleProcessingException(MessageProcessingException e) {
    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(jbpmContextName);
    try {
      // get the message session from the context
      DbMessageService dbMessageSessionImpl = (DbMessageService) jbpmContext.getServices().getMessageService();
      MessagingSession messageSession = dbMessageSessionImpl.getMessagingSession();

      // get the problematic command message from the exception
      Message message = e.message;

      // remove the problematic message from the queue
      dbMessageSessionImpl.receiveByIdNoWait(message.getId());
     
      message = Message.createCopy(message);

      // update the message with the stack trace
      StringWriter sw = new StringWriter();
      e.printStackTrace(new PrintWriter(sw));
      message.setException(sw.toString());

      // update the message with the jbpm-error-queue destination
      message.setDestination(errorDestination);
     
      // resend
      messageSession.save(message);

    } finally {
      jbpmContext.close();
    }
  }
View Full Code Here

   return getCurrentService(name, true);
  }
 
  public static Service getCurrentService(String name, boolean isRequired) {
    Service service = null;
    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
    if (jbpmContext!=null) {
      service = jbpmContext.getServices().getService(name);
    }
    if (isRequired && (service==null)) {
      throw new JbpmServiceException("service '"+name+"' unavailable");
    }
    return service;
View Full Code Here

      }
    }
  }

  public static void assignId(Object object) {
    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
    if (jbpmContext!=null) {
      // give this process instance an id
      Services services = jbpmContext.getServices();
      if (services.hasService(Services.SERVICENAME_PERSISTENCE)) {
        PersistenceService persistenceService = services.getPersistenceService();
        persistenceService.assignId(object);
      }
    }
View Full Code Here

                if (jobDataMap != null)
                {
                    final Long jobId = (Long) jobDataMap.get(TIMER_ID) ;
                    if (jobId != null)
                    {
                        final JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext() ;
                        Job job = null ;
                        try
                        {
                            job = jbpmContext.getJobSession().loadJob(jobId) ;
                            if (job != null)
                            {
                                jbpmContext.getServices().getMessageService().send(job) ;
                                if (LOGGER.isDebugEnabled())
                                {
                                    LOGGER.debug("Firing job " + jobId) ;
                                }
                                return ;
                            }
                        }
                        catch (final RuntimeException re)
                        {
                            final Integer maxRefireCount = (Integer) jobDataMap.get(MAX_REFIRE_COUNT) ;
                            if ((maxRefireCount != null) && (maxRefireCount > context.getRefireCount()))
                            {
                                final JobExecutionException jobEx = new JobExecutionException(re, true);
                                jobEx.setErrorCode(JobExecutionException.ERR_JOB_EXECUTION_THREW_EXCEPTION);
                                throw jobEx ;
                            }
                            else
                            {
                                if (job != null)
                                {
                                    // zero the retries to remove from the list of outstanding jobs.
                                    job.setRetries(0) ;
                                }
                                throw re ;
                            }
                        }
                        finally
                        {
                            jbpmContext.close() ;
                        }
                    }
                }
            }
            if (LOGGER.isDebugEnabled())
View Full Code Here

        {
            log.debug("Processing message " + message) ;
        }
        try
        {
            final JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
            try
            {
                // extract command from message
                Command command = extractCommand(message);
                if (log.isDebugEnabled())
                {
                    log.debug("Extracted command " + command) ;
                }
                if (command == null)
                {
                    discard(jbpmContext, message);
                    return;
                }
                final Object result = command.execute(jbpmContext);
                // send a response back if a "reply to" destination is set
                final Destination replyTo = message.getJMSReplyTo();
                if (replyTo != null && (result instanceof Serializable || result == null))
                {
                    sendResult(jbpmContext, (Serializable)result, replyTo, message.getJMSMessageID());
                }
                if (log.isDebugEnabled())
                {
                    log.debug("Executed command " + command) ;
                }
                jbpmContext.getSession().flush() ;
            }
            finally
            {
                final TxService txService = jbpmContext.getServices().getTxService() ;
                final boolean exceptionExpected = txService.isRollbackOnly() ;
                try
                {
                    jbpmContext.close() ;
                }
                catch (final JbpmException je)
                {
                    if (exceptionExpected)
                    {
View Full Code Here

        final JobExecutor jobExecutor = jbpmConfiguration.getJobExecutor() ;
        if (jobExecutor != null)
        {
            jobExecutor.start() ;
        }
        final JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext() ;
        jbpmContext.close() ;
        super.startService();
    }
View Full Code Here

                logger.debug("Signaling task " + tokenId + " from process instance " +
                    token.getProcessInstance().getId()) ;
            }
            final ProcessInstance processInstance = token.getProcessInstance() ;
            final ContextInstance contextInstance = processInstance.getContextInstance() ;
            final JbpmContext jbpmContext = executionContext.getJbpmContext() ;
            final String transitionName = (String)removeVariableLocally(jbpmContext, contextInstance, ESB_ASYNC_SIGNAL_TRANSITION_VARIABLE_NAME, token) ;
            final String actor = (String)removeVariableLocally(jbpmContext, contextInstance, ESB_ASYNC_SIGNAL_ACTOR_VARIABLE_NAME, token) ;
            final String origActor = jbpmContext.getActorId() ;
           
            final int variableCount = Integer.parseInt((String)removeVariableLocally(jbpmContext, contextInstance, ESB_ASYNC_SIGNAL_VARIABLE_COUNT, token)) ;
            for(int count = 0 ; count < variableCount ; count++)
            {
                final String name = (String)removeVariableLocally(jbpmContext, contextInstance, ESB_ASYNC_SIGNAL_VARIABLE_NAMES + count, token) ;
                final Object value = removeVariableLocally(jbpmContext, contextInstance, name, token) ;
                contextInstance.setVariable(name, value) ;
            }
           
            try
            {
                if (actor != null)
                {
                    jbpmContext.setActorId(actor) ;
                }
                final SignalCommand signalCommand = new SignalCommand(tokenId, transitionName) ;
                signalCommand.execute(jbpmContext) ;
            }
            finally
            {
                jbpmContext.setActorId(origActor) ;
            }
            if (isDebugEnabled)
            {
                logger.debug("Signalled task " + tokenId + " from process instance " +
                    token.getProcessInstance().getId()) ;
View Full Code Here

TOP

Related Classes of org.jbpm.JbpmContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.