Package org.jbpm.graph.exe

Examples of org.jbpm.graph.exe.Token


   * @see #loadToken(long)
   * @see #loadTokenForUpdate(long)
   */
  public Token getTokenForUpdate(long tokenId)
  {
    Token token = getGraphSession().getToken(tokenId);
    if (token != null)
    {
      addAutoSaveToken(token);
    }
    return token;
View Full Code Here


      script.read(scriptElement, jpdlReader);
    }
  }

  public void execute(ExecutionContext executionContext) {
    Token token = executionContext.getToken();
   
    // phase one: collect all the transitionNames
    Collection<?> transitionNames = null;

    // by default, the fork spawns a token for each leaving transition
    if (script==null) {
      transitionNames = getLeavingTransitionsMap().keySet();

    } else { // a script is specified 
      // if a script is specified, use that script to calculate the set
      // of leaving transitions to be used for forking tokens.
      Map<String, Object> outputMap = script.eval(token);
      if (outputMap.size()==1) {
        Object result = outputMap.values().iterator().next();
        if (result instanceof Collection) {
          transitionNames = (Collection<?>) result;
        }
      }
      if (transitionNames==null) {
        throw new JbpmException("script for fork '"+name+"' should produce one collection (in one writable variable): "+transitionNames);
      }
    }
   
    // TODO add some way of blocking the current token here and disable that blocking when the join reactivates this token
    // Then an exception can be thrown by in case someone tries to signal a token that is waiting in a fork.
    // Suspend and resume can NOT be used for this since that will also suspend any related timers, tasks and messages...
    // So a separate kind of blocking should be created for this.
    // @see also http://jira.jboss.com/jira/browse/JBPM-642

    // phase two: create forked tokens for the collected transition names
    Map<String, Token> forkedTokens = new HashMap<String, Token>();
    for (Object element : transitionNames) {
      String transitionName = (String) element;
      Token childToken = createForkedToken(token, transitionName);
      forkedTokens.put(transitionName, childToken);
    }

    // phase three: launch child tokens from the fork over the given transitions
    for (Map.Entry<String, Token> forkedToken : forkedTokens.entrySet()) {
      Token childToken = forkedToken.getValue();
      String leavingTransitionName = forkedToken.getKey();
      ExecutionContext childExecutionContext = new ExecutionContext(childToken);
      if (leavingTransitionName!=null) {
        leave(childExecutionContext, leavingTransitionName);
      } else {
View Full Code Here

    }
  }

  protected Token createForkedToken(Token parent, String transitionName) {
    // instantiate the new token
    return new Token(parent, getTokenName(parent, transitionName));
  }
View Full Code Here

    return subProcessResolver;
  }

  public void execute(ExecutionContext executionContext)
  {
    Token superProcessToken = executionContext.getToken();

    ProcessDefinition usedSubProcessDefinition = subProcessDefinition;
    // if this process has late binding
    if ((subProcessDefinition == null) && (subProcessName != null))
    {
      SubProcessResolver subProcessResolver = getSubProcessResolver();
      List<FlyweightAttribute> attributes = new ArrayList<FlyweightAttribute>();
      String subProcessNameResolved = (String)JbpmExpressionEvaluator.evaluate(subProcessName, executionContext);
      if (log.isDebugEnabled())
      {
        log.debug("SubProcessName after eval: " + subProcessNameResolved);
      }
      attributes.add(new FlyweightAttribute("name", subProcessNameResolved));
      Element subProcessElement = new DefaultElement("sub-process");
      subProcessElement.setAttributes(attributes);

      usedSubProcessDefinition = subProcessResolver.findSubProcess(subProcessElement);
    }

    // create the subprocess
    ProcessInstance subProcessInstance = superProcessToken.createSubProcessInstance(usedSubProcessDefinition);

    // fire the subprocess created event
    fireEvent(Event.EVENTTYPE_SUBPROCESS_CREATED, executionContext);

    // feed the readable variableInstances
View Full Code Here

  public void leave(ExecutionContext executionContext, Transition transition)
  {
    ProcessInstance subProcessInstance = executionContext.getSubProcessInstance();

    Token superProcessToken = subProcessInstance.getSuperProcessToken();

    // feed the readable variableInstances
    if ((variableAccesses != null) && (!variableAccesses.isEmpty()))
    {

      ContextInstance superContextInstance = executionContext.getContextInstance();
      ContextInstance subContextInstance = subProcessInstance.getContextInstance();

      // loop over all the variable accesses
      for (VariableAccess variableAccess : variableAccesses)
      {
        // if this variable access is writable
        if (variableAccess.isWritable())
        {
          // the variable is copied from the sub process mapped name
          // to the super process variable name
          String mappedName = variableAccess.getMappedName();
          Object value = subContextInstance.getVariable(mappedName);
          String variableName = variableAccess.getVariableName();
          log.debug("copying sub process var '" + mappedName + "' to super process var '" + variableName + "': " + value);
          if (value != null)
          {
            superContextInstance.setVariable(variableName, value, superProcessToken);
          }
        }
      }
    }

    // fire the subprocess ended event
    fireEvent(Event.EVENTTYPE_SUBPROCESS_END, executionContext);

    // remove the subprocess reference
    superProcessToken.setSubProcessInstance(null);

    // We replaced the normal log generation of super.leave() by creating the log here
    // and overriding the addNodeLog method with an empty version
    superProcessToken.addLog(new ProcessStateLog(this, superProcessToken.getNodeEnter(), Clock.getCurrentTime(), subProcessInstance));

    // call the subProcessEndAction
    super.leave(executionContext, getDefaultLeavingTransition());
  }
View Full Code Here

  }

  public Object execute(JbpmContext jbpmContext) throws Exception
  {
    setJbpmContext(jbpmContext);
    Token token = jbpmContext.getToken(tokenId);
    retrieveToken(token);
    return token;
  }
