Example #1
0
  private void completeExecuteArc(GraphProcess process, Node targetNode, List<ArcToken> tokens) {
    NodeToken nodeToken = getFactory().newNodeToken(process, targetNode, tokens);
    process.addNodeToken(nodeToken);

    // Add new node token to add the token sets which its generating arc tokens are members of
    Set<TokenSet> tokenSets = new HashSet<TokenSet>();

    for (ArcToken token : tokens) {
      for (ArcTokenSetMember setMember : token.getTokenSetMemberships()) {
        TokenSet tokenSet = setMember.getTokenSet();
        if (!tokenSet.isComplete() && !tokenSets.contains(tokenSet)) {
          tokenSets.add(tokenSet);
          NodeTokenSetMember newSetMember =
              getFactory().newNodeTokenSetMember(tokenSet, nodeToken, setMember.getMemberIndex());
          tokenSet.getActiveNodeTokens(this).add(nodeToken);
          nodeToken.getTokenSetMemberships().add(newSetMember);
        }
      }
    }

    fireEvent(NodeTokenEvent.newCreatedEvent(this, nodeToken));

    for (ArcToken token : tokens) {
      process.removeActiveArcToken(token);
      if (token.isPending()) {
        token.markProcessed(this);
      }
      token.markComplete(this, nodeToken);
      fireEvent(ArcTokenEvent.newCompletedEvent(this, token));
    }

    executeNode(process, nodeToken);
  }
 private void shareTokenSets(final ArcToken newToken, final ArcToken origToken) {
   for (ArcTokenSetMember setMember : origToken.getTokenSetMemberships()) {
     TokenSet tokenSet = setMember.getTokenSet();
     ArcTokenSetMember newSetMember =
         engine.getFactory().newArcTokenSetMember(tokenSet, newToken, setMember.getMemberIndex());
     newToken.getTokenSetMemberships().add(newSetMember);
     tokenSet.getActiveArcTokens(engine).add(newToken);
     tokenSets.add(tokenSet);
   }
 }