Examples of TokenContext


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

    NodeSocket nextSocket = null;

    TokenContext parentContext = context.getParentContext();
    if (parentContext != null)
    {
      // Our token ends here
      context.setLifecycleRequest(LifecycleRequest.STOP);

      NodeSocket parentNextSocket = null;
      if (parentContext.hasChildContext())
      {
        parentNextSocket = getEngine().resolveSocketRef(CoreConstants.INCOMPLETE_SOCKET_NAME, entrySocket, parentContext, false);
      }
      else
      {
        parentNextSocket = getEngine().resolveSocketRef(CoreConstants.SOCKET_OUT, entrySocket, parentContext, true);
      }

      if (parentNextSocket != null)
      {
        // Copy the data of the node entry socket in the current context
        // to the exit socket in the child context.
        EngineUtil.copySocketData(entrySocket, context, parentNextSocket, parentContext);

        // Continue the parent context in a new thread
        parentContext.setCurrentSocket(parentNextSocket);
        parentContext.setLifecycleRequest(LifecycleRequest.RESUME);

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

Examples of org.openbp.server.context.TokenContext

   * 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 + ")");
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();
    SubprocessNode node = (SubprocessNode) entrySocket.getNode();

    // If we do not have a sub process, simply continue with the default exit socket
    NodeSocket nextSocket = node.getDefaultExitSocket();

    ProcessItem subprocess = node.getSubprocess();

    // Dynamic sub processes:
    // If we have a Process Name parameter and its value is a string...
    Object result = TokenContextUtil.getParamValue(context, entrySocket, CoreConstants.DYNAMIC_SUBPROCESS_PARAM_NAME);
    if (result != null && result instanceof String)
    {
      // ...try to lookup and return a corresponding process.
      try
      {
        subprocess = (ProcessItem) context.getExecutingModel().resolveItemRef((String) result, ItemTypes.PROCESS);
      }
      catch (ModelException re)
      {
        // Fall thru to the default.
      }
    }

    if (subprocess != null)
    {
      // The default exit socket of the initial node of the sub process
      // that has the same name as the initial node of this sub process
      // node is our initial socket for execution of the sub process.
      String entryName = entrySocket.getName();
      Node subprocessInitialNode = subprocess.getNodeByName(entryName);

      if (subprocessInitialNode == null)
      {
        String msg = LogUtil.error(getClass(), "Initial node $0 called by $1 not found in process $2. [{3}]", entryName, node.getQualifier(), subprocess.getQualifier(), context);
        throw new EngineException("InitialNodeNotFound", msg);
      }

      if (!(subprocessInitialNode instanceof InitialNode))
      {
        String msg = LogUtil.error(getClass(), "Node $0 called by $1 is not an initial node. [{2}]", subprocessInitialNode.getQualifier(), node.getQualifier(), context);
        throw new EngineException("NotAnInitialNode", msg);
      }

      // Continue with the initial node of the sub process
      nextSocket = subprocessInitialNode.getDefaultExitSocket();
      if (nextSocket == null)
      {
        String msg = LogUtil.error(getClass(), "No default exit socket present for sub process initial node $0. [{1}]", subprocessInitialNode.getQualifier(), context);
        throw new EngineException("NoDefaultExitSocket", msg);
      }

      // Push the current position onto the call stack
      context.getCallStack().pushSubprocess(entrySocket);

      // Create the process variables of the subprocess
      EngineUtil.createProcessVariables(subprocess, context);

      // Copy the data of the node entry socket in the current context
      // to the initial node of the sub process in the new context
      EngineUtil.copySocketData(entrySocket, context, nextSocket, context);
    }
    else
    {
      String msg = LogUtil.error(getClass(), "Missing sub process for sub process node $0. [{1}]", node.getQualifier(), context);
      throw new EngineException("MissingSubprocess", msg);
    }

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

Examples of org.openbp.server.context.TokenContext

    // Determine the type of the object and use
    // the appropriate method to collect all member names

    if (obj instanceof TokenContext)
    {
      TokenContext context = (TokenContext) obj;

      // Iterate all parameter data of the context;
      // We want the complete information of what is in the context, so we don't skip
      // any members, even if the member value is null
      Map paramValues = context.getParamValues();
      for (Iterator it = paramValues.keySet().iterator(); it.hasNext();)
      {
        String key = (String) it.next();

        // Determine the value
        Object value = context.getParamValue(key);

        // Add the value to the member list
        if (members == null)
          members = new ArrayList();
        members.add(createNamedMember(key, value, true));
      }

      // We should sort the members.
      if (members != null)
      {
        Collections.sort(members);
      }
    }
    else if (cls.isArray())
    {
      int len = Array.getLength(obj);

      // Iterate the array;
      // Leaving holes in the array indices doesn't look very good,
      // so we don't skip any members, even if the member value is null
      for (int i = 0; i < len; i++)
      {
        if (members == null)
          members = new ArrayList();

        if (i == MAX_MEMBERS)
        {
          members.add(createEtcMember());
          break;
        }

        // Determine the value
        Object value = Array.get(obj, i);

        // Add the value to the member list
        members.add(createIndexMember(i, value));
      }
    }
    else if (obj instanceof Collection)
    {
      Collection coll = (Collection) obj;

      // Iterate the collection;
      // Leaving holes in the collection indices doesn't look very good,
      // so we don't skip any members, even if the member value is null
      int i = 0;
      for (Iterator it = coll.iterator(); it.hasNext();)
      {
        if (members == null)
          members = new ArrayList();

        if (i == MAX_MEMBERS)
        {
          members.add(createEtcMember());
          break;
        }

        // Determine the value
        Object value = it.next();

        // Add the value to the member list
        members.add(createIndexMember(i++, value));
      }
    }
    else if ((type = context.getExecutingModel().lookupTypeByClassName(cls.getName())) != null)
    {
      // Iterate all members of the type of the bean and its super beans
      for (Iterator it = type.getAllMembers(); it.hasNext();)
      {
        DataMember member = (DataMember) it.next();
View Full Code Here

Examples of org.openbp.server.context.TokenContext

    try
    {
      processFacade.begin();

      TokenContext tc = null;
      tokenId = dataMap.get(KEY_TOKEN_ID);
      if (tokenId == null)
      {
        // No token given, create new one
        tc = processFacade.createToken();
        processFacade.prepareTokenForScheduler(tc);
        tokenId = tc.getId();
      }
      else
      {
        // Use existing token
        tc = processFacade.getTokenById(tokenId);
        if (tc == null)
        {
          String msg = LogUtil.error(getClass(), "Cannot find the scheduled token context (id $0) for job $1.", tokenId, context
            .getJobDetail().getGroup() + "."
            + context.getJobDetail().getName());
          JobExecutionException ex = new JobExecutionException(msg);
          ex.setUnscheduleAllTriggers(true);
          throw ex;
        }
      }

      String positionRef = dataMap.getString(KEY_POSITION_REF);
      String executionMode = dataMap.getString(KEY_EXECUTION_MODE);
      String startMode = dataMap.getString(KEY_START_MODE);

      Map inputParamValues = null;

      for (Iterator it = dataMap.entrySet().iterator(); it.hasNext();)
      {
        Map.Entry entry = (Map.Entry) it.next();

        String key = (String) entry.getKey();
        if (key.startsWith(KEY_PARAM_PREFIX))
        {
          if (inputParamValues == null)
          {
            inputParamValues = new HashMap();
          }
          key = key.substring(KEY_PARAM_PREFIX.length());
          inputParamValues.put(key, entry.getValue());
        }
        else if (key.startsWith(KEY_RUNTIME_ATRIBUTE_PREFIX))
        {
          key = key.substring(KEY_RUNTIME_ATRIBUTE_PREFIX.length());
          tc.setRuntimeAttribute(key, entry.getValue());
        }
      }

      Engine engine = processServer.getEngine();
View Full Code Here

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

Examples of org.openbp.server.context.TokenContext

   * 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

Examples of org.openbp.server.context.TokenContext

    // 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

Examples of org.openbp.server.context.TokenContext

   *
   * @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

Examples of org.openbp.server.context.TokenContext

   * @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
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.