Author: alex.guizar(a)jboss.com
Date: 2009-02-28 16:26:56 -0500 (Sat, 28 Feb 2009)
New Revision: 4088
Modified:
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/ExecuteActionJob.java
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/ExecuteNodeJob.java
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/Timer.java
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
jbpm3/branches/jbpm-3.2.6.GA/modules/enterprise/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java
Log:
move addAutoSaveProcessInstance calls back to each job, as in the JBPM-1015 resolution
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4213963
Modified:
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/ExecuteActionJob.java
===================================================================
---
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/ExecuteActionJob.java 2009-02-28
16:55:18 UTC (rev 4087)
+++
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/ExecuteActionJob.java 2009-02-28
21:26:56 UTC (rev 4088)
@@ -13,25 +13,32 @@
private static final long serialVersionUID = 1L;
Action action;
-
+
public ExecuteActionJob() {
}
-
+
public ExecuteActionJob(Token token) {
super(token);
}
-
+
public boolean execute(JbpmContext jbpmContext) throws Exception {
- log.debug("job["+id+"] executes "+action);
-
+ log.debug("job[" + id + "] executes " + action);
+
+ // register process instance for automatic save
+ // see
https://jira.jboss.org/jira/browse/JBPM-1015
+ jbpmContext.addAutoSaveProcessInstance(processInstance);
+
+ // prepare execution context
ExecutionContext executionContext = new ExecutionContext(token);
executionContext.setAction(action);
executionContext.setEvent(action.getEvent());
-
- Node node = (token!=null ? token.getNode() : null);
- if (node!=null) {
+
+ // then execute the action
+ Node node = token != null ? token.getNode() : null;
+ if (node != null) {
node.executeAction(action, executionContext);
- } else {
+ }
+ else {
action.execute(executionContext);
}
@@ -41,9 +48,10 @@
public Action getAction() {
return action;
}
+
public void setAction(Action action) {
this.action = action;
}
-
+
private static Log log = LogFactory.getLog(ExecuteActionJob.class);
}
Modified:
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/ExecuteNodeJob.java
===================================================================
---
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/ExecuteNodeJob.java 2009-02-28
16:55:18 UTC (rev 4087)
+++
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/ExecuteNodeJob.java 2009-02-28
21:26:56 UTC (rev 4088)
@@ -10,7 +10,7 @@
public class ExecuteNodeJob extends Job {
private static final long serialVersionUID = 1L;
-
+
Node node;
public ExecuteNodeJob() {
@@ -19,20 +19,28 @@
public ExecuteNodeJob(Token token) {
super(token);
}
-
- public boolean execute(JbpmContext jbpmContext) throws Exception {
- log.debug("job["+id+"] executes "+node);
+ public boolean execute(JbpmContext jbpmContext) throws Exception {
+ log.debug("job[" + id + "] executes " + node);
+
+ // register process instance for automatic save
+ // see
https://jira.jboss.org/jira/browse/JBPM-1015
+ jbpmContext.addAutoSaveProcessInstance(processInstance);
+
+ // unlock token in case it leaves the node
token.unlock(this.toString());
+ // prepare execution context
ExecutionContext executionContext = new ExecutionContext(token);
+ // then execute the node
node.execute(executionContext);
return true;
}
-
+
public Node getNode() {
return node;
}
+
public void setNode(Node node) {
this.node = node;
}
Modified: jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/Timer.java
===================================================================
---
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/Timer.java 2009-02-28
16:55:18 UTC (rev 4087)
+++
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/Timer.java 2009-02-28
21:26:56 UTC (rev 4088)
@@ -20,13 +20,13 @@
private final static String dateFormat = "yyyy-MM-dd HH:mm:ss,SSS";
static BusinessCalendar businessCalendar = new BusinessCalendar();
-
+
String name;
String repeat;
String transitionName = null;
Action action = null;
GraphElement graphElement = null;
-
+
public Timer() {
}
@@ -35,57 +35,62 @@
}
public boolean execute(JbpmContext jbpmContext) throws Exception {
+ // register process instance for automatic save
+ // see
https://jira.jboss.org/jira/browse/JBPM-1015
+ jbpmContext.addAutoSaveProcessInstance(processInstance);
+
+ // prepare execution context
ExecutionContext executionContext = new ExecutionContext(token);
executionContext.setTimer(this);
+ if (taskInstance != null) executionContext.setTaskInstance(taskInstance);
- if (taskInstance!=null) {
- executionContext.setTaskInstance(taskInstance);
- }
-
// first fire the event if there is a graph element specified
- if (graphElement!=null) {
+ if (graphElement != null) {
graphElement.fireAndPropagateEvent(Event.EVENTTYPE_TIMER, executionContext);
}
// then execute the action if there is one
- if (action!=null) {
+ if (action != null) {
try {
- log.debug("executing '"+this+"'");
- if (graphElement!=null) {
+ log.debug("executing " + this);
+ if (graphElement != null) {
graphElement.executeAction(action, executionContext);
- } else {
+ }
+ else {
action.execute(executionContext);
}
- } catch (Exception actionException) {
+ }
+ catch (Exception actionException) {
// NOTE that Error's are not caught because that might halt the JVM and mask
the original Error.
log.warn("timer action threw exception", actionException);
// if there is a graphElement connected to this timer...
if (graphElement != null) {
try {
- // we give that graphElement a chance to catch the exception
+ // give that graphElement a chance to catch the exception
graphElement.raiseException(actionException, executionContext);
- log.debug("timer exception got handled by
'"+graphElement+"'");
- } catch (Exception handlerException) {
+ log.debug("timer exception got handled by '" + graphElement +
"'");
+ }
+ catch (Exception handlerException) {
// if the exception handler rethrows or the original exception results in a
DelegationException...
throw handlerException;
}
- } else {
+ }
+ else {
throw actionException;
}
}
}
// then take a transition if one is specified
- if ( (transitionName!=null)
- && (exception==null) // and if no unhandled exception occurred during
the action
- ) {
+ // and if no unhandled exception occurred during the action
+ if (transitionName != null && exception == null) {
if (token.getNode().hasLeavingTransition(transitionName)) {
token.signal(transitionName);
}
}
// if repeat is specified, reschedule the job
- if (repeat!=null) {
+ if (repeat != null) {
// suppose that it took the timer runner thread a
// very long time to execute the timers.
// then the repeat action dueDate could already have passed.
@@ -108,26 +113,22 @@
return false;
}
-
+
return true;
}
-
+
public String toString() {
StringBuilder text = new StringBuilder("Timer");
if (name != null || dueDate != null) {
text.append('(');
- if (name!=null)
- text.append(name).append(",");
- if (dueDate!=null)
- text.append(formatDueDate(dueDate)).append(",");
- if (taskInstance!=null)
- text.append(taskInstance).append(",");
+ if (name != null) text.append(name).append(",");
+ if (dueDate != null) text.append(formatDueDate(dueDate)).append(",");
+ if (taskInstance != null) text.append(taskInstance).append(",");
- if (token!=null)
+ if (token != null)
text.append(token);
- else if (processInstance!=null)
- text.append(processInstance);
+ else if (processInstance != null) text.append(processInstance);
text.append(')');
}
@@ -141,33 +142,42 @@
public String getRepeat() {
return repeat;
}
+
public void setRepeat(String repeat) {
this.repeat = repeat;
}
+
public String getName() {
return name;
}
+
public void setName(String name) {
this.name = name;
}
+
public String getTransitionName() {
return transitionName;
}
+
public void setTransitionName(String transitionName) {
this.transitionName = transitionName;
}
+
public GraphElement getGraphElement() {
return graphElement;
}
+
public void setGraphElement(GraphElement graphElement) {
this.graphElement = graphElement;
}
+
public Action getAction() {
return action;
}
+
public void setAction(Action action) {
this.action = action;
}
-
+
private static Log log = LogFactory.getLog(Timer.class);
}
Modified:
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
===================================================================
---
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2009-02-28
16:55:18 UTC (rev 4087)
+++
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2009-02-28
21:26:56 UTC (rev 4088)
@@ -164,10 +164,6 @@
JobSession jobSession = jbpmContext.getJobSession();
job = jobSession.loadJob(job.getId());
- // register process instance for automatic save
- // see
https://jira.jboss.org/jira/browse/JBPM-1015
- jbpmContext.addAutoSaveProcessInstance(job.getProcessInstance());
-
log.debug("executing " + job);
try {
if (job.execute(jbpmContext)) {
Modified:
jbpm3/branches/jbpm-3.2.6.GA/modules/enterprise/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java
===================================================================
---
jbpm3/branches/jbpm-3.2.6.GA/modules/enterprise/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java 2009-02-28
16:55:18 UTC (rev 4087)
+++
jbpm3/branches/jbpm-3.2.6.GA/modules/enterprise/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java 2009-02-28
21:26:56 UTC (rev 4088)
@@ -29,7 +29,6 @@
import org.jbpm.JbpmContext;
import org.jbpm.JbpmException;
import org.jbpm.command.Command;
-import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.job.Job;
import org.jbpm.persistence.db.DbPersistenceService;
@@ -57,14 +56,9 @@
private Job acquireJob(JbpmContext jbpmContext) {
Job job = jbpmContext.getJobSession().loadJob(jobId);
- // register process instance for automatic save
- // see
https://jira.jboss.org/jira/browse/JBPM-1015
- ProcessInstance processInstance = job.getProcessInstance();
- jbpmContext.addAutoSaveProcessInstance(processInstance);
-
// if job is exclusive, lock process instance
if (job.isExclusive()) {
- jbpmContext.getGraphSession().lockProcessInstance(processInstance);
+ jbpmContext.getGraphSession().lockProcessInstance(job.getProcessInstance());
}
// mark job as locked to prevent other parts of the engine from deleting it