[jbpm-commits] JBoss JBPM SVN: r2617 - in jbpm3/trunk: modules/enterprise/jar and 9 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Oct 24 21:14:15 EDT 2008
Author: alex.guizar at jboss.com
Date: 2008-10-24 21:14:15 -0400 (Fri, 24 Oct 2008)
New Revision: 2617
Added:
jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobsCommand.java
jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageService.java
jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java
Modified:
jbpm3/trunk/modules/enterprise/jar/pom.xml
jbpm3/trunk/modules/enterprise/jar/src/main/etc/jbpm.cfg.xml
jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java
jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java
jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java
jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceImpl.java
jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerService.java
jbpm3/trunk/modules/enterprise/jar/src/main/resources/META-INF/ejb-jar.xml
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/AppServerConfigurationsTest.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/msg/jms/JmsMessageTest.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java
jbpm3/trunk/modules/userguide/src/main/docbook/en/modules/enterprise.xml
jbpm3/trunk/pom.xml
Log:
[JBPM-1709] completed exclusive job support, still need to iron some wrinkles
Modified: jbpm3/trunk/modules/enterprise/jar/pom.xml
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/pom.xml 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/pom.xml 2008-10-25 01:14:15 UTC (rev 2617)
@@ -174,18 +174,6 @@
</excludes>
</configuration>
</plugin>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <!-- Please only remove excludes, when the tests are working -->
- <excludes>
- <!-- https://jira.jboss.org/jira/browse/JBPM-1708 -->
- <!-- exclude>org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java</exclude -->
- <!-- https://jira.jboss.org/jira/browse/JBPM-1709 -->
- <!-- exclude>org/jbpm/msg/jms/JmsMessageTest.java</exclude -->
- </excludes>
- </configuration>
- </plugin>
</plugins>
</build>
@@ -234,16 +222,57 @@
<name>log4j.output.dir</name>
<value>${basedir}/target</value>
</property>
- <property>
- <name>datasource.xa</name>
- <value>${datasource.xa}</value>
- </property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
+ <profile>
+ <id>no-xa-datasource</id>
+ <activation>
+ <property>
+ <name>!datasource.xa</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <!-- do not remove, ejb scheduler requires xa support -->
+ <exclude>org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java</exclude>
+ <!-- https://jira.jboss.org/jira/browse/JBPM-1709 -->
+ <exclude>org/jbpm/msg/jms/JmsMessageTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>xa-datasource</id>
+ <activation>
+ <property>
+ <name>datasource.xa</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <!-- https://jira.jboss.org/jira/browse/JBPM-1708 -->
+ <exclude>org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java</exclude>
+ <!-- https://jira.jboss.org/jira/browse/JBPM-1709 -->
+ <exclude>org/jbpm/msg/jms/JmsMessageTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
-
</project>
Modified: jbpm3/trunk/modules/enterprise/jar/src/main/etc/jbpm.cfg.xml
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/etc/jbpm.cfg.xml 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/etc/jbpm.cfg.xml 2008-10-25 01:14:15 UTC (rev 2617)
@@ -2,7 +2,7 @@
<jbpm-context>
<service name="persistence" factory="org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory" />
- <service name="message" factory="org.jbpm.msg.jms.JmsMessageServiceFactoryImpl" />
+ <service name="message" factory="org.jbpm.msg.jms.JmsMessageServiceFactory" />
<service name="scheduler" factory="org.jbpm.scheduler.ejbtimer.EntitySchedulerServiceFactory" />
<service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
<service name="logging" factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
Modified: jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -35,7 +35,7 @@
import org.jbpm.JbpmException;
import org.jbpm.command.Command;
import org.jbpm.command.CommandService;
-import org.jbpm.msg.jms.JmsMessageServiceFactoryImpl;
+import org.jbpm.msg.jms.JmsMessageServiceFactory;
import org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory;
/**
@@ -83,7 +83,7 @@
* <td><code>jms/JbpmConnectionFactory</code></td>
* <td>Resource Manager Reference</td>
* <td>Logical name of the factory that provides JMS connections to the
- * {@linkplain JmsMessageServiceFactoryImpl message service}. Required for
+ * {@linkplain JmsMessageServiceFactory message service}. Required for
* processes that contain asynchronous continuations.
* </td>
* </tr>
Modified: jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -1,3 +1,24 @@
+/*
+ * 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.ejb.impl;
import java.io.PrintWriter;
@@ -2,5 +23,11 @@
import java.io.StringWriter;
-import java.util.Iterator;
import java.util.List;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.naming.NamingException;
+
import org.apache.commons.logging.Log;
@@ -11,7 +38,14 @@
import org.jbpm.JbpmContext;
import org.jbpm.command.Command;
import org.jbpm.job.Job;
+import org.jbpm.msg.jms.JmsMessageService;
+import org.jbpm.msg.jms.JmsMessageServiceFactory;
+import org.jbpm.svc.Services;
+/**
+ * Individual job processing command.
+ * @author Alejandro Guizar
+ */
public class ExecuteJobCommand implements Command {
private final long jobId;
@@ -31,25 +65,28 @@
if (job.isExclusive()) {
// acquire exclusive jobs
List exclusiveJobs = jbpmContext.getSession().createCriteria(Job.class)
- .add(Restrictions.isNull("lockMode"))
- .add(Restrictions.eq("processInstance", job.getProcessInstance()))
- .list();
+ .add(Restrictions.isNull("lockMode"))
+ .add(Restrictions.eq("processInstance", job.getProcessInstance()))
+ .list();
String lockOwner = Long.toString(jobId);
- for (Iterator i = exclusiveJobs.iterator(); i.hasNext();) {
- Job exclusiveJob = (Job) i.next();
+ long[] exclusiveJobIds = new long[exclusiveJobs.size()];
+ for (int i = 0; i < exclusiveJobIds.length; i++) {
+ Job exclusiveJob = (Job) exclusiveJobs.get(i);
exclusiveJob.setLockOwner(lockOwner);
+ exclusiveJobIds[i] = exclusiveJob.getId();
}
// execute exclusive jobs in separate transaction
-
+ executeJobs(jbpmContext, exclusiveJobIds);
}
else {
- executeJob(job, jbpmContext);
+ executeJob(job, jbpmContext);
}
- return job;
+ return null;
}
- private static void executeJob(Job job, JbpmContext jbpmContext) {
- job.setLockOwner(ExecuteJobCommand.class.getName()); // prevent others from removing job
+ static void executeJob(Job job, JbpmContext jbpmContext) {
+ // prevent others from removing job
+ job.setLockOwner(ExecuteJobCommand.class.getName());
log.debug("executing " + job);
try {
if (job.execute(jbpmContext)) {
@@ -70,5 +107,24 @@
}
}
+ private static void executeJobs(JbpmContext jbpmContext, long[] exclusiveJobIds)
+ throws NamingException, JMSException {
+ Services services = jbpmContext.getServices();
+ JmsMessageServiceFactory messageServiceFactory = (JmsMessageServiceFactory) services.getServiceFactory(Services.SERVICENAME_MESSAGE);
+ Destination destination = messageServiceFactory.getCommandDestination();
+
+ JmsMessageService messageService = (JmsMessageService) services.getMessageService();
+ Session session = messageService.getSession();
+ MessageProducer producer = session.createProducer(destination);
+ try {
+ Command command = new ExecuteJobsCommand(exclusiveJobIds);
+ Message message = session.createObjectMessage(command);
+ producer.send(message);
+ }
+ finally {
+ producer.close();
+ }
+ }
+
private static Log log = LogFactory.getLog(ExecuteJobCommand.class);
}
Added: jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobsCommand.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobsCommand.java (rev 0)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobsCommand.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -0,0 +1,51 @@
+/*
+ * 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.ejb.impl;
+
+import org.jbpm.JbpmContext;
+import org.jbpm.command.Command;
+import org.jbpm.db.JobSession;
+import org.jbpm.job.Job;
+
+/**
+ * Batch job processing command.
+ * @author Alejandro Guizar
+ */
+public class ExecuteJobsCommand implements Command {
+
+ private long[] jobIds;
+ private static final long serialVersionUID = 1L;
+
+ public ExecuteJobsCommand(long[] jobIds) {
+ this.jobIds = jobIds;
+ }
+
+ public Object execute(JbpmContext jbpmContext) throws Exception {
+ JobSession jobSession = jbpmContext.getJobSession();
+ for (int i = 0; i < jobIds.length; i++) {
+ Job job = jobSession.loadJob(jobIds[i]);
+ ExecuteJobCommand.executeJob(job, jbpmContext);
+ }
+ return null;
+ }
+
+}
Copied: jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageService.java (from rev 2613, jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceImpl.java)
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageService.java (rev 0)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageService.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -0,0 +1,146 @@
+/*
+ * 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.msg.jms;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.jbpm.JbpmContext;
+import org.jbpm.JbpmException;
+import org.jbpm.db.JobSession;
+import org.jbpm.job.Job;
+import org.jbpm.msg.MessageService;
+
+public class JmsMessageService implements MessageService {
+
+ private static final long serialVersionUID = 1L;
+
+ JobSession jobSession = null;
+ Connection connection = null;
+ Session session = null;
+ Destination destination = null;
+ MessageProducer messageProducer = null;
+ boolean isCommitEnabled = false;
+
+ public JmsMessageService(Connection connection, Destination destination, boolean isCommitEnabled) throws JMSException {
+ JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
+ if (jbpmContext==null) {
+ throw new JbpmException("jms message service must be created inside a jbpm context");
+ }
+ this.jobSession = jbpmContext.getJobSession();
+
+ this.connection = connection;
+ this.destination = destination;
+ this.isCommitEnabled = isCommitEnabled;
+ /*
+ * If the connection supports XA, the session will always take part in the global transaction.
+ * Otherwise the first parameter specifies whether message productions and consumptions
+ * are part of a single transaction (TRUE) or performed immediately (FALSE).
+ * Messages are never meant to be received before the database transaction commits,
+ * hence the transacted is preferable.
+ */
+ session = connection.createSession(true, Session.SESSION_TRANSACTED);
+ }
+
+ public void send(Job job) {
+ try {
+ jobSession.saveJob(job);
+
+ Message message = session.createMessage();
+ message.setLongProperty("jobId", job.getId());
+ if (job.getToken()!=null) {
+ message.setLongProperty("tokenId", job.getToken().getId());
+ }
+ if (job.getProcessInstance()!=null) {
+ message.setLongProperty("processInstanceId", job.getProcessInstance().getId());
+ }
+ if (job.getTaskInstance()!=null) {
+ message.setLongProperty("taskInstanceId", job.getTaskInstance().getId());
+ }
+ getMessageProducer().send(message);
+ } catch (JMSException e) {
+ throw new JbpmException("couldn't send jms message", e);
+ }
+ }
+
+ public void close() {
+ JbpmException exception = null;
+
+ if (messageProducer!=null) {
+ try {
+ messageProducer.close();
+ } catch (Exception e) {
+ // NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
+ exception = new JbpmException("couldn't close message producer", e);
+ }
+ }
+
+ if (session!=null) {
+ if (isCommitEnabled) {
+ try {
+ session.commit();
+ } catch (Exception e) {
+ if (exception==null) {
+ exception = new JbpmException("couldn't commit JMS session", e);
+ }
+ }
+ }
+
+ try {
+ session.close();
+ } catch (Exception e) {
+ if (exception==null) {
+ exception = new JbpmException("couldn't close JMS session", e);
+ }
+ }
+ }
+
+ if (connection!=null) {
+ try {
+ connection.close();
+ } catch (Exception e) {
+ if (exception==null) {
+ exception = new JbpmException("couldn't close JMS connection", e);
+ }
+ }
+ }
+
+ if (exception!=null) {
+ throw exception;
+ }
+ }
+
+ public Session getSession() {
+ return session;
+ }
+
+ protected MessageProducer getMessageProducer() throws JMSException {
+ if (messageProducer==null) {
+ messageProducer = session.createProducer(destination);
+ }
+ return messageProducer;
+ }
+}
Copied: jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java (from rev 2613, jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java)
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java (rev 0)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -0,0 +1,128 @@
+/*
+ * 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.msg.jms;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jbpm.JbpmException;
+import org.jbpm.ejb.impl.JobListenerBean;
+import org.jbpm.svc.Service;
+import org.jbpm.svc.ServiceFactory;
+
+/**
+ * The JMS message service leverages the reliable communication infrastructure
+ * accessed through JMS interfaces to deliver asynchronous continuation
+ * messages to the {@link JobListenerBean}.
+ *
+ * <h3>Configuration</h3>
+ *
+ * The JMS message service factory exposes the following configurable fields.
+ *
+ * <ul>
+ * <li><code>connectionFactoryJndiName</code></li>
+ * <li><code>destinationJndiName</code></li>
+ * <li><code>isCommitEnabled</code></li>
+ * </ul>
+ *
+ * Refer to the jBPM manual for details.
+ *
+ * @author Tom Baeyens
+ * @author Alejandro Guizar
+ */
+public class JmsMessageServiceFactory implements ServiceFactory {
+
+ private static final long serialVersionUID = 1L;
+
+ String connectionFactoryJndiName = "java:comp/env/jms/JbpmConnectionFactory";
+ String destinationJndiName = "java:comp/env/jms/JobQueue";
+ String commandDestinationJndiName = "java:comp/env/jms/CommandQueue";
+ boolean isCommitEnabled = false;
+
+ private ConnectionFactory connectionFactory;
+ private Destination destination;
+ private Destination commandDestination;
+
+ public ConnectionFactory getConnectionFactory() {
+ if (connectionFactory == null) {
+ try {
+ connectionFactory = (ConnectionFactory) lookup(connectionFactoryJndiName);
+ }
+ catch (NamingException e) {
+ throw new JbpmException("could not retrieve message connection factory", e);
+ }
+ }
+ return connectionFactory;
+ }
+
+ public Destination getDestination() {
+ if (destination == null) {
+ try {
+ destination = (Destination) lookup(destinationJndiName);
+ }
+ catch (NamingException e) {
+ throw new JbpmException("could not retrieve message destination", e);
+ }
+ }
+ return destination;
+ }
+
+ public Destination getCommandDestination() {
+ return commandDestination;
+ }
+
+ public boolean isCommitEnabled() {
+ return isCommitEnabled;
+ }
+
+ private static Object lookup(String name) throws NamingException {
+ Context initial = new InitialContext();
+ try {
+ return initial.lookup(name);
+ }
+ finally {
+ initial.close();
+ }
+ }
+
+ public Service openService() {
+ try {
+ Connection connection = getConnectionFactory().createConnection();
+ return new JmsMessageService(connection, getDestination(), isCommitEnabled);
+ }
+ catch (JMSException e) {
+ throw new JbpmException("couldn't open message session", e);
+ }
+ }
+
+ public void close() {
+ connectionFactory = null;
+ destination = null;
+ commandDestination = null;
+ }
+
+}
Modified: jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -22,104 +22,28 @@
package org.jbpm.msg.jms;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
import javax.jms.JMSException;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
import org.jbpm.JbpmException;
-import org.jbpm.ejb.impl.JobListenerBean;
import org.jbpm.svc.Service;
-import org.jbpm.svc.ServiceFactory;
/**
- * The JMS message service leverages the reliable communication infrastructure
- * accessed through JMS interfaces to deliver asynchronous continuation
- * messages to the {@link JobListenerBean}.
- *
- * <h3>Configuration</h3>
- *
- * The JMS message service factory exposes the following configurable fields.
- *
- * <ul>
- * <li><code>connectionFactoryJndiName</code></li>
- * <li><code>destinationJndiName</code></li>
- * <li><code>isCommitEnabled</code></li>
- * </ul>
- *
- * Refer to the jBPM manual for details.
- *
- * @author Tom Baeyens
- * @author Alejandro Guizar
+ * Alias for {@link JmsMessageServiceFactory}, supplied for compatibility
+ * with the jBPM 3.2 series.
+ * @deprecated replaced by {@link JmsMessageServiceFactory}
*/
-public class JmsMessageServiceFactoryImpl implements ServiceFactory {
+public class JmsMessageServiceFactoryImpl extends JmsMessageServiceFactory {
private static final long serialVersionUID = 1L;
-
- String connectionFactoryJndiName = "java:comp/env/jms/JbpmConnectionFactory";
- String destinationJndiName = "java:comp/env/jms/JobQueue";
- boolean isCommitEnabled = false;
- private ConnectionFactory connectionFactory;
- private Destination destination;
-
- public ConnectionFactory getConnectionFactory() {
- if (connectionFactory == null) {
- try {
- connectionFactory = (ConnectionFactory) lookup(connectionFactoryJndiName);
- }
- catch (NamingException e) {
- throw new JbpmException("could not retrieve message connection factory", e);
- }
- }
- return connectionFactory;
- }
-
- public Destination getDestination() {
- if (destination == null) {
- try {
- destination = (Destination) lookup(destinationJndiName);
- }
- catch (NamingException e) {
- throw new JbpmException("could not retrieve message destination", e);
- }
- }
- return destination;
- }
-
- private static Object lookup(String name) throws NamingException {
- Context initial = new InitialContext();
- try {
- return initial.lookup(name);
- }
- finally {
- initial.close();
- }
- }
-
public Service openService() {
try {
Connection connection = getConnectionFactory().createConnection();
-
- // If you use an XA connection factory in JBoss, the parameters will be ignored. It will always take part in the global JTA transaction.
- // If you use a non XA connection factory, the first parameter specifies whether you want to have all message productions and
- // consumptions as part of one transaction (TRUE) or whether you want all productions and consumptions to be instantanious (FALSE)
- // Of course, we never want messages to be received before the current jbpm transaction commits so we just set it to true.
- Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-
- return new JmsMessageServiceImpl(connection, session, getDestination(), isCommitEnabled);
+ return new JmsMessageServiceImpl(connection, getDestination(), isCommitEnabled);
}
catch (JMSException e) {
throw new JbpmException("couldn't open message session", e);
- }
+ }
}
- public void close() {
- connectionFactory = null;
- destination = null;
- }
-
}
Modified: jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceImpl.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceImpl.java 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/msg/jms/JmsMessageServiceImpl.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -24,112 +24,18 @@
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import org.jbpm.JbpmContext;
-import org.jbpm.JbpmException;
-import org.jbpm.db.JobSession;
-import org.jbpm.job.Job;
-import org.jbpm.msg.MessageService;
+/**
+ * Alias for {@link JmsMessageService}, supplied for compatibility with the
+ * jBPM 3.2 series.
+ * @deprecated replaced by {@link JmsMessageService}
+ */
+public class JmsMessageServiceImpl extends JmsMessageService {
-public class JmsMessageServiceImpl implements MessageService {
-
private static final long serialVersionUID = 1L;
- JobSession jobSession = null;
- Connection connection = null;
- Session session = null;
- Destination destination = null;
- MessageProducer messageProducer = null;
- boolean isCommitEnabled = false;
-
- public JmsMessageServiceImpl(Connection connection, Session session, Destination destination, boolean isCommitEnabled) {
- this.connection = connection;
- this.session = session;
- this.destination = destination;
- this.isCommitEnabled = isCommitEnabled;
-
- JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
- if (jbpmContext==null) {
- throw new JbpmException("instantiation of the JmsMessageService requires a current JbpmContext");
- }
- this.jobSession = jbpmContext.getJobSession();
+ public JmsMessageServiceImpl(Connection connection, Destination destination, boolean isCommitEnabled) throws JMSException {
+ super(connection, destination, isCommitEnabled);
}
- public void send(Job job) {
- try {
- jobSession.saveJob(job);
-
- Message message = session.createMessage();
- message.setLongProperty("jobId", job.getId());
- if (job.getToken()!=null) {
- message.setLongProperty("tokenId", job.getToken().getId());
- }
- if (job.getProcessInstance()!=null) {
- message.setLongProperty("processInstanceId", job.getProcessInstance().getId());
- }
- if (job.getTaskInstance()!=null) {
- message.setLongProperty("taskInstanceId", job.getTaskInstance().getId());
- }
- getMessageProducer().send(message);
- } catch (JMSException e) {
- throw new JbpmException("couldn't send jms message", e);
- }
- }
-
- public void close() {
- JbpmException exception = null;
-
- if (messageProducer!=null) {
- try {
- messageProducer.close();
- } catch (Exception e) {
- // NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
- exception = new JbpmException("couldn't close message producer", e);
- }
- }
-
- if (session!=null) {
- if (isCommitEnabled) {
- try {
- session.commit();
- } catch (Exception e) {
- if (exception==null) {
- exception = new JbpmException("couldn't commit JMS session", e);
- }
- }
- }
-
- try {
- session.close();
- } catch (Exception e) {
- if (exception==null) {
- exception = new JbpmException("couldn't close JMS session", e);
- }
- }
- }
-
- if (connection!=null) {
- try {
- connection.close();
- } catch (Exception e) {
- if (exception==null) {
- exception = new JbpmException("couldn't close JMS connection", e);
- }
- }
- }
-
- if (exception!=null) {
- throw exception;
- }
- }
-
- protected MessageProducer getMessageProducer() throws JMSException {
- if (messageProducer==null) {
- messageProducer = session.createProducer(destination);
- }
- return messageProducer;
- }
}
Modified: jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerService.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerService.java 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerService.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -29,8 +29,7 @@
public EntitySchedulerService(LocalTimerEntityHome timerEntityHome) {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if(jbpmContext == null) {
- throw new JbpmException(
- "instantiation of the EjbSchedulerService requires a current JbpmContext");
+ throw new JbpmException("entity scheduler service must be created inside a jbpm context");
}
this.jobSession = jbpmContext.getJobSession();
this.session = jbpmContext.getSession();
Modified: jbpm3/trunk/modules/enterprise/jar/src/main/resources/META-INF/ejb-jar.xml
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/resources/META-INF/ejb-jar.xml 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/resources/META-INF/ejb-jar.xml 2008-10-25 01:14:15 UTC (rev 2617)
@@ -167,7 +167,7 @@
<message-destination-ref>
<description>
- Messages which do not contain a command are sent to the queue referenced here. Optional;
+ Messages that do not contain a command are sent to the queue referenced here. Optional;
if absent, such messages are rejected, which may cause the container to redeliver.
</description>
<message-destination-ref-name>jms/DeadLetterQueue</message-destination-ref-name>
@@ -211,7 +211,7 @@
<message-destination-ref>
<description>
- Messages which do not contain a job ID are sent to the queue referenced here. Optional; if
+ Messages that do not contain a job ID are sent to the queue referenced here. Optional; if
absent, such messages are rejected, which may cause the container to redeliver.
</description>
<message-destination-ref-name>jms/DeadLetterQueue</message-destination-ref-name>
Modified: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/AppServerConfigurationsTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/AppServerConfigurationsTest.java 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/AppServerConfigurationsTest.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -26,7 +26,7 @@
import org.apache.cactus.ServletTestCase;
import org.jbpm.JbpmConfiguration;
import org.jbpm.api.test.IntegrationTestSetup;
-import org.jbpm.msg.jms.JmsMessageServiceFactoryImpl;
+import org.jbpm.msg.jms.JmsMessageServiceFactory;
import org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory;
import org.jbpm.scheduler.ejbtimer.EntitySchedulerServiceFactory;
import org.jbpm.svc.Services;
@@ -55,7 +55,7 @@
public void testJmsMessageServiceFactoryConfiguration()
{
- assertSame(JmsMessageServiceFactoryImpl.class, jbpmConfiguration.getServiceFactory(Services.SERVICENAME_MESSAGE).getClass());
+ assertSame(JmsMessageServiceFactory.class, jbpmConfiguration.getServiceFactory(Services.SERVICENAME_MESSAGE).getClass());
}
public void testEjbSchedulerServiceFactoryConfiguration()
Modified: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/msg/jms/JmsMessageTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/msg/jms/JmsMessageTest.java 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/msg/jms/JmsMessageTest.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -44,7 +44,7 @@
import org.jbpm.graph.exe.ProcessInstance;
/**
- * Exercises for the {@linkplain JmsMessageServiceImpl JMS message service}.
+ * Exercises for the {@linkplain JmsMessageService JMS message service}.
* @author Alejandro Guizar
*/
public class JmsMessageTest extends ServletTestCase {
Modified: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java 2008-10-25 01:14:15 UTC (rev 2617)
@@ -60,9 +60,7 @@
private static final Log log = LogFactory.getLog(EjbSchedulerTest.class);
public static Test suite() throws Exception {
- return Boolean.getBoolean("datasource.xa") ?
- new IntegrationTestSetup(EjbSchedulerTest.class, "enterprise-test.war") :
- new TestSuite();
+ return new IntegrationTestSetup(EjbSchedulerTest.class, "enterprise-test.war");
}
protected void setUp() throws Exception {
Modified: jbpm3/trunk/modules/userguide/src/main/docbook/en/modules/enterprise.xml
===================================================================
--- jbpm3/trunk/modules/userguide/src/main/docbook/en/modules/enterprise.xml 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/modules/userguide/src/main/docbook/en/modules/enterprise.xml 2008-10-25 01:14:15 UTC (rev 2617)
@@ -67,12 +67,21 @@
logical destination, <literal>JobQueue</literal>.
</entry>
</row>
+ <row>
+ <entry><literal>jms/CommandQueue</literal></entry>
+ <entry>Message Destination Reference</entry>
+ <entry>The command listener bean receives messages from the queue referenced here.
+ To ensure this is the same queue to which command messages can be sent,
+ the <literal>message-destination-link element</literal> points to a common
+ logical destination, <literal>CommandQueue</literal>.
+ </entry>
+ </row>
</tbody>
</tgroup>
</table>
<para><literal>CommandListenerBean</literal> is a message-driven bean that listens
- on the <literal>JbpmCommandQueue</literal> for command messages. This bean delegates
+ on the <literal>CommandQueue</literal> for command messages. This bean delegates
command execution to the <literal>CommandServiceBean</literal>.
</para>
@@ -203,7 +212,7 @@
<service name="persistence"
factory="org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory" />
<service name="message"
- factory="org.jbpm.msg.jms.JmsMessageServiceFactoryImpl" />
+ factory="org.jbpm.msg.jms.JmsMessageServiceFactory" />
<service name="scheduler"
factory="org.jbpm.scheduler.ejbtimer.EntitySchedulerServiceFactory" />
</jbpm-context></programlisting>
@@ -245,7 +254,7 @@
</itemizedlist>
- <para><literal>JmsMessageServiceFactoryImpl</literal> leverages the reliable communication
+ <para><literal>JmsMessageServiceFactory</literal> leverages the reliable communication
infrastructure exposed through JMS interfaces to deliver asynchronous continuation messages
to the <literal>JobListenerBean</literal>. The JMS message service factory exposes the following
configurable fields.</para>
Modified: jbpm3/trunk/pom.xml
===================================================================
--- jbpm3/trunk/pom.xml 2008-10-25 01:08:36 UTC (rev 2616)
+++ jbpm3/trunk/pom.xml 2008-10-25 01:14:15 UTC (rev 2617)
@@ -520,7 +520,7 @@
</property>
</activation>
<properties>
- <datasource.xa>true</datasource.xa>
+ <datasource.xa />
</properties>
<dependencies>
<dependency>
@@ -545,7 +545,7 @@
</property>
</activation>
<properties>
- <datasource.xa>true</datasource.xa>
+ <datasource.xa />
</properties>
<dependencies>
<dependency>
More information about the jbpm-commits
mailing list