Package org.jbpm.graph.exe

Examples of org.jbpm.graph.exe.Token


  public void write(Element element) {
    // TODO
  }

  public void execute(ExecutionContext executionContext) {
    Token token = executionContext.getToken();
    Collection<String> transitionNames = retrieveTransitionNames(token);
    // if this is the first time we enter
    if (transitionNames == null) {
      // collect all leaving transition names
      transitionNames = new ArrayList<String>(getTransitionNames(token));
    }

    // select one of the remaining transition names
    String nextTransition = interleaver.selectNextTransition(transitionNames);
    // remove it from the remaining transitions
    transitionNames.remove(nextTransition);

    // store the transition names
    storeTransitionNames(transitionNames, token);

    // pass the token over the selected transition
    token.getNode().leave(executionContext, nextTransition);
  }
View Full Code Here


            }
            if (! (tokenValue instanceof Token)) {
                context.setError("Error moving token", "Attempted to move something other than a token");
                return;
            }
            final Token token = (Token) tokenValue;
            final Node node;
            final Object nodeValue = nodeExpression.getValue(elContext);
            if (nodeValue == null) {
                context.setError("Error moving token", "Node value is null");
                return;
            }
            if (nodeValue instanceof Node) {
                node = (Node) nodeValue;
            } else {
                final String nodeName = nodeValue.toString();
                node = token.getProcessInstance().getProcessDefinition().getNode(nodeName);
                if (node == null) {
                    context.setError("Error moving token", "No node found by name of '" + nodeName + "'");
                    return;
                }
            }
            token.setNode(node);
            context.addSuccessMessage("Token moved to node '" + node.getName() + "'");
            context.getJbpmContext().getSession().flush();
            context.selectOutcome("success");
        } catch (Exception ex) {
            context.setError("Error moving token", ex);
View Full Code Here

        jpdlReader.addError("invalid parent lock mode '" + lock + "'");
    }
  }

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

    boolean isAbleToReactivateParent = token.isAbleToReactivateParent();

    if (!token.hasEnded()) token.end(false);

    // if this token is not able to reactivate the parent,
    // we don't need to check anything
    if (isAbleToReactivateParent) {
      // the token arrived in the join and can only reactivate the parent once
      token.setAbleToReactivateParent(false);

      Token parentToken = token.getParent();
      if (parentToken != null) {
        JbpmContext jbpmContext = executionContext.getJbpmContext();
        Session session = jbpmContext != null ? jbpmContext.getSession() : null;
        if (session != null) {
          // obtain update lock by default (LockMode.UPGRADE)
          LockMode lockMode = parentLockMode != null ? LockMode.parse(parentLockMode)
              : LockMode.UPGRADE;
          log.debug("acquiring " + lockMode + " lock on " + parentToken);
          // lock updates as appropriate, no need to flush here
          session.lock(parentToken, lockMode);
        }

        boolean reactivateParent = true;

        // if this is a discriminator
        if (isDiscriminator) {
          // reactivate the parent when the first token arrives in the join.
          // this must be the first token arriving, otherwise isAbleToReactivateParent()
          // should have been false above.
          reactivateParent = true;
        }
        // if a fixed set of tokenNames is specified at design time...
        else if (tokenNames != null) {
          // check reactivation on the basis of those tokenNames
          reactivateParent = mustParentBeReactivated(parentToken, tokenNames.iterator());
        }
        // if a script is specified
        else if (script != null) {
          // check if the script returns a collection or a boolean
          Object result = null;
          try {
            result = script.eval(token);
          }
          catch (Exception e) {
            this.raiseException(e, executionContext);
          }
          // if the result is a collection
          if (result instanceof Collection) {
            // it must be a collection of tokenNames
            Collection<String> runtimeTokenNames = CollectionUtil.checkCollection(
                (Collection<?>) result, String.class);
            reactivateParent = mustParentBeReactivated(parentToken, runtimeTokenNames.iterator());
          }
          // if it's a boolean...
          else if (result instanceof Boolean) {
            // the boolean specifies if the parent needs to be reactivated
            reactivateParent = (Boolean) result;
          }
        }
        // if a nOutOfM is specified
        else if (nOutOfM != -1) {
          int n = 0;
          // check how many tokens already arrived in the join
          for (Token concurrentToken : parentToken.getChildren().values()) {
            if (equals(concurrentToken.getNode())) n++;
          }
          if (n < nOutOfM) reactivateParent = false;
        }
        // if no configuration is specified..
        else {
          // the default behaviour is to check all concurrent tokens and reactivate
          // the parent if the last token arrives in the join
          reactivateParent = mustParentBeReactivated(parentToken, parentToken.getChildren()
              .keySet()
              .iterator());
        }

        // if the parent token needs to be reactivated from this join node
        if (reactivateParent) {
          // write to all child tokens that the parent is already reactivated
          for (Token child : parentToken.getChildren().values()) {
            child.setAbleToReactivateParent(false);
          }
          // write to all child tokens that the parent is already reactivated
          ExecutionContext parentContext = new ExecutionContext(parentToken);
          leave(parentContext);
View Full Code Here

  }

  public boolean mustParentBeReactivated(Token parentToken, Iterator<String> childTokenNames) {
    while (childTokenNames.hasNext()) {
      String concurrentTokenName = childTokenNames.next();
      Token concurrentToken = parentToken.getChild(concurrentTokenName);
      if (concurrentToken.isAbleToReactivateParent()) {
        log.debug("join will not reactivate parent: found concurrent " + concurrentToken);
        return false;
      }
    }
    return true;
View Full Code Here

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

            if (value instanceof TaskInstance) {
                ((TaskInstance)value).setSignalling(false);
                ((TaskInstance)value).cancel();
                context.addSuccessMessage("Task instance cancelled");
            } else if (value instanceof Token) {
                final Token token = ((Token) value);
                token.end();
                for (TaskInstance task : (Collection<TaskInstance>) token.getProcessInstance().getTaskMgmtInstance().getUnfinishedTasks(token)) {
                    task.cancel();
                }
                context.addSuccessMessage("Token ended");
            } else if (value instanceof ProcessInstance) {
                final ProcessInstance processInstance = ((ProcessInstance) value);
View Full Code Here

      // batch tokens
      if (tokenIds != null && tokenIds.length > 0)
      {
        for (int i = 0; i < tokenIds.length; i++)
        {
          Token token = jbpmContext.loadTokenForUpdate(tokenIds[i]);
          result.add(execute(token));
        }
      }
      else
      {
View Full Code Here

   
    changeNappy.end();

    processInstance = saveAndReload(processInstance);

    Token token = processInstance.getRootToken();
    taskMgmtInstance = processInstance.getTaskMgmtInstance();
    TaskInstance makeBottle = (TaskInstance) taskMgmtInstance.getUnfinishedTasks(token).iterator().next();
    assertEquals("johndoe", makeBottle.getActorId());
   
    Set retrievedTaskInstancePooledActorIds = new HashSet();
View Full Code Here

  public void testAprioriRuntimeKnowledgeScenario2() {
    scenario = 2;
   
    ProcessInstance processInstance = new ProcessInstance(processDefinition);
    Token token = processInstance.getRootToken();
    processInstance.signal();
    processInstance.signal();
   
    assertSame(t, token.getNode());
    assertEquals(1, getNbrOfTasks(token));
   
    addOneTask(token);

    assertSame(t, token.getNode());
    assertEquals(2, getNbrOfTasks(token));
   
    endOneTask(token);

    assertSame(t, token.getNode());
    assertEquals(1, getNbrOfTasks(token));
   
    endOneTask(token);

    assertSame(c, token.getNode());
    assertEquals(0, getNbrOfTasks(token));
  }
View Full Code Here

  public void testAprioriRuntimeKnowledgeScenario3() {
    scenario = 3;
   
    ProcessInstance processInstance = new ProcessInstance(processDefinition);
    Token token = processInstance.getRootToken();
    processInstance.signal();
    processInstance.signal();
   
    assertSame(t, token.getNode());
    assertEquals(2, getNbrOfTasks(token));
   
    addOneTask(token);

    assertSame(t, token.getNode());
    assertEquals(3, getNbrOfTasks(token));
   
    endOneTask(token);
    endOneTask(token);

    assertSame(t, token.getNode());
    assertEquals(1, getNbrOfTasks(token));
   
    endOneTask(token);

    assertSame(c, token.getNode());
    assertEquals(0, getNbrOfTasks(token));
  }
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.