Package org.openbp.server.context

Examples of org.openbp.server.context.TokenContext


    // Instantiate and fill the map to provide parameters
    Map params = null;

    // Create a new token that we can execute
    TokenContext token = processFacade.createToken();
    token.setDebuggerId("Deb1");

    // Start the token using the provided parameters
    processFacade.startToken(token, pos, params);
    pos = null;

    for (;;)
    {
      // Invoke the process
      if (pos != null)
      {
        // We have a position to continue the process with, so apply it
        processFacade.resumeToken(token, pos, null);
      }

      // Make the process engine execute all pending contexts and wait until there is all contexts have been executed.s have been executed.s have been executed.
      processFacade.executePendingContextsInThisThread();

      // See where we are
      if (token.getCurrentSocket() == null)
      {
        System.out.println("Process ended normally.");
        return false;
      }
      Node node = token.getCurrentSocket().getNode();

      if (node instanceof WaitStateNode)
      {
        System.out.println("Wait state node " + node.getName() + " encountered.");
      }
View Full Code Here


   * will be assigned to the 'AcceptingUser' property of the workflow and to the 'UserId' of the workflow
   * if the 'AssignToCurrentUser' property of the workflow has been set.
   */
  public void resumeWorkflow(final WorkflowTask workflowTask, final String socketName, final String currentUserId)
  {
    TokenContext context = workflowTask.getTokenContext();

    context = workflowTask.getTokenContext();

    NodeSocket workflowEntrySocket = context.getCurrentSocket();
    WorkflowNode workflowNode = (WorkflowNode) workflowEntrySocket.getNode();

    NodeSocket nextSocket = resolveSocketRef(socketName, workflowEntrySocket, context, true);
    context.setCurrentSocket(nextSocket);
    context.setLifecycleRequest(LifecycleRequest.RESUME);
    tokenContextService.saveContext(context);

    if (workflowNode != null)
    {
      if (workflowNode.isAssignToCurrentUser())
View Full Code Here

    // End all child contexts.
    // Copy the list in order to prevent a concurrent modification exception
    for (Iterator it = tokenContextService.getChildContexts(context); it.hasNext();)
    {
      TokenContext childContext = (TokenContext) it.next();
      endToken(childContext);
    }

    TokenContext parentContext = context.getParentContext();
    if (parentContext != null)
    {
      parentContext.removeChildContext(context);
    }
    context.setParentContext(null);

    for (Iterator itTask = tokenContextService.getworkflowTasks(criteria); itTask.hasNext();)
    {
View Full Code Here

   *
   * @param event Engine event to dispatch
   */
  public void fireEngineEvent(final EngineEvent event)
  {
    TokenContext context = event.getContext();
    context.fireEngineEvent(event);
    if (! event.shallSkipSubsequentObservers())
    {
      getObserverMgr().fireEvent(event);
    }
  }
View Full Code Here

   * @param ec The engine context to run on
   */
  public void performRollback(EngineContext ec)
  {
    Engine engine = ec.getEngine();
    TokenContext memContext = ec.getTokenContext();
    Object contextId = memContext.getId();

    // Save variable values before we perform the rollback
    NodeSocket memCurrentSocket = memContext.getCurrentSocket();
    int memPriority = memContext.getPriority();
    String memQueueType = memContext.getQueueType();
    CallStack memCallStack = null;
    ProgressInfo memProgressInfo = null;
    Map memProcessVariables = null;
    try
    {
      if (rollbackPositionBehavior == RollbackPositionBehavior.MAINTAIN_POSITION)
      {
        memCallStack = (CallStack) CopyUtil.copyObject(memContext.getCallStack(), Copyable.COPY_DEEP, null);
        memProgressInfo = (ProgressInfo) CopyUtil.copyObject(memContext.getProgressInfo(), Copyable.COPY_DEEP, null);
      }
    }
    catch (CloneNotSupportedException e)
    {
      String msg = LogUtil.error(getClass(), "Error cloning token. [{0}]", memContext, e);
      throw new EngineException("NoDefaultExitSocket", msg);
    }
    if (rollbackDataBehavior == RollbackDataBehavior.UPDATE_VARIABLES || rollbackDataBehavior == RollbackDataBehavior.ADD_VARIABLES)
    {
      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;
            }
          }
        }
      }
View Full Code Here

   * @param ee Engine executor that called this method
   * @throws OpenBPException On error
   */
  public void executeModelObject(ModelObject mo, EngineExecutor ee)
  {
    TokenContext context = ee.getTokenContext();
    NodeSocket entrySocket = context.getCurrentSocket();
    ActivityNode node = (ActivityNode) entrySocket.getNode();

    NodeSocket nextSocket = node.getDefaultExitSocket();

    // Activity reference missing, try the node's handler
    TokenContext oldContext = context;
    HandlerContext hc = getEngine().executeHandler(node.getActivityHandlerDefinition(), HandlerTypes.ACTIVITY, context, context.getCurrentSocket(), nextSocket);
    if (hc != null)
    {
      context = hc.getTokenContext();
      if (context != oldContext)
View Full Code Here

   * @param ee Engine executor that called this method
   * @throws OpenBPException On error
   */
  public void executeModelObject(ModelObject mo, EngineExecutor ee)
  {
    TokenContext context = ee.getTokenContext();
    NodeSocket entrySocket = context.getCurrentSocket();
    VisualItem visual = (VisualItem) mo;

    NodeSocket nextSocket = null;

    // Check, whether we've a dynamic visual we should execute instead of this visual.
    VisualItem dynamicVisual = determineDynamicVisual(visual, context, entrySocket);

    if (dynamicVisual != this)
    {
      // Delegate execution to the dynamic visual.
      visual = dynamicVisual;
    }

    // Execute the visual implementation
    try
    {
      String visualType = "external";
      String exitSocketName = UIAdapterCache.getInstance().executeVisual(visualType, visual, context, entrySocket);
      if (exitSocketName != null)
      {
        // Return value of activity execution is the name of the exit socket
        // Determine the corresponding exit socket using the usual search strategy
        // Note that visuals for asynchronous protocols like HTTP don't return an exit name.
        nextSocket = getEngine().resolveSocketRef(exitSocketName, entrySocket, context, true);
      }
    }
    catch (OpenBPException e)
    {
      // The exception can be rethrown as is.
      throw e;
    }
    catch (Throwable t)
    {
      String msg = LogUtil.error(getClass(), "Error executing visual $0. [{1}]", visual.getName(), t, context);
      throw new EngineException("VisualExecutionFailed", msg, t);
    }

    context.setCurrentSocket(nextSocket);
  }
View Full Code Here

   * @param ee Engine executor that called this method
   * @throws OpenBPException On error
   */
  public void executeModelObject(ModelObject mo, EngineExecutor ee)
  {
    TokenContext context = ee.getTokenContext();
    NodeSocket entrySocket = context.getCurrentSocket();
    FinalNode node = (FinalNode) entrySocket.getNode();

    NodeSocket nextSocket = null;

    String jumpTarget = (String) TokenContextUtil.getParamValue(context, entrySocket, CoreConstants.DYNAMIC_JUMPTARGET_PARAM_NAME);
    if (jumpTarget == null)
      jumpTarget = node.getJumpTarget();

    if (jumpTarget != null)
    {
      // Execute a jump target final node
      nextSocket = executeJumpTargetFinalNode(entrySocket, context, jumpTarget);
    }
    else
    {
      // Execute a regular return final node
      nextSocket = executeReturnFinalNode(node, entrySocket, context);
    }

    if (nextSocket != null)
    {
      // Copy the data of the exit socket of the sub process in the
      // sub process context to the exit socket of this activity in the current context
      EngineUtil.copySocketData(entrySocket, context, nextSocket, context);

      context.setCurrentSocket(nextSocket);
    }
    else
    {
      // Our token ends here
      context.setLifecycleRequest(LifecycleRequest.STOP);
    }
  }
View Full Code Here

   */
  @Transactional(propagation = Propagation.REQUIRED)
  public Object startProcess(VacationData data)
  {
    // Create the process context and start the process
    TokenContext token = getProcessFacade().createToken();
    // We need to retrieve the process' output parameters, so do not delete the process after it has completed.
    token.setDeleteAfterCompletion(false);
    token.setDebuggerId("Deb1");

    // Start the process
    Map<String, Object> inputParam = new HashMap<String, Object>();
    inputParam.put("Data", data);
    getProcessFacade().startToken(token, "/VacationRequest/HandleVacationRequest.Start", inputParam);

    // Note: We do not have asynchronous processing in the workflow, so we use blocking execution
    // (i. e. execute the process right here in this thread).
    // Otherweise, the execution would have to be done by some worker thread (blocking execution).
    getProcessFacade().executePendingContextsInThisThread();

    return token.getId();
  }
View Full Code Here

   */
  @Transactional(propagation = Propagation.REQUIRED)
  public void resumeProcess(Object tokenId, String resumptionCode, Map<String, Object> resumptionParam)
  {
    // Re-load the token from the database
    TokenContext token = getProcessFacade().getTokenById(tokenId);

    // Now resume the process
    getProcessFacade().resumeToken(token, resumptionCode, resumptionParam);

    // Again, we will cause the engine to execute pending threads before we continue.
View Full Code Here

TOP

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

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.