001: package org.jbpm.job;
002:
003: import java.io.Serializable;
004: import java.text.DateFormat;
005: import java.text.SimpleDateFormat;
006: import java.util.Date;
007:
008: import org.jbpm.JbpmContext;
009: import org.jbpm.graph.exe.ProcessInstance;
010: import org.jbpm.graph.exe.Token;
011: import org.jbpm.taskmgmt.exe.TaskInstance;
012:
013: public abstract class Job implements Serializable {
014:
015: private static final long serialVersionUID = 1L;
016: private static final DateFormat dateFormat = new SimpleDateFormat(
017: "dd-MMM-yyyy HH:mm:ss,SSS");
018:
019: long id;
020: int version;
021:
022: Date dueDate;
023:
024: ProcessInstance processInstance;
025: Token token;
026: TaskInstance taskInstance;
027:
028: boolean isSuspended;
029:
030: /**
031: * specifies if this job can be executed concurrently with other jobs for the
032: * same process instance.
033: */
034: boolean isExclusive;
035:
036: /**
037: * name of the job executor thread that has locked this job.
038: */
039: String lockOwner;
040:
041: /**
042: * the time the job executor thread locked this job.
043: */
044: Date lockTime;
045:
046: String exception;
047: int retries = 1;
048:
049: String configuration;
050:
051: public Job() {
052: }
053:
054: public Job(Token token) {
055: this .token = token;
056: this .processInstance = token.getProcessInstance();
057: }
058:
059: public abstract boolean execute(JbpmContext jbpmContext)
060: throws Exception;
061:
062: public String toString() {
063: return "job[" + id + "]";
064: }
065:
066: public String toStringLongFormat() {
067: return "id=" + id + ", version=" + version + ", dueDate="
068: + (dueDate != null ? dateFormat.format(dueDate) : null)
069: + ", isSuspended=" + isSuspended + ", isExclusive="
070: + isExclusive + ", lockOwner=" + lockOwner
071: + ", lockTime=" + lockTime + ", exception=" + exception
072: + ", retries=" + retries + ", configuration="
073: + configuration;
074: }
075:
076: public ProcessInstance getProcessInstance() {
077: return processInstance;
078: }
079:
080: public void setProcessInstance(ProcessInstance processInstance) {
081: this .processInstance = processInstance;
082: }
083:
084: public Token getToken() {
085: return token;
086: }
087:
088: public void setToken(Token token) {
089: this .token = token;
090: }
091:
092: public long getId() {
093: return id;
094: }
095:
096: public Date getAqcuireDate() {
097: return lockTime;
098: }
099:
100: public void setLockTime(Date aqcuireDate) {
101: this .lockTime = aqcuireDate;
102: }
103:
104: public Date getDueDate() {
105: return dueDate;
106: }
107:
108: public void setDueDate(Date dueDate) {
109: this .dueDate = dueDate;
110: }
111:
112: public String getException() {
113: return exception;
114: }
115:
116: public void setException(String exception) {
117: this .exception = exception;
118: }
119:
120: public boolean isExclusive() {
121: return isExclusive;
122: }
123:
124: public void setExclusive(boolean isExclusive) {
125: this .isExclusive = isExclusive;
126: }
127:
128: public String getJobExecutorName() {
129: return lockOwner;
130: }
131:
132: public void setLockOwner(String jobExecutorName) {
133: this .lockOwner = jobExecutorName;
134: }
135:
136: public int getRetries() {
137: return retries;
138: }
139:
140: public void setRetries(int retries) {
141: this .retries = retries;
142: }
143:
144: public TaskInstance getTaskInstance() {
145: return taskInstance;
146: }
147:
148: public void setTaskInstance(TaskInstance taskInstance) {
149: this .taskInstance = taskInstance;
150: }
151:
152: public String getConfiguration() {
153: return configuration;
154: }
155:
156: public void setConfiguration(String configuration) {
157: this .configuration = configuration;
158: }
159:
160: public String getLockOwner() {
161: return lockOwner;
162: }
163:
164: public Date getLockTime() {
165: return lockTime;
166: }
167:
168: public boolean isSuspended() {
169: return isSuspended;
170: }
171:
172: public void setSuspended(boolean isSuspended) {
173: this .isSuspended = isSuspended;
174: }
175:
176: public int getVersion() {
177: return version;
178: }
179: }
|