Examples of TokenContext


Examples of org.openbp.server.context.TokenContext

    return null;
  }

  public static TokenContext rollbackAndContinue(TokenContext contextArg, int rollbackDataBehavior, int rollbackPositionBehavior, Engine engine)
  {
    TokenContext memContext = contextArg;
    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(EngineUtil.class, "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
    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

Examples of org.openbp.server.context.TokenContext

      if (tokenId != null)
      {
        try
        {
          ProcessFacade processFacade = processServer.getProcessFacade();
          TokenContext tc = processFacade.getTokenById(tokenId);
          desc.setTokenContext(tc);
        }
        catch (Exception e)
        {
          String msg = LogUtil.error(getClass(), "Cannot find the scheduled token context (id $0) for job $1.", tokenId,
View Full Code Here

Examples of org.openbp.server.context.TokenContext

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

    NodeSocket nextSocket = null;

    TokenContext oldContext = context;
    HandlerContext hc = getEngine().executeHandler(activity.getHandlerDefinition(), HandlerTypes.ACTIVITY, context, context.getCurrentSocket(), nextSocket);
    if (hc != null)
    {
      context = hc.getTokenContext();
      if (context != oldContext)
View Full Code Here

Examples of org.openbp.server.context.TokenContext

   * @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();
    DecisionNode node = (DecisionNode) entrySocket.getNode();

    boolean result = false;

    String expression = node.getExpression();
    if (expression != null)
    {
      // Evaluate a script expression
      ScriptEngine scriptEngine = getEngine().getScriptEngineFactory().obtainScriptEngine(context);
      try
      {
        // Evaluate the expression
        scriptEngine.prepareNodeSocketExecution(entrySocket);
        Object value = scriptEngine.executeScript(expression, "Decision node script", entrySocket.getNode()
                              .getQualifier().toString());
        scriptEngine.finishNodeSocketExecution(entrySocket);

        // Assign the result to the parameter
        if (value != null && ! value.equals(Boolean.FALSE))
          result = true;
      }
      finally
      {
        getEngine().getScriptEngineFactory().releaseScriptEngine(scriptEngine);
      }
    }

    String socketName = result ? CoreConstants.SOCKET_YES : CoreConstants.SOCKET_NO;
    NodeSocket nextSocket = getEngine().resolveSocketRef(socketName, entrySocket, context, true);
    context.setCurrentSocket(nextSocket);
  }
View Full Code Here

Examples of org.openbp.server.context.TokenContext

        case ControlLink.TA_ROLLBACK_BEGIN:
        begin = true;
        // Fallthrough

        case ControlLink.TA_ROLLBACK:
        TokenContext newContext = EngineUtil.rollbackAndContinue(context, link.getRollbackDataBehavior(), link.getRollbackPositionBehavior(), engine);
        if (newContext != null)
          context = newContext;
        break;
      }
View Full Code Here

Examples of org.openbp.server.context.TokenContext

   * @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();
    ForkNode node = (ForkNode) entrySocket.getNode();

    NodeSocket defaultOutSocket = node.getDefaultExitSocket();
    if (defaultOutSocket == null)
    {
      String msg = LogUtil.error(getClass(), "No default exit socket present for fork node $0. [{1}]", node.getQualifier(), context);
      throw new EngineException("NoDefaultExitSocket", msg);
    }

    Object collectionParamValue = TokenContextUtil.getParamValue(context, entrySocket, CoreConstants.FORK_COLLECTION_PARAM);
    if (collectionParamValue != null)
    {
      // Automatic fork node based on input collection
      if (defaultOutSocket.getParamByName(CoreConstants.FORK_COLLECTION_ELEMENT_PARAM) == null)
      {
        String msg = LogUtil.error(getClass(), "Fork node having a $0 input parameter requires a $1 output parameter. [{2}]", CoreConstants.FORK_COLLECTION_PARAM, CoreConstants.FORK_COLLECTION_ELEMENT_PARAM, context);
        throw new EngineException("NoCollectionElementForFork", msg);
      }

      Iterator it = CollectionUtil.iterator(collectionParamValue);
      while (it.hasNext())
      {
        Object collectionElement = it.next();

        // Create a new child context
        TokenContext childContext = getEngine().getTokenContextService().createChildContext(context);

        // Provide the collection element to it
        Param outParam = defaultOutSocket.getParamByName(CoreConstants.FORK_COLLECTION_ELEMENT_PARAM);
        if (outParam != null)
        {
          // If the exit socket contains a 'WorkflowTask' parameter, set it
          TokenContextUtil.setParamValue(childContext, outParam, collectionElement);
        }

        // Copy the data of the node entry socket in the current context
        // to the exit socket in the child context.
        EngineUtil.copySocketData(entrySocket, context, defaultOutSocket, childContext);

        childContext.setCurrentSocket(defaultOutSocket);
        getEngine().resumeToken(childContext);
      }
    }
    else
    {
      // Iterate all exit sockets
      for (Iterator itOutSockets = node.getSockets(false); itOutSockets.hasNext();)
      {
        final NodeSocket outSocket = (NodeSocket) itOutSockets.next();

        if (outSocket.getName().equals(CoreConstants.FORK_RESUME))
          continue;

        // Create a new child context
        TokenContext childContext = getEngine().getTokenContextService().createChildContext(context);

        // Copy the data of the node entry socket in the current context
        // to the exit socket in the child context.
        EngineUtil.copySocketData(entrySocket, context, outSocket, childContext);

        childContext.setCurrentSocket(outSocket);
        getEngine().resumeToken(childContext);
      }
    }

    // When there is a 'Resume' exit socket, let's continue there; otherwise simply end
View Full Code Here

Examples of org.openbp.server.context.TokenContext

    }

    DebuggerClient breakClient = null;

    // Check if this token context already runs under control of a debugger client
    TokenContext context = event.getTokenContext();
    String clientId = context.getDebuggerId();
    if (clientId != null)
    {
      DebuggerClient client = getClient(clientId);
      if (client == null)
      {
        // There is a client id referenced in the token context, but no such client
        if (waitForDebugger)
        {
          client = waitForDebuggerClient(clientId);
        }
        else
        {
          // Remove the id from the context and continue the process
          context.setDebuggerId(null);
          return;
        }
      }

      int mode = client.getDebuggerMode();

      if (eventType.equals(EngineTraceEvent.PROCESS_EXCEPTION))
      {
        // An exeception occurred during process execution
        if ((mode & MODE_BREAK_ON_EXCEPTION) != 0)
        {
          breakClient = client;
        }
      }

      if (breakClient == null)
      {
        if (stopAtFirstEvent)
        {
          stopAtFirstEvent = false;
          breakClient = client;
        }
        if (stopAtAnyEvent)
        {
          breakClient = client;
        }

        // First, check if we ran onto a breakpoint set by this client
        if (pos1 != null)
        {
          Breakpoint bp = client.getActiveBreakpoint(pos1);
          if (bp != null)
          {
            breakClient = client;

            if ((bp.getState() & Breakpoint.STATE_TEMPORARY) != 0)
            {
              // Clear temporary breakpoint
              client.clearBreakpoint(pos1);
            }
          }
        }

        if (breakClient == null && pos2 != null)
        {
          Breakpoint bp = client.getActiveBreakpoint(pos2);
          if (bp != null)
          {
            breakClient = client;

            if ((bp.getState() & Breakpoint.STATE_TEMPORARY) != 0)
            {
              // Clear temporary breakpoint
              client.clearBreakpoint(pos2);
            }
          }
        }

        // Check if we enter a top-level process
        if (breakClient == null && (mode & MODE_BREAK_ON_TOP_LEVEL) != 0 && eventType.equals(EngineTraceEvent.NODE_EXIT)
          && event.getNode() instanceof InitialNode && context.getCallStack().getCallDepth() == 0)
        {
          // Yes, we are at the exit socket of an initial node of a top level process
          // Check if there is a 'break on top level' client
          breakClient = client;
        }

        // Check if we accepted a workflow task
        if (breakClient == null && (mode & MODE_BREAK_ON_WORKFLOW) != 0 && eventType.equals(EngineTraceEvent.NODE_EXIT)
          && event.getNode() instanceof WorkflowNode && event.getNodeSocket().isDefaultSocket())
        {
          // Yes, we are leaving a worklfow node at the default socket
          // (meaning we accepted a workflow task)
          breakClient = client;
        }

        if (breakClient == null)
        {
          // We have no breakpoint set by this client, now check if there is
          // a command pending we need to follow

          // Check if the current command applies to the current position
          int command = client.getNextCommand();

          if (command == CMD_STEP_NEXT)
          {
            // The step next command halts for any events
            breakClient = client;
          }
          else if (command == CMD_STEP_INTO)
          {
            // The step into command
            if (eventType.equals(EngineTraceEvent.NODE_ENTRY))
              breakClient = client;
          }
          else if (command == CMD_STEP_OVER)
          {
            // The step over command
            // Check if the current call level <= call level at time when the command was issued
            if (eventType.equals(EngineTraceEvent.NODE_ENTRY))
            {
              int depth = context.getCallStack().getCallDepth();
              int commandDepth = client.getCallDepth();
              if (depth <= commandDepth)
              {
                breakClient = client;
              }
            }
          }
          else if (command == CMD_STEP_OUT)
          {
            // The step out command
            // Check if the current call level < call level at time when the command was issued
            if (eventType.equals(EngineTraceEvent.NODE_ENTRY))
            {
              int depth = context.getCallStack().getCallDepth();
              int commandDepth = client.getCallDepth();
              if (depth <= commandDepth)
              {
                breakClient = client;
              }
            }
          }
          else if (command == CMD_STEP_UNTIL)
          {
            // The step until command halts at the position specified with the command
            String stepUntilPosition = client.getStepUntilPosition();
            if (pos1 != null && pos1.equals(stepUntilPosition) || pos2 != null && pos2.equals(stepUntilPosition))
            {
              breakClient = client;
            }
          }

          if (command != CMD_STEP_UNTIL)
          {
            // Check if we should skip System model processes
            if (breakClient != null && (mode & MODE_SKIP_SYSTEM_MODEL) != 0)
            {
              if (pos1 != null && CoreConstants.SYSTEM_MODEL_NAME.equals(pos1.getModel()))
              {
                // Process belongs to the System model, skip
                breakClient = null;
              }
            }
          }
        }
      }
    }
    else
    {
      // No client is associated with this context
      // check if any client has set a global breakpoint for the current position
      if (pos1 != null)
      {
        breakClient = determineGlobalBreakpointClient(pos1);
      }
      if (breakClient == null && pos2 != null)
      {
        breakClient = determineGlobalBreakpointClient(pos2);
      }
    }

    if (breakClient != null)
    {
      // There is a debugger client associated with this event, stop the process

      // Determine current position
      ModelQualifier pos = null;
      if (event.getTargetParam() instanceof NodeParam)
        pos = event.getTargetParam().getQualifier();
      else if (event.getSourceParam() instanceof NodeParam)
        pos = event.getSourceParam().getQualifier();
      else if (event.getNodeSocket() != null)
        pos = event.getNodeSocket().getQualifier();
      else if (event.getNode() != null)
        pos = event.getNode().getQualifier();
      if (pos == null)
        pos = event.getProcess().getQualifier();

      // Save the halt status information in the client object
      DebuggerClient.HaltInfo haltInfo = breakClient.addHaltInfo(pos, event, context);

      // When stopping a process, reset the step until target
      breakClient.setStepUntilPosition(null);

      // Connect the token context of this process to the client
      context.setDebuggerId(breakClient.getClientId());

      // Wait for a command from the client
      waitForCommand(breakClient, haltInfo);

      // Reset the client information concerning the halted process
View Full Code Here

Examples of org.openbp.server.context.TokenContext

   * @param ee Engine executor that called this method
   * @throws OpenBPException On error
   */
  public void executeModelObject(ModelObject mo, EngineExecutor ee)
  {
    TokenContext context = ee.getTokenContext();
    context.setLifecycleRequest(LifecycleRequest.STOP);

    TokenContext rootContext = TokenContextUtil.getRootContext(context);
    if (rootContext != context)
    {
      // Our top-level context ends here (and will implicitely end all child contexts)
      rootContext.setLifecycleRequest(LifecycleRequest.STOP);

      TokenContextService contextService = getEngine().getTokenContextService();
      contextService.saveContext(rootContext);
    }
  }
View Full Code Here

Examples of org.openbp.server.context.TokenContext

    {
      executionLoopStopRequested = false;

      for (Iterator it = tcs.getExecutableContexts(fetchSize); it.hasNext() && ! executionLoopStopRequested;)
      {
        TokenContext context = (TokenContext) it.next();

        if (! runContext(context))
          break;

        ++nAcceptedContexts;
View Full Code Here

Examples of org.openbp.server.context.TokenContext

      // If an exception happens during context execution,
      // we will leave the loop and check for executable contexts again the next time.
      for (Iterator it = getEngine().getTokenContextService().getExecutableContexts(0); it.hasNext() && ! executionLoopStopRequested;)
      {
        TokenContext context = (TokenContext) it.next();
        found = true;

        executeContextInThisThread(context);
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.