[jbpm-commits] JBoss JBPM SVN: r6688 - jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Sep 28 07:52:38 EDT 2010


Author: bradsdavis
Date: 2010-09-28 07:52:37 -0400 (Tue, 28 Sep 2010)
New Revision: 6688

Modified:
   jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/JmsConnectorService.java
Log:
Moved the message producer and session creation to be per-thread.

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-28 09:17:11 UTC (rev 6687)
+++ jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/src/main/java/org/jbpm/jms/JmsConnectorService.java	2010-09-28 11:52:37 UTC (rev 6688)
@@ -21,6 +21,9 @@
  */
 package org.jbpm.jms;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
 import javax.jms.Connection;
 import javax.jms.JMSException;
 import javax.jms.Message;
@@ -29,7 +32,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.jbpm.JbpmContext;
 import org.jbpm.JbpmException;
 import org.jbpm.db.JobSession;
@@ -42,6 +44,7 @@
 
 public class JmsConnectorService implements MessageService, SchedulerService {
 
+  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);
@@ -49,28 +52,18 @@
   private final JobSession jobSession;
 
   private final Connection connection;
-  private final Session session;
-  private final MessageProducer messageProducer;
-
+  
+  private final JmsConnectorServiceFactory factory;
+  
   public JmsConnectorService(JmsConnectorServiceFactory factory) throws JMSException {
     JbpmContext jbpmContext = factory.getJbpmConfiguration().getCurrentJbpmContext();
     if (jbpmContext == null) throw new JbpmException("no active jbpm context");
     jobSession = jbpmContext.getJobSession();
-
-    this.connection = factory.getConnectionFactory().createConnection();
-    /*
-     * 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 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-    messageProducer = session.createProducer(factory.getDestination());
+    
+    this.factory = factory;
+    this.connection = factory.getConnectionFactory().createConnection();    
   }
 
-  public Session getSession() {
-    return session;
-  }
-
   public void send(Job job) {
     jobSession.saveJob(job);
     sendWithoutSaving(job);
@@ -78,9 +71,25 @@
 
   void sendWithoutSaving(Job job) {
     try {
+      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageProducer messageProducer = session.createProducer(factory.getDestination());
       Message message = session.createMessage();
       populateMessage(message, job);
       messageProducer.send(message);
+      
+      try {
+          messageProducer.close();
+        }
+        catch (JMSException e) {
+          log.warn("could not close message producer", e);
+        }
+
+        try {
+          session.close();
+        }
+        catch (JMSException e) {
+          log.warn("could not close jms session", e);
+        }
     }
     catch (JMSException e) {
       throw new JbpmException("could not send jms message", e);
@@ -92,7 +101,13 @@
 
     if (job instanceof Timer) {
       Timer timer = (Timer) job;
+      
+      if(log.isDebugEnabled()) {
+    	log.debug("Creating timer for job: "+job.getId()+" to execute at: "+(timer.getDueDate() == null ? "no set date" : sdf.format(timer.getDueDate())));
+      }
       message.setLongProperty("JMS_JBOSS_SCHEDULED_DELIVERY", timer.getDueDate().getTime());
+      //higher priority for timers.
+      message.setJMSPriority(9);
     }
   }
 
@@ -113,24 +128,13 @@
   }
 
   public void close() {
-    try {
-      messageProducer.close();
+	try {
+      if(connection!=null)
+      {
+		connection.close();
+      }
     }
     catch (JMSException e) {
-      log.warn("could not close message producer", e);
-    }
-
-    try {
-      session.close();
-    }
-    catch (JMSException e) {
-      log.warn("could not close jms session", e);
-    }
-
-    try {
-      connection.close();
-    }
-    catch (JMSException e) {
       log.warn("could not close jms connection", e);
     }
   }



More information about the jbpm-commits mailing list