Author: bradsdavis
Date: 2010-09-28 08:18:27 -0400 (Tue, 28 Sep 2010)
New Revision: 6691
Modified:
jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/ejb/CommandListenerBean.java
Log:
Handled the closing of sessions, connections, and producers.
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-28
12:16:40 UTC (rev 6690)
+++
jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/ejb/CommandListenerBean.java 2010-09-28
12:18:27 UTC (rev 6691)
@@ -34,13 +34,14 @@
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;
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;
@@ -90,8 +91,10 @@
@Resource
private MessageDrivenContext messageDrivenContext;
+
@EJB(name = "ejb/LocalCommandService")
private LocalCommandService commandService;
+
@Resource(name = "jms/JbpmConnectionFactory", shareable = true)
private ConnectionFactory jmsConnectionFactory;
@@ -111,8 +114,7 @@
catch (RuntimeException e) {
// if this is a locking exception, keep it quiet
if (DbPersistenceService.isLockingException(e)) {
- StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error("failed to
execute "
- + command, e);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error("failed to
execute " + command, e);
}
else {
log.error("failed to execute " + command, e);
@@ -163,20 +165,27 @@
private void sendResult(Serializable result, Destination destination, String
correlationId)
throws JMSException {
if (log.isDebugEnabled()) log.debug("sending " + result + " to "
+ destination);
- Connection jmsConnection = jmsConnectionFactory.createConnection();
+
+ Connection jmsConnection = null;
+ Session jmsSession = null;
+ MessageProducer producer = null;
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
*/
- Session jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ jmsConnection = jmsConnectionFactory.createConnection();
+ jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Message resultMessage = jmsSession.createObjectMessage(result);
resultMessage.setJMSCorrelationID(correlationId);
- jmsSession.createProducer(destination).send(resultMessage);
+ producer = jmsSession.createProducer(destination);
+ producer.send(resultMessage);
}
finally {
- jmsConnection.close();
+ JmsUtil.closeSilently(producer);
+ JmsUtil.closeSilently(jmsSession);
+ JmsUtil.closeSilently(jmsConnection);
}
}
}
Show replies by date