[jbpm-commits] JBoss JBPM SVN: r1968 - in jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm: scheduler/ejbtimer and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Aug 21 19:22:35 EDT 2008


Author: alex.guizar at jboss.com
Date: 2008-08-21 19:22:35 -0400 (Thu, 21 Aug 2008)
New Revision: 1968

Modified:
   jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java
   jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerService.java
   jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java
   jbpm3/branches/jpdl-3.2.3.CP/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/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java
===================================================================
--- jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java	2008-08-21 23:16:05 UTC (rev 1967)
+++ jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactoryImpl.java	2008-08-21 23:22:35 UTC (rev 1968)
@@ -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;
@@ -59,7 +57,6 @@
 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 +65,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 initialContext = new InitialContext();
     try {
-      Context initial = new InitialContext();
-      connectionFactory = (ConnectionFactory) initial.lookup(connectionFactoryJndiName);
-      destination = (Destination) initial.lookup(destinationJndiName);
-      initial.close();
+      return initialContext.lookup(name);
     }
-    catch (NamingException e) {
-      log.error("jms object lookup problem", e);
-      throw new JbpmException("jms object lookup problem", e);
+    finally {
+      initialContext.close();
     }
   }
 
   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 
       // 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) {
+      Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+
+      return new JmsMessageServiceImpl(connection, session, getDestination(), isCommitEnabled);
+    }
+    catch (JMSException e) {
       throw new JbpmException("couldn't open jms message session", e);
     }
-    
-    return new JmsMessageServiceImpl(connection, session, destination, isCommitEnabled);
   }
 
   public void close() {

Modified: jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerService.java
===================================================================
--- jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerService.java	2008-08-21 23:16:05 UTC (rev 1967)
+++ jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerService.java	2008-08-21 23:22:35 UTC (rev 1968)
@@ -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/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java
===================================================================
--- jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java	2008-08-21 23:16:05 UTC (rev 1967)
+++ jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java	2008-08-21 23:22:35 UTC (rev 1968)
@@ -1,37 +1,37 @@
 package org.jbpm.scheduler.ejbtimer;
 
-import javax.naming.Context;
 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() {
-    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);
+  public LocalTimerServiceHome getTimerServiceHome() {
+    if (timerServiceHome == null) {
+      try {
+        timerServiceHome = (LocalTimerServiceHome) new InitialContext().lookup(timerServiceHomeJndiName);
+      } catch (NamingException e) {
+        throw new JbpmException("ejb timer service lookup problem", e);
+      }
     }
+    return timerServiceHome;
   }
 
   public Service openService() {
-    return new EjbSchedulerService(timerServiceHome);
+    return new EjbSchedulerService(getTimerServiceHome());
   }
 
   public void close() {

Modified: jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java
===================================================================
--- jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java	2008-08-21 23:16:05 UTC (rev 1967)
+++ jbpm3/branches/jpdl-3.2.3.CP/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java	2008-08-21 23:22:35 UTC (rev 1968)
@@ -1,11 +1,8 @@
 package org.jbpm.scheduler.ejbtimer;
 
-import javax.naming.Context;
 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;
@@ -34,24 +31,23 @@
 
   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() {
-    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);
+  public LocalTimerEntityHome getTimerEntityHome() {
+    if (timerEntityHome == null) {
+      try {
+        timerEntityHome = (LocalTimerEntityHome) new InitialContext().lookup(timerEntityHomeJndiName);
+      } catch (NamingException e) {
+        throw new JbpmException("ejb timer entity lookup problem", e);
+      }
     }
+    return timerEntityHome;
   }
 
   public Service openService() {
-    return new EntitySchedulerService(timerEntityHome);
+    return new EntitySchedulerService(getTimerEntityHome());
   }
 
   public void close() {




More information about the jbpm-commits mailing list