View Full Code Here

            if (entity instanceof TaskInstance) {
                final TaskInstance task = (TaskInstance) entity;
                oldValue = task.getVariable(name);
                task.setVariable(name, value);
            } else if (entity instanceof Token) {
                final Token token = (Token) entity;
                final ContextInstance contextInstance = token.getProcessInstance().getContextInstance();
                oldValue = contextInstance.getVariable(name, token);
                contextInstance.setVariable(name, value, token);
            } else if (entity instanceof ProcessInstance) {
                final ProcessInstance processInstance = (ProcessInstance) entity;
                final ContextInstance contextInstance = processInstance.getContextInstance();
View Full Code Here

  protected Map loadLogFromMap(Map logMap)
  {
    Iterator iter = logMap.keySet().iterator();
    while (iter.hasNext())
    {
      Token t = (Token)iter.next();

      List logs = (List)logMap.get(t);
      Iterator iter2 = logs.iterator();
      while (iter2.hasNext())
      {
View Full Code Here

  public Merge(String name) {
    super(name);
  }

  public void execute(ExecutionContext executionContext) {
    Token token = executionContext.getToken();
    Node mergeNode = token.getNode();
   
    // if this is a simple merge
    if ( ! isSynchronized ) {
      mergeNode.leave(executionContext);

    // this is a synchronizing multi merge
    } else {
     
      Collection<Token> concurrentTokens = token.getParent().getChildren().values();
      boolean reactivate = true;
      for (Token concurrentToken : concurrentTokens) {
        if (! mergeNode.equals(concurrentToken.getNode())) {
          reactivate = false;
          break;
View Full Code Here

      // delete logs
      log.debug("deleting logs for " + processInstance);
      deleteLogs(processInstance);

      // detach from parent process token
      Token superProcessToken = processInstance.getSuperProcessToken();
      if (superProcessToken != null) {
        log.debug("detaching "
            + processInstance
            + " from super process token "
            + superProcessToken.getId());
        processInstance.setSuperProcessToken(null);
        superProcessToken.setSubProcessInstance(null);
      }

      // delete tokens and subprocess instances
      log.debug("deleting subprocesses for " + processInstance);
      deleteSubProcesses(processInstance);
View Full Code Here

TOP

Related Classes of org.jbpm.graph.exe.Token

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.