Package org.openbp.server.context

Examples of org.openbp.server.context.TokenContextService


  /**
   * Run method.
   */
  public void run()
  {
    TokenContextService tokenContextService = engineRunner.getEngine().getTokenContextService();
    TokenContext context = tokenContextService.getContextById(contextId);

    String oldThreadName = null;
    try
    {
      engineRunner.increaseNumberOfExecutingContexts();

      // Note that the Runnable might be invoked at a time when this same context
      // has already been processed or deleted.
      // Check if the context still exists and if its request and state are ok.
      if (context == null)
      {
        LogUtil.debug(getClass(), "Trying to run non-existing context with id $0.", contextId);
        return;
      }
      if (context.getLifecycleRequest() != LifecycleRequest.RESUME)
      {
        LogUtil.debug(getClass(), "Trying to run context that does not have a resumption request: $0.", context);
        return;
      }
      if (context.getLifecycleState() != LifecycleState.SELECTED)
      {
        LogUtil.debug(getClass(), "Trying to run context that has not been selected for execution: $0.", context);
        return;
      }

      // Set the name of the executing thread: Either process variable value or short name
      Object objThreadName = context.getProcessVariableValue(CoreConstants.PROCESSVAR_THREAD_NAME);
      if (objThreadName != null)
      {
        String threadName = objThreadName.toString();
        oldThreadName = Thread.currentThread().getName();
        Thread.currentThread().setName("Context execution (" + threadName + ")");
      }

      engineRunner.getEngine().executeContext(context);
    }
    catch (Throwable t)
    {
      boolean handled = false;
      EngineRunnerExceptionHandler handler = engineRunner.getEngineRunnerExceptionHandler();
      if (handler != null)
      {
        handled = handler.handleException(context, t);
      }

      if (! handled)
      {
        LogUtil.error(getClass(), "Unhandled error occured while executing a process.", t);
      }
    }
    finally
    {
      if (oldThreadName != null)
      {
        Thread.currentThread().setName(oldThreadName);
      }

      engineRunner.decreaseNumberOfExecutingContexts();
      tokenContextService.clearCache();
    }
  }
View Full Code Here


    {
      memProcessVariables = copyProcessVariables(memContext, engine.getPersistenceContextProvider());
    }

    // Perform transaction rollback and get rid of the rollback-invalid persistence context
    TokenContextService contextService = engine.getTokenContextService();
    contextService.evictContext(memContext);
    engine.rollback();

    // Retrieve the current version of the context
    engine.begin();
    TokenContext dbContext = contextService.getContextById(contextId);
    boolean updateContext = false;

    if (rollbackPositionBehavior == RollbackPositionBehavior.MAINTAIN_POSITION)
    {
      // Maintain the current position, so update the DB context from the memory context.
      dbContext.setCurrentSocket (memCurrentSocket);
      dbContext.setCallStack (memCallStack);
      dbContext.setPriority (memPriority);
      dbContext.setQueueType (memQueueType);
      dbContext.setProgressInfo (memProgressInfo);
      updateContext = true;
    }

    if (memProcessVariables != null)
    {
      for (Iterator it = memProcessVariables.entrySet().iterator(); it.hasNext();)
      {
        Map.Entry entry = (Map.Entry) it.next();
        String varName = (String) entry.getKey();
        Object value = entry.getValue();
        value = PersistenceContextObjectSerializer.resolveSerializableObjectReference(value, dbContext, varName, engine.getPersistenceContextProvider());

        if (rollbackDataBehavior == RollbackDataBehavior.UPDATE_VARIABLES)
        {
          // Update the DB context with the variable value of the memory context
          dbContext.setProcessVariableValue(varName, value);
          updateContext = true;
        }
        else
        {
          // Add new variables of the memory context to the DB context
          if (dbContext.getProcessVariableValue(varName) == null)
          {
            if (value != null)
            {
              dbContext.setProcessVariableValue(varName, value);
              updateContext = true;
            }
          }
        }
      }
    }

    if (updateContext)
    {
      contextService.saveContext(dbContext);
      if (isCommitTokenContextChangesEnabled())
      {
        engine.commit();
      }
    }
View Full Code Here

    Map<String, Object> outputParam = new HashMap<String, Object>();
    getProcessFacade().retrieveOutputParameters(token, outputParam);

    // Since we cleared the 'delete process after completion' flag, we need to delete the process manually.
    TokenContextService tcs = processServer.getTokenContextService();
    tcs.deleteContext(token);
   
    return (String) outputParam.get("ErrMsg");
  }
View Full Code Here

TOP

Related Classes of org.openbp.server.context.TokenContextService

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.