[jbpm-commits] JBoss JBPM SVN: r1925 - in jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm: scheduler/ejbtimer and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Aug 18 21:23:34 EDT 2008


Author: alex.guizar at jboss.com
Date: 2008-08-18 21:23:34 -0400 (Mon, 18 Aug 2008)
New Revision: 1925

Modified:
   jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java
   jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerService.java
   jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java
   jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java
Log:
restored the ability to override the jndi names used by the enterprise service factories in jbpm.cfg.xml: JBPM-960

Modified: jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java
===================================================================
--- jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java	2008-08-18 13:58:26 UTC (rev 1924)
+++ jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java	2008-08-19 01:23:34 UTC (rev 1925)
@@ -30,8 +30,6 @@
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.jbpm.JbpmException;
 import org.jbpm.ejb.impl.JobListenerBean;
 import org.jbpm.svc.Service;
@@ -55,11 +53,11 @@
  * Refer to the jBPM manual for details.
  * 
  * @author Tom Baeyens
+ * @author Alejandro Guizar
  */
 public class JmsMessageServiceFactoryImpl implements ServiceFactory {
 
   private static final long serialVersionUID = 1L;
-  private static final Log log = LogFactory.getLog(JmsMessageServiceFactoryImpl.class);
   
   String connectionFactoryJndiName = "java:comp/env/jms/JbpmConnectionFactory";
   String destinationJndiName = "java:comp/env/jms/JobQueue";
@@ -68,37 +66,55 @@
   private ConnectionFactory connectionFactory;
   private Destination destination;
 
-  public JmsMessageServiceFactoryImpl() {
+  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 {
-      Context initial = new InitialContext();
-      connectionFactory = (ConnectionFactory) initial.lookup(connectionFactoryJndiName);
-      destination = (Destination) initial.lookup(destinationJndiName);
+      return initial.lookup(name);
+    }
+    finally {
       initial.close();
     }
-    catch (NamingException e) {
-      log.error("jms object lookup problem", e);
-      throw new JbpmException("jms object lookup problem", e);
-    }
   }
 
   public Service openService() {
-    Connection connection = null;
-    Session session = null;
-    
     try {
-      connection = connectionFactory.createConnection();
-      
+      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 XQ connection factory, the first parameter specifies whether you want to have all message productions and 
+      // 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 = connection.createSession(true, Session.SESSION_TRANSACTED);
-      
-    } catch (JMSException e) {
-      throw new JbpmException("couldn't open jms message session", e);
-    }
-    
-    return new JmsMessageServiceImpl(connection, session, destination, isCommitEnabled);
+      Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+
+      return new JmsMessageServiceImpl(connection, session, getDestination(), isCommitEnabled);
+    } 
+    catch (JMSException e) {
+      throw new JbpmException("couldn't open message session", e);
+    }    
   }
 
   public void close() {

Modified: jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerService.java
===================================================================
--- jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerService.java	2008-08-18 13:58:26 UTC (rev 1924)
+++ jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerService.java	2008-08-19 01:23:34 UTC (rev 1925)
@@ -14,6 +14,10 @@
 import org.jbpm.job.Timer;
 import org.jbpm.scheduler.SchedulerService;
 
+/**
+ * @author Tom Baeyens
+ * @deprecated replaced by {@link EntitySchedulerService}
+ */
 public class EjbSchedulerService implements SchedulerService {
   
   private static final long serialVersionUID = 1L;

Modified: jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java
===================================================================
--- jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java	2008-08-18 13:58:26 UTC (rev 1924)
+++ jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java	2008-08-19 01:23:34 UTC (rev 1925)
@@ -4,34 +4,45 @@
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.jbpm.JbpmException;
 import org.jbpm.svc.Service;
 import org.jbpm.svc.ServiceFactory;
 
+/**
+ * @author Tom Baeyens
+ * @deprecated replaced by {@link EntitySchedulerServiceFactory}
+ */
 public class EjbSchedulerServiceFactory implements ServiceFactory {
 
   private static final long serialVersionUID = 1L;
 
-  private static final Log log = LogFactory.getLog(EjbSchedulerServiceFactory.class);
-
   String timerServiceHomeJndiName = "java:comp/env/ejb/LocalTimerServiceBean";
 
   private LocalTimerServiceHome timerServiceHome;
 
-  public EjbSchedulerServiceFactory() {
+  public LocalTimerServiceHome getTimerServiceHome() {
+    if (timerServiceHome == null) {
+      try {
+        timerServiceHome = (LocalTimerServiceHome) lookup(timerServiceHomeJndiName);
+      } catch (NamingException e) {
+        throw new JbpmException("ejb timer service lookup problem", e);
+      }
+    }
+    return timerServiceHome;
+  }
+
+  private static Object lookup(String name) throws NamingException {
+    Context initial = new InitialContext();
     try {
-      Context initial = new InitialContext();
-      timerServiceHome = (LocalTimerServiceHome) initial.lookup(timerServiceHomeJndiName);
-    } catch (NamingException e) {
-      log.error("ejb timer service lookup problem", e);
-      throw new JbpmException("ejb timer service lookup problem", e);
+      return initial.lookup(name);
     }
+    finally {
+      initial.close();
+    }
   }
 
   public Service openService() {
-    return new EjbSchedulerService(timerServiceHome);
+    return new EjbSchedulerService(getTimerServiceHome());
   }
 
   public void close() {

Modified: jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java
===================================================================
--- jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java	2008-08-18 13:58:26 UTC (rev 1924)
+++ jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java	2008-08-19 01:23:34 UTC (rev 1925)
@@ -4,8 +4,6 @@
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.jbpm.JbpmException;
 import org.jbpm.ejb.LocalTimerEntityHome;
 import org.jbpm.job.Timer;
@@ -28,30 +26,40 @@
  * Refer to the jBPM manual for details.
  *
  * @author Tom Baeyens
+ * @author Alejandro Guizar
  * @author Fady Matar
  */
 public class EntitySchedulerServiceFactory implements ServiceFactory {
 
   private static final long serialVersionUID = 1L;
 
-  private static final Log log = LogFactory.getLog(EntitySchedulerServiceFactory.class);
-
   String timerEntityHomeJndiName = "java:comp/env/ejb/LocalTimerEntityBean";
 
   private LocalTimerEntityHome timerEntityHome;
 
-  public EntitySchedulerServiceFactory() {
+  public LocalTimerEntityHome getTimerEntityHome() {
+    if (timerEntityHome == null) {
+      try {
+        timerEntityHome = (LocalTimerEntityHome) lookup(timerEntityHomeJndiName);
+      } catch (NamingException e) {
+        throw new JbpmException("ejb timer entity lookup problem", e);
+      }
+    }
+    return timerEntityHome;
+  }
+
+  private static Object lookup(String name) throws NamingException {
+    Context initial = new InitialContext();
     try {
-      Context initial = new InitialContext();
-      timerEntityHome = (LocalTimerEntityHome) initial.lookup(timerEntityHomeJndiName);
-    } catch (NamingException e) {
-      log.error("ejb timer entity lookup problem", e);
-      throw new JbpmException("ejb timer entity lookup problem", e);
+      return initial.lookup(name);
     }
+    finally {
+      initial.close();
+    }
   }
 
   public Service openService() {
-    return new EntitySchedulerService(timerEntityHome);
+    return new EntitySchedulerService(getTimerEntityHome());
   }
 
   public void close() {




More information about the jbpm-commits mailing list