/** * instructs the main path of execution to continue by taking the specified transition on the * current node. * * @throws IllegalStateException if the token is not active. */ public void signal(Transition transition) { if (hasEnded()) throw new IllegalStateException("process instance has ended"); rootToken.signal(transition); }
/** * creates a child token. */ public Token(Token parent, String name) { this.start = Clock.getCurrentTime(); this.processInstance = parent.getProcessInstance(); this.name = name; this.node = parent.getNode(); this.parent = parent; parent.addChild(this); this.isTerminationImplicit = parent.isTerminationImplicit(); parent.addLog(new TokenCreateLog(this)); // assign an id to this token before events get fired Services.assignId(this); }
/** * notifies a parent that one of its nodeMap has ended. */ private void notifyParentOfTokenEnd() { if (isRoot()) { processInstance.end(); } else if (parent != null && !parent.hasActiveChildren()) { parent.end(); } }
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof Token)) return false; Token other = (Token) o; if (id != 0 && id == other.getId()) return true; return (name != null ? name.equals(other.getName()) : other.getName() == null) && (parent != null ? parent.equals(other.getParent()) : processInstance.equals(other.getProcessInstance())); }
public Object execute(Token token) { if (inStateAtLeastSince == null || token.getNodeEnter().before(inStateAtLeastSince)) { if (log.isDebugEnabled()) log.debug("signalling " + token); if (transitionName == null) { token.signal(); } else { token.signal(transitionName); } } return token; }
private void changeTokenVersion(Token token) { // change node reference on token (current node) Node oldNode = token.getNode(); ProcessDefinition newDef = token.getProcessInstance().getProcessDefinition(); Node newNode = findReplacementNode(newDef, oldNode); token.setNode(newNode); // Change timers too! adjustTimersForToken(token); // change tasks adjustTaskInstancesForToken(token); // change children recursively Map children = token.getChildren(); if (children != null) { for (Iterator i = children.values().iterator(); i.hasNext();) { changeTokenVersion((Token) i.next()); } } }
public String getFullName() { if (isRoot()) return "/"; StringBuffer nameBuilder = new StringBuffer(); for (Token token = this; token.hasParent(); token = token.getParent()) { String tokenName = token.getName(); if (tokenName != null) nameBuilder.insert(0, tokenName); nameBuilder.insert(0, '/'); } return nameBuilder.toString(); }
public Node getNode() { return token.getNode(); }
/** * called by a transition to pass execution to this node. */ public void enter(ExecutionContext executionContext) { Token token = executionContext.getToken(); // update the runtime context information token.setNode(this); // register entrance time so that a node-log can be generated upon leaving token.setNodeEnter(Clock.getCurrentTime()); // fire the leave-node event for this node fireEvent(Event.EVENTTYPE_NODE_ENTER, executionContext); // remove the transition references from the runtime context executionContext.setTransition(null); executionContext.setTransitionSource(null); // execute the node if (isAsync) { ExecuteNodeJob job = createAsyncContinuationJob(token); executionContext.getJbpmContext().getServices().getMessageService().send(job); token.lock(job.toString()); } else { execute(executionContext); } }
token.setNode(null); token.startCompositeLog(transitionLog); try { token.endCompositeLog();
for (Iterator iter = children.values().iterator(); iter.hasNext();) { Token child = (Token) iter.next(); if (!child.hasEnded()) { child.end(); parent.addLog(new TokenEndLog(this)); notifyParentOfTokenEnd();
protected void cancelToken(Token token) { // recursively cancel children cancelTokens(token.getChildren().values()); // cancel tasks cancelTasks(getTasksForToken(token)); if (!token.hasEnded()) { // end token but do not propagate to parent // to prevent inadvertent termination token.end(false); } if (log.isDebugEnabled()) log.debug("cancelled " + token); }
/** * suspends a process execution. */ public void suspend() { isSuspended = true; suspendJobs(); suspendTaskInstances(); // propagate to child tokens if (children != null) { for (Iterator iter = children.values().iterator(); iter.hasNext();) { Token child = (Token) iter.next(); child.suspend(); } } }
/** * resumes a process execution. */ public void resume() { isSuspended = false; resumeJobs(); resumeTaskInstances(); // propagate to child tokens if (children != null) { for (Iterator iter = children.values().iterator(); iter.hasNext();) { Token child = (Token) iter.next(); child.resume(); } } }
/** * saves the process instance of the given token. */ public void save(Token token) { save(token.getProcessInstance()); }
protected void retrieveToken(Token token) { retrieveNode(token.getNode()); // Hibernate.initialize(token.getAvailableTransitions()); if( token.getChildren() != null ) { for (Iterator iter = token.getChildren().values().iterator(); iter.hasNext();) { retrieveToken((Token) iter.next()); } } }
public void execute(ExecutionContext executionContext) { Token token = executionContext.getToken(); // get the token on which the milestone should be verified Token milestoneToken = token.findToken( tokenPath ); if ( isMilestoneReached( name, milestoneToken ) ) { // continue to pass the token over the default transition token.getNode().leave(executionContext); } else { addMilestoneListener(name,milestoneToken); } }
/** * called by the implementation of this node to continue execution over the given transition. */ public void leave(ExecutionContext executionContext, Transition transition) { if (transition == null) throw new JbpmException("transition is null"); Token token = executionContext.getToken(); token.setNode(this); executionContext.setTransition(transition); // fire the leave-node event for this node fireEvent(Event.EVENTTYPE_NODE_LEAVE, executionContext); // log this node if (token.getNodeEnter() != null) { addNodeLog(token); } // update the runtime information for taking the transition // the transitionSource is used to calculate events on superstates executionContext.setTransitionSource(this); // take the transition transition.take(executionContext); }
} 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 + "'"); token.setNode(node); context.addSuccessMessage("Token moved to node '" + node.getName() + "'"); context.getJbpmContext().getSession().flush();
/** * ends this token and all of its children (if any). this is the last active (i.e. not-ended) * child of a parent token, the parent token will be ended as well and that verification will * continue to propagate. */ public void end() { end(true); }