[jbpm-commits] JBoss JBPM SVN: r2657 - in jbpm3/trunk/modules/core/src: test/java/org/jbpm and 3 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Oct 29 10:12:23 EDT 2008
Author: tom.baeyens at jboss.com
Date: 2008-10-29 10:12:23 -0400 (Wed, 29 Oct 2008)
New Revision: 2657
Added:
jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/
jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/AsyncAction.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/CustomJobExecutor.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/CustomJobExecutorThread.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java
jbpm3/trunk/modules/core/src/test/resources/org/jbpm/seam/
jbpm3/trunk/modules/core/src/test/resources/org/jbpm/seam/custom.job.executor.jbpm.cfg.xml
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
Log:
[JBPM-1166] fix SEAM timer tx integration problem
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java 2008-10-29 13:01:28 UTC (rev 2656)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java 2008-10-29 14:12:23 UTC (rev 2657)
@@ -20,24 +20,24 @@
private static final long serialVersionUID = 1L;
- JbpmConfiguration jbpmConfiguration;
- String name;
- int nbrOfThreads;
- int idleInterval;
- int maxIdleInterval;
- int historyMaxSize;
+ protected JbpmConfiguration jbpmConfiguration;
+ protected String name;
+ protected int nbrOfThreads;
+ protected int idleInterval;
+ protected int maxIdleInterval;
+ protected int historyMaxSize;
- int maxLockTime;
- int lockMonitorInterval;
- int lockBufferTime;
+ protected int maxLockTime;
+ protected int lockMonitorInterval;
+ protected int lockBufferTime;
- Map threads = new HashMap();
- LockMonitorThread lockMonitorThread;
- Map monitoredJobIds = Collections.synchronizedMap(new HashMap());
+ protected Map threads = new HashMap();
+ protected LockMonitorThread lockMonitorThread;
+ protected Map monitoredJobIds = Collections.synchronizedMap(new HashMap());
- boolean isStarted = false;
+ protected boolean isStarted = false;
- private static String hostName;
+ protected static String hostName;
public synchronized void start() {
if (! isStarted) {
@@ -86,12 +86,16 @@
protected synchronized void startThread() {
String threadName = getNextThreadName();
- Thread thread = new JobExecutorThread(threadName, this, jbpmConfiguration, idleInterval, maxIdleInterval, maxLockTime, historyMaxSize);
+ Thread thread = createThread(threadName);
threads.put(threadName, thread);
log.debug("starting new job executor thread '"+threadName+"'");
thread.start();
}
+ protected Thread createThread(String threadName) {
+ return new JobExecutorThread(threadName, this, jbpmConfiguration, idleInterval, maxIdleInterval, maxLockTime, historyMaxSize);
+ }
+
protected String getNextThreadName() {
return getThreadName(threads.size()+1);
}
Added: jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/AsyncAction.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/AsyncAction.java (rev 0)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/AsyncAction.java 2008-10-29 14:12:23 UTC (rev 2657)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.seam;
+
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.exe.ExecutionContext;
+
+public class AsyncAction implements ActionHandler {
+ public void execute(ExecutionContext executionContext) throws Exception {
+ JobExecutorCustomizationTest.jobEvents.add("execute action");
+ }
+}
\ No newline at end of file
Added: jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/CustomJobExecutor.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/CustomJobExecutor.java (rev 0)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/CustomJobExecutor.java 2008-10-29 14:12:23 UTC (rev 2657)
@@ -0,0 +1,11 @@
+package org.jbpm.seam;
+
+import org.jbpm.job.executor.JobExecutor;
+
+public class CustomJobExecutor extends JobExecutor {
+ private static final long serialVersionUID = 1L;
+
+ protected Thread createThread(String threadName) {
+ return new CustomJobExecutorThread(threadName, this, jbpmConfiguration, idleInterval, maxIdleInterval, maxLockTime, historyMaxSize);
+ }
+}
Added: jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/CustomJobExecutorThread.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/CustomJobExecutorThread.java (rev 0)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/CustomJobExecutorThread.java 2008-10-29 14:12:23 UTC (rev 2657)
@@ -0,0 +1,24 @@
+package org.jbpm.seam;
+
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.job.Job;
+import org.jbpm.job.executor.JobExecutor;
+import org.jbpm.job.executor.JobExecutorThread;
+
+public class CustomJobExecutorThread extends JobExecutorThread {
+
+ public CustomJobExecutorThread(String name, JobExecutor jobExecutor, JbpmConfiguration jbpmConfiguration, int idleInterval, int maxIdleInterval, long maxLockTime, int maxHistory) {
+ super(name, jobExecutor, jbpmConfiguration, idleInterval, maxIdleInterval, maxLockTime, maxHistory);
+ }
+
+ protected void executeJob(Job job) {
+ // intercept before
+ JobExecutorCustomizationTest.jobEvents.add("before");
+ try {
+ super.executeJob(job);
+ } finally {
+ // intercept after
+ JobExecutorCustomizationTest.jobEvents.add("after");
+ }
+ }
+}
Added: jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java (rev 0)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java 2008-10-29 14:12:23 UTC (rev 2657)
@@ -0,0 +1,63 @@
+package org.jbpm.seam;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.job.executor.JobExecutor;
+
+
+public class JobExecutorCustomizationTest extends AbstractDbTestCase {
+
+ public static List jobEvents = new ArrayList();
+
+ protected String getJbpmTestConfig() {
+ return "org/jbpm/seam/custom.job.executor.jbpm.cfg.xml";
+ }
+
+ public void testCustomJobExecutor() {
+ JobExecutor jobExecutor = getJbpmConfiguration().getJobExecutor();
+ assertEquals(CustomJobExecutor.class, jobExecutor.getClass());
+
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
+ "<process-definition name='customjobexecution' initial='start'>" +
+ " <node name='start'>" +
+ " <transition to='end'>" +
+ " <action async='true' class='"+AsyncAction.class.getName()+"' />" +
+ " </transition>" +
+ " </node>" +
+ " <state name='end' />" +
+ "</process-definition>"
+ );
+ jbpmContext.deployProcessDefinition(processDefinition);
+ long processDefinitionId = processDefinition.getId();
+ try {
+
+ newTransaction();
+
+ jbpmContext.newProcessInstanceForUpdate("customjobexecution");
+
+ newTransaction();
+
+ jobExecutor.start();
+ try {
+ waitForJobs(8000, 0);
+ } finally {
+ jobExecutor.stop();
+ }
+
+ } finally {
+ newTransaction();
+
+ graphSession.deleteProcessDefinition(processDefinitionId);
+ }
+
+ List expectedJobEvents = new ArrayList();
+ expectedJobEvents.add("before");
+ expectedJobEvents.add("execute action");
+ expectedJobEvents.add("after");
+
+ assertEquals(expectedJobEvents, jobEvents);
+ }
+}
Added: jbpm3/trunk/modules/core/src/test/resources/org/jbpm/seam/custom.job.executor.jbpm.cfg.xml
===================================================================
--- jbpm3/trunk/modules/core/src/test/resources/org/jbpm/seam/custom.job.executor.jbpm.cfg.xml (rev 0)
+++ jbpm3/trunk/modules/core/src/test/resources/org/jbpm/seam/custom.job.executor.jbpm.cfg.xml 2008-10-29 14:12:23 UTC (rev 2657)
@@ -0,0 +1,13 @@
+<jbpm-configuration>
+ <bean name="jbpm.job.executor" class="org.jbpm.seam.CustomJobExecutor">
+ <field name="jbpmConfiguration"><ref bean="jbpmConfiguration" /></field>
+ <field name="name"><string value="JbpmJobExecutor" /></field>
+ <field name="nbrOfThreads"><int value="1" /></field>
+ <field name="idleInterval"><int value="5000" /></field>
+ <field name="maxIdleInterval"><int value="3600000" /></field> <!-- 1 hour -->
+ <field name="historyMaxSize"><int value="20" /></field>
+ <field name="maxLockTime"><int value="600000" /></field> <!-- 10 minutes -->
+ <field name="lockMonitorInterval"><int value="60000" /></field> <!-- 1 minute -->
+ <field name="lockBufferTime"><int value="5000" /></field> <!-- 5 seconds -->
+ </bean>
+</jbpm-configuration>
\ No newline at end of file
More information about the jbpm-commits
mailing list