📄 taskinstance.java
字号:
/**
* convenience method that combines a {@link #setActorId(String)} and
* a {@link #start()}.
*/
public void start(String actorId){
start(actorId, true);
}
/**
* convenience method that combines a {@link #setActorId(String,boolean)} and
* a {@link #start()}.
*/
public void start(String actorId, boolean overwriteSwimlane){
setActorId(actorId, overwriteSwimlane);
start();
}
/**
* cancels this task.
*/
public void cancel() {
this.isCancelled = true;
this.isOpen = false;
end();
}
/**
* marks this task as done. If this task is related to a task node
* this might trigger a signal on the token.
* @see #end(Transition)
*/
public void end() {
end((Transition)null);
}
/**
* marks this task as done and specifies the name of a transition
* leaving the task-node for the case that the completion of this
* task instances triggers a signal on the token.
* If this task leads to a signal on the token, the given transition
* name will be used in the signal.
* If this task completion does not trigger execution to move on,
* the transitionName is ignored.
*/
public void end(String transitionName) {
Transition leavingTransition = null;
if (task!=null) {
Node node = task.getTaskNode();
if (node==null) {
node = (Node) task.getParent();
}
if (node!=null) {
leavingTransition = node.getLeavingTransition(transitionName);
}
}
if (leavingTransition==null) {
throw new NullPointerException("task node does not have leaving transition '"+transitionName+"'");
}
end(leavingTransition);
}
/**
* marks this task as done and specifies a transition
* leaving the task-node for the case that the completion of this
* task instances triggers a signal on the token.
* If this task leads to a signal on the token, the given transition
* name will be used in the signal.
* If this task completion does not trigger execution to move on,
* the transition is ignored.
*/
public void end(Transition transition) {
if (this.end!=null){
throw new IllegalStateException("task instance '"+id+"' is already ended");
}
if (this.isSuspended) {
throw new JbpmException("task instance '"+id+"' is suspended");
}
// mark the end of this task instance
this.end = new Date();
this.isOpen = false;
// fire the task instance end event
if ( (task!=null)
&& (token!=null)
) {
ExecutionContext executionContext = new ExecutionContext(token);
executionContext.setTask(task);
executionContext.setTaskInstance(this);
task.fireEvent(Event.EVENTTYPE_TASK_END, executionContext);
}
// log this assignment
if (token!=null) {
token.addLog(new TaskEndLog(this));
}
// submit the variables
submitVariables();
// verify if the end of this task triggers continuation of execution
if (isSignalling) {
this.isSignalling = false;
if ( this.isStartTaskInstance() // ending start tasks always leads to a signal
|| ( (task!=null)
&& (token!=null)
&& (task.getTaskNode()!=null)
&& (task.getTaskNode().completionTriggersSignal(this))
)
) {
if (transition==null) {
log.debug("completion of task '"+task.getName()+"' results in taking the default transition");
token.signal();
} else {
log.debug("completion of task '"+task.getName()+"' results in taking transition '"+transition+"'");
token.signal(transition);
}
}
}
}
public boolean hasEnded() {
return (end!=null);
}
/**
* suspends a process execution.
*/
public void suspend() {
isSuspended = true;
isOpen = false;
}
/**
* resumes a process execution.
*/
public void resume() {
isSuspended = false;
isOpen = true;
}
// comments /////////////////////////////////////////////////////////////////
public void addComment(String message) {
addComment(new Comment(message));
}
public void addComment(Comment comment) {
if (comment!=null) {
if (comments==null) comments = new ArrayList();
comments.add(comment);
comment.setTaskInstance(this);
if (token!=null) {
comment.setToken(token);
token.addComment(comment);
}
}
}
public List getComments() {
return comments;
}
// task form ////////////////////////////////////////////////////////////////
public boolean isLast() {
return ( (token!=null)
&& (taskMgmtInstance!=null)
&& (! taskMgmtInstance.hasUnfinishedTasks(token))
);
}
/**
* is the list of transitions that can be used in the end method
* and it is null in case this is not the last task instance.
*/
public List getAvailableTransitions() {
List transitions = null;
if ( (! isLast())
&& (token!=null)
) {
transitions = new ArrayList(token.getNode().getLeavingTransitions());
}
return transitions;
}
// equals ///////////////////////////////////////////////////////////////////
// hack to support comparing hibernate proxies against the real objects
// since this always falls back to ==, we don't need to overwrite the hashcode
public boolean equals(Object o) {
return EqualsUtil.equals(this, o);
}
public String toString() {
return "TaskInstance"+(name!=null ? "["+name+"]" : Integer.toHexString(System.identityHashCode(this)));
}
// private //////////////////////////////////////////////////////////////////
public void setPooledActors(Set pooledActors) {
if (pooledActors!=null) {
this.pooledActors = new HashSet(pooledActors);
Iterator iter = pooledActors.iterator();
while (iter.hasNext()) {
PooledActor pooledActor = (PooledActor) iter.next();
pooledActor.addTaskInstance(this);
}
} else {
pooledActors = null;
}
}
// protected ////////////////////////////////////////////////////////////////
protected VariableContainer getParentVariableContainer() {
ContextInstance contextInstance = getContextInstance();
return (contextInstance!=null ? contextInstance.getOrCreateTokenVariableMap(token) : null);
}
// getters and setters //////////////////////////////////////////////////////
public String getActorId() {
return actorId;
}
public Date getDueDate() {
return dueDate;
}
public void setDueDate(Date dueDate) {
this.dueDate = dueDate;
}
public Date getEnd() {
return end;
}
public void setEnd(Date end) {
this.end = end;
}
public void setCreate(Date create) {
this.create = create;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Date getStart() {
return start;
}
public TaskMgmtInstance getTaskMgmtInstance() {
return taskMgmtInstance;
}
public void setTaskMgmtInstance(TaskMgmtInstance taskMgmtInstance) {
this.taskMgmtInstance = taskMgmtInstance;
}
public Token getToken() {
return token;
}
public void setToken(Token token) {
this.token = token;
}
public void setSignalling(boolean isSignalling) {
this.isSignalling = isSignalling;
}
public boolean isSignalling() {
return isSignalling;
}
public boolean isCancelled() {
return isCancelled;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isBlocking() {
return isBlocking;
}
public void setBlocking(boolean isBlocking) {
this.isBlocking = isBlocking;
}
public Date getCreate() {
return create;
}
public Task getTask() {
return task;
}
public SwimlaneInstance getSwimlaneInstance() {
return swimlaneInstance;
}
public void setSwimlaneInstance(SwimlaneInstance swimlaneInstance) {
this.swimlaneInstance = swimlaneInstance;
}
public String getPreviousActorId() {
return previousActorId;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public boolean isOpen() {
return isOpen;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
private static final Log log = LogFactory.getLog(TaskInstance.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -