[jbpm-commits] JBoss JBPM SVN: r6702 - in jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm: jms and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Sep 29 17:53:03 EDT 2010
Author: alex.guizar at jboss.com
Date: 2010-09-29 17:53:02 -0400 (Wed, 29 Sep 2010)
New Revision: 6702
Removed:
jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/JmsUtil.java
Modified:
jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/ejb/CommandListenerBean.java
jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/ExecuteJobCommand.java
jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/JmsConnectorService.java
Log:
JBPM-2945 remove undeclared dependency on commons-lang (not worth including in distribution just for two logs)
simplify jms connection closing based on api note
Modified: jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/ejb/CommandListenerBean.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/ejb/CommandListenerBean.java 2010-09-29 21:14:17 UTC (rev 6701)
+++ jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/ejb/CommandListenerBean.java 2010-09-29 21:53:02 UTC (rev 6702)
@@ -38,11 +38,9 @@
import javax.jms.ObjectMessage;
import javax.jms.Session;
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.command.Command;
-import org.jbpm.jms.JmsUtil;
import org.jbpm.persistence.db.DbPersistenceService;
import org.jbpm.persistence.db.StaleObjectLogConfigurer;
@@ -92,10 +90,10 @@
@Resource
private MessageDrivenContext messageDrivenContext;
-
+
@EJB(name = "ejb/LocalCommandService")
private LocalCommandService commandService;
-
+
@Resource(name = "jms/JbpmConnectionFactory", shareable = true)
private ConnectionFactory jmsConnectionFactory;
@@ -105,27 +103,30 @@
try {
// extract command from message
Command command = extractCommand(message);
+ // a null return value means the message did not carry a valid command
+ // warnings were logged already; just swallow the message and return
if (command == null) return;
// execute command via local command executor bean
Object result;
try {
- if(log.isDebugEnabled()) {
- log.debug("Command: "+ReflectionToStringBuilder.toString(command)+" sent with Message["+message.toString()+"]");
- }
- result = commandService.execute(command);
-
- if(log.isTraceEnabled()) {
- log.trace("Command: "+ReflectionToStringBuilder.toString(command)+" sent with Message["+message.toString()+"] Completed Successfully. Committing.");
- }
+ if (log.isDebugEnabled()) {
+ log.debug("executing " + command);
+ }
+ result = commandService.execute(command);
+
+ if (log.isTraceEnabled()) {
+ log.trace(command + " completed successfully, committing");
+ }
}
catch (RuntimeException e) {
// if this is a locking exception, keep it quiet
if (DbPersistenceService.isLockingException(e)) {
- StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(message.toString()+"failed to execute " + command, e);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(message
+ + " failed to execute " + command, e);
}
else {
- log.error(message.toString()+" failed to execute " + command, e);
+ log.error(message + " failed to execute " + command, e);
}
// MDBs are not supposed to throw exceptions
messageDrivenContext.setRollbackOnly();
@@ -134,8 +135,7 @@
// send a response back if a "reply to" destination is set
Destination replyTo;
- if (jmsConnectionFactory != null
- && (replyTo = message.getJMSReplyTo()) != null
+ if (jmsConnectionFactory != null && (replyTo = message.getJMSReplyTo()) != null
&& (result instanceof Serializable || result == null)) {
sendResult((Serializable) result, replyTo, message.getJMSMessageID());
}
@@ -173,27 +173,29 @@
private void sendResult(Serializable result, Destination destination, String correlationId)
throws JMSException {
if (log.isDebugEnabled()) log.debug("sending " + result + " to " + destination);
-
- Connection jmsConnection = null;
- Session jmsSession = null;
- MessageProducer producer = null;
+
+ Connection jmsConnection = jmsConnectionFactory.createConnection();
try {
/*
* if the connection supports xa, the session will be transacted, else the session will
* auto acknowledge; in either case no explicit transaction control must be performed -
* see ejb 2.1 - 17.3.5
*/
- jmsConnection = jmsConnectionFactory.createConnection();
- jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Message resultMessage = jmsSession.createObjectMessage(result);
resultMessage.setJMSCorrelationID(correlationId);
- producer = jmsSession.createProducer(destination);
+ MessageProducer producer = jmsSession.createProducer(destination);
producer.send(resultMessage);
}
finally {
- JmsUtil.closeSilently(producer);
- JmsUtil.closeSilently(jmsSession);
- JmsUtil.closeSilently(jmsConnection);
+ // there is no need to close the sessions and producers of a closed connection
+ // http://download.oracle.com/javaee/1.4/api/javax/jms/Connection.html#close()
+ try {
+ jmsConnection.close();
+ }
+ catch (JMSException e) {
+ log.warn("failed to close jms connection", e);
+ }
}
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/ExecuteJobCommand.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/ExecuteJobCommand.java 2010-09-29 21:14:17 UTC (rev 6701)
+++ jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/ExecuteJobCommand.java 2010-09-29 21:53:02 UTC (rev 6702)
@@ -90,8 +90,14 @@
else {
// job is a repetitive timer
Timer timer = jbpmContext.getJobSession().loadTimer(job.getId());
- JmsConnectorService schedulerService = (JmsConnectorService) jbpmContext.getServices().getSchedulerService();
+ JmsConnectorService schedulerService = (JmsConnectorService) jbpmContext.getServices()
+ .getSchedulerService();
schedulerService.sendWithoutSaving(timer);
}
}
+
+ @Override
+ public String toString() {
+ return "ExecuteJobCommand(" + jobId + ")";
+ }
}
Modified: jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/JmsConnectorService.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/JmsConnectorService.java 2010-09-29 21:14:17 UTC (rev 6701)
+++ jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/JmsConnectorService.java 2010-09-29 21:53:02 UTC (rev 6702)
@@ -43,15 +43,14 @@
import org.jbpm.scheduler.SchedulerService;
public class JmsConnectorService implements MessageService, SchedulerService {
+
+ private final JobSession jobSession;
+ private final JmsConnectorServiceFactory factory;
private static final DateFormat sdf = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(JmsConnectorService.class);
-
- private final JobSession jobSession;
-
- private final JmsConnectorServiceFactory factory;
public JmsConnectorService(JmsConnectorServiceFactory factory) throws JMSException {
JbpmContext jbpmContext = factory.getJbpmConfiguration().getCurrentJbpmContext();
@@ -63,28 +62,34 @@
public void send(Job job) {
jobSession.saveJob(job);
- sendWithoutSaving(job);
+ try {
+ sendWithoutSaving(job);
+ }
+ catch (JMSException e) {
+ throw new JbpmException("failed to send job message", e);
+ }
}
- void sendWithoutSaving(Job job) {
- Connection connection = null;
- MessageProducer messageProducer = null;
- Session session = null;
+ void sendWithoutSaving(Job job) throws JMSException {
+ Connection connection = factory.getConnectionFactory().createConnection();
try {
- connection = factory.getConnectionFactory().createConnection();
- session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
- messageProducer = session.createProducer(factory.getDestination());
+ Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+
Message message = session.createMessage();
populateMessage(message, job);
+
+ MessageProducer messageProducer = session.createProducer(factory.getDestination());
messageProducer.send(message);
}
- catch (JMSException e) {
- throw new JbpmException("could not send jms message", e);
- }
finally {
- JmsUtil.closeSilently(messageProducer);
- JmsUtil.closeSilently(session);
- JmsUtil.closeSilently(connection);
+ // there is no need to close the sessions and producers of a closed connection
+ // http://download.oracle.com/javaee/1.4/api/javax/jms/Connection.html#close()
+ try {
+ connection.close();
+ }
+ catch (JMSException e) {
+ log.warn("failed to close jms connection", e);
+ }
}
}
Deleted: jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/JmsUtil.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/JmsUtil.java 2010-09-29 21:14:17 UTC (rev 6701)
+++ jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/JmsUtil.java 2010-09-29 21:53:02 UTC (rev 6702)
@@ -1,69 +0,0 @@
-package org.jbpm.jms;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Utility for handling common JMS tasks.
- *
- * @author Brad Davis
- *
- */
-public class JmsUtil {
-
- private static final Log log = LogFactory.getLog(JmsUtil.class);
- private JmsUtil(){
- //seal
- }
-
- /**
- * Call within the finally block to cleanup message producers.
- * @param producer
- */
- public static void closeSilently(MessageProducer producer)
- {
- if(producer!=null) {
- try {
- producer.close();
- } catch (JMSException e) {
- log.warn("issue closing message producer.",e);
- }
- }
- }
-
- /**
- * Call within the finally block to cleanup JMS sessions.
- * @param session
- */
- public static void closeSilently(Session session)
- {
- if(session!=null) {
- try {
- session.close();
- } catch(JMSException e) {
- log.warn("issue closing session.",e);
- }
- }
- }
-
- /**
- * Call within the finally block to cleanup JMS connections.
- * @param connection
- */
- public static void closeSilently(Connection connection)
- {
- if(connection!=null) {
- try {
- connection.close();
- } catch (JMSException e) {
- log.warn("issue closing connection.",e);
- }
- }
-
- }
-}
More information about the jbpm-commits
mailing list