[jbpm-commits] JBoss JBPM SVN: r4005 - in jbpm3/branches/jbpm-3.2.5.SP/modules/core/src: main/java/org/jbpm/job/executor and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Feb 23 13:37:53 EST 2009
Author: alex.guizar at jboss.com
Date: 2009-02-23 13:37:53 -0500 (Mon, 23 Feb 2009)
New Revision: 4005
Modified:
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/ExecuteActionJob.java
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/ExecuteNodeJob.java
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/Timer.java
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/jbpm2036/JBPM2036Test.java
Log:
JBPM-2036: unlock timer so that
(a) any job executor thread can acquire it next time
(b) other parts of the engine know it is not executing, and can be deleted
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/ExecuteActionJob.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/ExecuteActionJob.java 2009-02-23 15:02:58 UTC (rev 4004)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/ExecuteActionJob.java 2009-02-23 18:37:53 UTC (rev 4005)
@@ -24,10 +24,6 @@
public boolean execute(JbpmContext jbpmContext) throws Exception {
log.debug("job["+id+"] executes "+action);
- // add processInstance to autoSave field (For details refer to
- // https://jira.jboss.org/jira/browse/JBPM-1015)
- jbpmContext.addAutoSaveToken(token);
-
ExecutionContext executionContext = new ExecutionContext(token);
executionContext.setAction(action);
executionContext.setEvent(action.getEvent());
@@ -39,8 +35,6 @@
action.execute(executionContext);
}
- jbpmContext.save(processInstance);
-
return true;
}
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/ExecuteNodeJob.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/ExecuteNodeJob.java 2009-02-23 15:02:58 UTC (rev 4004)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/ExecuteNodeJob.java 2009-02-23 18:37:53 UTC (rev 4005)
@@ -23,14 +23,10 @@
public boolean execute(JbpmContext jbpmContext) throws Exception {
log.debug("job["+id+"] executes "+node);
- // add processInstance to autoSave field (For details refer to
- // https://jira.jboss.org/jira/browse/JBPM-1015)
- jbpmContext.addAutoSaveToken(token);
-
token.unlock(this.toString());
ExecutionContext executionContext = new ExecutionContext(token);
node.execute(executionContext);
- jbpmContext.save(processInstance);
+
return true;
}
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/Timer.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/Timer.java 2009-02-23 15:02:58 UTC (rev 4004)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/Timer.java 2009-02-23 18:37:53 UTC (rev 4005)
@@ -35,10 +35,6 @@
}
public boolean execute(JbpmContext jbpmContext) throws Exception {
- // add processInstance to autoSave field (For details refer to
- // https://jira.jboss.org/jira/browse/JBPM-1015)
- jbpmContext.addAutoSaveToken(token);
-
ExecutionContext executionContext = new ExecutionContext(token);
executionContext.setTimer(this);
@@ -87,19 +83,29 @@
token.signal(transitionName);
}
}
-
- // save the token
- jbpmContext.save(processInstance);
-
+
// if repeat is specified, reschedule the job
if (repeat!=null) {
- // suppose that it took the timer runner thread a
+ // 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.
- while (dueDate.getTime()<=System.currentTimeMillis()) {
- dueDate = businessCalendar.add(dueDate, new Duration(repeat));
- }
- log.debug("updated '"+this+"' for repetition on '"+formatDueDate(dueDate)+"'");
+ Duration interval = new Duration(repeat);
+ long currentTime = System.currentTimeMillis();
+
+ Date repeatDate = dueDate;
+ do {
+ repeatDate = businessCalendar.add(repeatDate, interval);
+ } while (repeatDate.getTime() <= currentTime);
+
+ log.debug("scheduling " + this + " for repeat on: " + formatDueDate(repeatDate));
+ dueDate = repeatDate;
+
+ // unlock timer so that:
+ // (a) any job executor thread can acquire it next time
+ // (b) other parts of the engine know it is not executing, and can be deleted
+ // see https://jira.jboss.org/jira/browse/JBPM-2036
+ lockOwner = null;
+
return false;
}
@@ -128,10 +134,10 @@
return text.toString();
}
- public static String formatDueDate(Date date) {
+ private static String formatDueDate(Date date) {
return new SimpleDateFormat(dateFormat).format(date);
}
-
+
public String getRepeat() {
return repeat;
}
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2009-02-23 15:02:58 UTC (rev 4004)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2009-02-23 18:37:53 UTC (rev 4005)
@@ -161,8 +161,12 @@
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 {
- log.debug("executing " + job);
if (job.execute(jbpmContext)) {
jobSession.deleteJob(job);
}
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/jbpm2036/JBPM2036Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/jbpm2036/JBPM2036Test.java 2009-02-23 15:02:58 UTC (rev 4004)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/jbpm2036/JBPM2036Test.java 2009-02-23 18:37:53 UTC (rev 4005)
@@ -1,5 +1,6 @@
package org.jbpm.jbpm2036;
+import org.jbpm.context.exe.ContextInstance;
import org.jbpm.db.AbstractDbTestCase;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.ProcessDefinition;
@@ -13,66 +14,68 @@
* @author Thomas.Diesler at jboss.com
* @since 11-Feb-2009
*/
-public class JBPM2036Test extends AbstractDbTestCase
-{
- public void testTimerAction()
- {
+public class JBPM2036Test extends AbstractDbTestCase {
+ public void testTimerAction() {
ProcessDefinition processDefinition = getProcessDefinition();
jbpmContext.deployProcessDefinition(processDefinition);
newTransaction();
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
jbpmContext.save(processInstance);
processJobs(30000);
- long piId = processInstance.getId();
- assertTrue("expected process instance " + piId + " to have ended",
- jbpmContext.loadProcessInstance(piId).hasEnded());
- assertEquals(1, TimerAction.getExecutionCount());
+ processInstance = jbpmContext.loadProcessInstance(processInstance.getId());
+ assertTrue("expected " + processInstance + " to have ended", processInstance.hasEnded());
+
+ ContextInstance contextInstance = processInstance.getContextInstance();
+ assertEquals(1, contextInstance.getVariable("chaos"));
+ assertEquals(1, contextInstance.getVariable("undead"));
}
- finally
- {
+ finally {
graphSession.deleteProcessDefinition(processDefinition.getId());
}
}
- private ProcessDefinition getProcessDefinition()
- {
+ private ProcessDefinition getProcessDefinition() {
return ProcessDefinition.parseXmlString("<process-definition name='jbpm2036'>"
+ " <start-state name='start'>"
+ " <transition to='midway'/>"
+ " </start-state>"
- + " <state name='midway'>"
- + " <timer name='chaos' duedate='1 second' repeat='5 seconds'>"
+ + " <task-node name='midway'>"
+ + " <timer name='chaos' duedate='1 second' repeat='yes'>"
+ " <action class='"
+ TimerAction.class.getName()
- + "' />"
+ + "'>"
+ + " <leave>true</leave>"
+ + " </action>"
+ " </timer>"
+ + " <task name='doit'>"
+ + " <timer name='undead' duedate='500 milliseconds' repeat='1 second'>"
+ + " <action class='"
+ + TimerAction.class.getName()
+ + "'/>"
+ + " </timer>"
+ + " </task>"
+ " <transition to='end'/>"
- + " </state>"
+ + " </task-node>"
+ " <end-state name='end' />"
+ "</process-definition>");
}
- public static class TimerAction implements ActionHandler
- {
- private static int executionCount = 0;
+ public static class TimerAction implements ActionHandler {
+ private boolean leave;
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception
- {
- executionContext.leaveNode();
- executionCount++;
- }
+ public void execute(ExecutionContext executionContext) throws Exception {
+ String timerName = executionContext.getTimer().getName();
+ Integer executionCount = (Integer) executionContext.getVariable(timerName);
+ executionContext.setVariable(timerName, executionCount != null ? executionCount + 1 : 1);
- public static int getExecutionCount()
- {
- return executionCount;
+ if (leave) executionContext.leaveNode();
}
}
}
More information about the jbpm-commits
mailing list