Package org.openbp.server.context

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


    }

    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

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

    {
      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

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

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

   * 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

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

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

    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

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.