Package org.openbp.server.context

Examples of org.openbp.server.context.TokenContextService


  @Test
  public void testResetExecutingTokenStateMethod()
    throws Exception
  {
    String localHost = new DefaultSystemNameProvider().getSystemName();
    TokenContextService tokenContextService = getProcessServer().getTokenContextService();

    // Create all kinds of contexts and simulate several states

    TokenContext tc1 = startSimpleSignalSetProcess("TestSignal1", "Done", 0);
    tc1.setLifecycleState(LifecycleState.SELECTED);
    tc1.setLifecycleRequest(LifecycleRequest.NONE);
    tc1.setNodeId(localHost);
    tokenContextService.saveContext(tc1);

    TokenContext tc2 = startSimpleSignalSetProcess("TestSignal2", "Done", 0);
    tc2.setLifecycleState(LifecycleState.SELECTED);
    tc2.setLifecycleRequest(LifecycleRequest.NONE);
    tc2.setNodeId("DifferentHost");
    tokenContextService.saveContext(tc2);

    TokenContext tc3 = startSimpleSignalSetProcess("TestSignal3", "Done", 0);
    tc3.setLifecycleState(LifecycleState.RUNNING);
    tc3.setLifecycleRequest(LifecycleRequest.NONE);
    tc3.setNodeId(localHost);
    tokenContextService.saveContext(tc3);

    TokenContext tc4 = startSimpleSignalSetProcess("TestSignal4", "Done", 0);
    tc4.setLifecycleState(LifecycleState.ERROR);
    tc4.setLifecycleRequest(LifecycleRequest.NONE);
    tc4.setNodeId(localHost);
    tokenContextService.saveContext(tc4);

    TokenContext tc5 = startSimpleSignalSetProcess("TestSignal5", "Done", 0);
    tokenContextService.saveContext(tc5);

    getProcessServer().getEngine().commit();

    // Execute those that can be executed
    getProcessFacade().executePendingContextsInThisThread();

    // Check the state of the executions
    assertEquals(null, TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal1"));
    assertEquals(null, TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal2"));
    assertEquals(null, TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal3"));
    assertEquals(null, TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal4"));
    assertEquals("Done", TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal5"));

    // *** Now reset all contexts that seem to be currently executed by this node ***
    // (i. e. simulate system startup)
    int ret = getProcessFacade().resetExecutingTokenState(null);
    assertEquals(2, ret);

    // Clear cache so we will not be fooled by cached context objects
    tokenContextService.clearCache();

    // Execute those that can be executed
    getProcessFacade().executePendingContextsInThisThread();

    // Check the state of the executions
    // 2 Contexts should still be there (tc2: Different host, tc4: Error state)
    assertEquals("Done", TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal1"));
    assertEquals(null, TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal2"));
    assertEquals("Done", TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal3"));
    assertEquals(null, TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal4"));
    assertEquals("Done", TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal5"));

    // Cleanup the last ones
    tc2 = tokenContextService.getContextById(tc2.getId());
    tc2.setLifecycleState(LifecycleState.SUSPENDED);
    tc2.setLifecycleRequest(LifecycleRequest.RESUME);
    tc2.setNodeId(localHost);
    tokenContextService.saveContext(tc2);

    tc4 = tokenContextService.getContextById(tc4.getId());
    tc4.setLifecycleState(LifecycleState.SUSPENDED);
    tc4.setLifecycleRequest(LifecycleRequest.RESUME);
    tokenContextService.saveContext(tc4);

    tokenContextService.commit();

    getProcessFacade().executePendingContextsInThisThread();
    assertEquals("Done", TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal2"));
    assertEquals("Done", TestCaseSyncMgr.getInstance().getSignal(null, "TestSignal4"));
  }
View Full Code Here


   * @return The new workflow task
   * @throws OpenBPException Any exception that may occur during creation or save operation of the workflow
   */
  protected WorkflowTask createWorkflowTask(NodeSocket entrySocket, TokenContext context)
  {
    TokenContextService contextService = getEngine().getTokenContextService();

    WorkflowNode node = (WorkflowNode) entrySocket.getNode();

    // Create a new workflow task
    WorkflowTask workflowTask = contextService.createWorkflowTask(context);

    // Update the current task from the entry socket and the prototype
    WorkflowTaskDescriptor prototype = node.getWorkflowTaskDescriptor();
    updateWorkflowTaskFromPrototype(workflowTask, entrySocket, context, prototype);

    // Update the creating user and creation date if not present already
    if (workflowTask.getCreatingUserId() == null)
    {
      workflowTask.setCreatingUserId(context.getUserId());
    }
    if (workflowTask.getTimeCreated() == null)
    {
      workflowTask.setTimeCreated(new Timestamp(System.currentTimeMillis()));
    }

    // This is an active workflow task now.
    workflowTask.setStatus(WorkflowTask.STATUS_ENABLED);

    workflowTask = contextService.addWorkflowTask(workflowTask);

    return workflowTask;
  }
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
    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);
      engine.commit();
    }

    // Make the rolled-back context the current one
    return dbContext;
View Full Code Here

          }
          sessionRegistry.registerSession(context.getId(), context, sessionTimeout);
        }
      }

      TokenContextService contextService = engine.getTokenContextService();
      contextService.saveContext(context);
      engine.commit();

      do
      {
        executeNextStep();
View Full Code Here

  /**
   * Handles any lifecycle state requests and perform the transaction handling.
   */
  private void handleLifecycleRequest()
  {
    TokenContextService contextService = engine.getTokenContextService();

    int lifecycleRequest = context.getLifecycleRequest();

    if (lifecycleRequest == LifecycleRequest.SUSPEND_MEMORY)
    {
      LogUtil.trace(getClass(), "Suspending token (memory suspend). [{0}]", context);

      // This is a mere memory-suspend, so don't commit this change.
      engine.changeTokenState(context, LifecycleState.IDLING, LifecycleRequest.NONE);

      // Wait for some notification, using the context as synchronisation object
      synchronized (context)
      {
        try
        {
          context.wait();
        }
        catch (InterruptedException e)
        {
        }
      }

      // Resume again
      LogUtil.trace(getClass(), "Resuming token (memory suspend). [{0}]", context);
      engine.changeTokenState(context, LifecycleState.RUNNING, LifecycleRequest.NONE);
    }

    if (lifecycleRequest == LifecycleRequest.SUSPEND_IMMEDIATE)
    {
      // This node type requires persistence of the process state
      LogUtil.trace(getClass(), "Suspending token (immediate suspend). [{0}]", context);

      engine.changeTokenState(context, LifecycleState.SUSPENDED, LifecycleRequest.NONE);

      contextService.saveContext(context);
      engine.commit();
    }
    else if (lifecycleRequest == LifecycleRequest.STOP)
    {
      // Normally terminate processing
View Full Code Here

    NodeSocket oldCurrentSocket = context.getCurrentSocket();

    int transactionControl = link.getTransactionControl();
    if (transactionControl != ControlLink.TA_NONE)
    {
      TokenContextService contextService = engine.getTokenContextService();

      boolean begin = false;
      switch (transactionControl)
      {
        case ControlLink.TA_BEGIN:
        begin = true;
        break;

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

        case ControlLink.TA_COMMIT:
        contextService.saveContext(context);
        engine.commit();
        break;

        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;
      }

      if (begin)
      {
        engine.begin();
      }

      if (context.getLifecycleRequest() == LifecycleRequest.SUSPEND_TRANSACTION)
      {
        // There is a suspension request for the next transaction control, serve it.
        LogUtil.trace(getClass(), "Suspending token (transaction suspend). [{0}]", context);

        engine.changeTokenState(context, LifecycleState.SUSPENDED, LifecycleRequest.NONE);
        contextService.saveContext(context);
        engine.commit();
      }
    }

    if (context.getCurrentSocket() == oldCurrentSocket)
View Full Code Here

    }
  }

  private void rollbackAndExit(int lifecycleState)
  {
    TokenContextService contextService = engine.getTokenContextService();

    Object contextId = context.getId();
    engine.rollback();

    context = contextService.getContextById(contextId);
    engine.changeTokenState(context, lifecycleState, LifecycleRequest.NONE);
    contextService.saveContext(context);
    engine.commit();

    // TODO Fix 3 What to do with child/root context? Maybe call endToken with a parameter?
  }
View Full Code Here

    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

   * have finished their execution at this point in time.
   * @return The number of contexts that have been retrieved for execution and passed to the thread pool
   */
  public int executePendingContextsInDifferentThread()
  {
    TokenContextService tcs = getEngine().getTokenContextService();
    int nAcceptedContexts = 0;

    try
    {
      executionLoopStopRequested = false;

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

        if (! runContext(context))
          break;
View Full Code Here

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

        TokenContextService contextService = getEngine().getTokenContextService();
        contextService.saveContext(parentContext);
      }
    }
    else
    {
      nextSocket = node.getDefaultExitSocket();
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.