[jbpm-commits] JBoss JBPM SVN: r6301 - in jbpm3/branches/jbpm-3.2-soa/modules: core/src/main/java/org/jbpm/jcr/jndi and 7 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed May 5 19:19:53 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-05-05 19:19:51 -0400 (Wed, 05 May 2010)
New Revision: 6301

Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/JbpmSessionFactory.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jcr/jndi/JndiJcrServiceFactory.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/JndiUtil.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mock/Jndi.java
   jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java
   jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java
   jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/JobListenerBean.java
   jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/TimerEntityBean.java
   jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java
   jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java
   jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java
   jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/TimerServiceBean.java
Log:
prevent serializability test from failing when code source location is not a file
synchronize initialization of jndi resources in service factories

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/JbpmSessionFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/JbpmSessionFactory.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/JbpmSessionFactory.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -29,9 +29,6 @@
 import java.util.Iterator;
 import java.util.Properties;
 
-import javax.naming.InitialContext;
-import javax.rmi.PortableRemoteObject;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.HibernateException;
@@ -41,9 +38,11 @@
 import org.hibernate.mapping.PersistentClass;
 import org.hibernate.type.LongType;
 import org.hibernate.type.StringType;
+
 import org.jbpm.JbpmConfiguration;
 import org.jbpm.JbpmException;
 import org.jbpm.util.ClassLoaderUtil;
+import org.jbpm.util.JndiUtil;
 
 /**
  * creates JbpmSessions. Obtain a JbpmSessionFactory with
@@ -85,18 +84,11 @@
     if (instance == null) {
       // if there is a JNDI name configured
       if (jndiName != null) {
-        try {
-          // fetch the JbpmSessionFactory from JNDI
-          if (log.isDebugEnabled()) {
-            log.debug("fetching JbpmSessionFactory from " + jndiName);
-          }
-          InitialContext initialContext = new InitialContext();
-          Object o = initialContext.lookup(jndiName);
-          instance = (JbpmSessionFactory) PortableRemoteObject.narrow(o, JbpmSessionFactory.class);
+        // fetch the JbpmSessionFactory from JNDI
+        if (log.isDebugEnabled()) {
+          log.debug("fetching JbpmSessionFactory from " + jndiName);
         }
-        catch (Exception e) {
-          throw new JbpmException("couldn't fetch JbpmSessionFactory from  " + jndiName);
-        }
+        instance = (JbpmSessionFactory) JndiUtil.lookup(jndiName, JbpmSessionFactory.class);
       }
       // else there is no JNDI name configured
       else {

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jcr/jndi/JndiJcrServiceFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jcr/jndi/JndiJcrServiceFactory.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jcr/jndi/JndiJcrServiceFactory.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -22,29 +22,22 @@
 package org.jbpm.jcr.jndi;
 
 import javax.jcr.Repository;
-import javax.naming.InitialContext;
-import javax.rmi.PortableRemoteObject;
 
-import org.jbpm.JbpmException;
 import org.jbpm.jcr.impl.AbstractJcrServiceFactory;
+import org.jbpm.util.JndiUtil;
 
 public class JndiJcrServiceFactory extends AbstractJcrServiceFactory {
 
   private static final long serialVersionUID = 1L;
-  
-  String jndiName = null;
 
-  protected Repository getRepository() {
-    Repository jcrRepository;
-    try {
-      InitialContext initialContext = new InitialContext();
-      Object o = initialContext.lookup(jndiName);
-      jcrRepository = (Repository) PortableRemoteObject.narrow(o, Repository.class);
-    } catch (Exception e) {
-      // NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
-      throw new JbpmException("couldn't fetch JCR repository from JNDI with name '"+jndiName+"'", e);
+  String jndiName;
+  private Repository repository;
+
+  protected synchronized Repository getRepository() {
+    if (repository == null) {
+      repository = (Repository) JndiUtil.lookup(jndiName, Repository.class);
     }
-    return jcrRepository;
+    return repository;
   }
 
 }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -21,18 +21,16 @@
  */
 package org.jbpm.persistence.jta;
 
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import javax.transaction.UserTransaction;
 
-import org.jbpm.JbpmException;
 import org.jbpm.persistence.db.DbPersistenceServiceFactory;
 import org.jbpm.svc.Service;
+import org.jbpm.util.JndiUtil;
 
 /**
  * The JTA persistence service enables jBPM to participate in JTA transactions. If an existing
- * transaction is underway, {@link JtaDbPersistenceService} clings to it; otherwise it starts a new
- * transaction.
+ * transaction is underway, {@link JtaDbPersistenceService} clings to it; otherwise it starts a
+ * new transaction.
  * 
  * <h3>Configuration</h3>
  * 
@@ -63,15 +61,15 @@
     return new JtaDbPersistenceService(this);
   }
 
-  public UserTransaction getUserTransaction() {
+  public synchronized UserTransaction getUserTransaction() {
     if (userTransaction == null) {
       String jndiName = getConfiguration().getProperty("jta.UserTransaction");
       if (jndiName == null) {
         /*
-         * EJB 2.1 section 20.9 The container must make the UserTransaction interface available to
-         * the enterprise beans that are allowed to use this interface (only session and message-
-         * driven beans with bean-managed transaction demarcation are allowed to use this interface)
-         * in JNDI under the name java:comp/UserTransaction.
+         * EJB 2.1 section 20.9 The container must make the UserTransaction interface available
+         * to the enterprise beans that are allowed to use this interface (only session and
+         * message- driven beans with bean-managed transaction demarcation are allowed to use
+         * this interface) in JNDI under the name java:comp/UserTransaction.
          */
         /*
          * J2EE 1.4 section 4.2.1.1 The J2EE platform must provide an object implementing the
@@ -80,12 +78,7 @@
          */
         jndiName = "java:comp/UserTransaction";
       }
-      try {
-        userTransaction = (UserTransaction) new InitialContext().lookup(jndiName);
-      }
-      catch (NamingException e) {
-        throw new JbpmException("could not retrieve user transaction with name " + jndiName, e);
-      }
+      userTransaction = (UserTransaction) JndiUtil.lookup(jndiName, UserTransaction.class);
     }
     return userTransaction;
   }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/JndiUtil.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/JndiUtil.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/JndiUtil.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.util;
 
+import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.rmi.PortableRemoteObject;
@@ -33,12 +34,20 @@
 
   public static Object lookup(String jndiName, Class type) {
     try {
-      InitialContext initialContext = new InitialContext();
-      Object object = initialContext.lookup(jndiName);
-      return PortableRemoteObject.narrow(object, type);
+      return PortableRemoteObject.narrow(lookup(jndiName), type);
     }
     catch (NamingException e) {
       throw new JndiLookupException("could not retrieve: " + jndiName, e);
     }
   }
+
+  private static Object lookup(String jndiName) throws NamingException {
+    Context initialContext = new InitialContext();
+    try {
+      return initialContext.lookup(jndiName);
+    }
+    finally {
+      initialContext.close();
+    }
+  }
 }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -25,7 +25,9 @@
 import java.io.Serializable;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
 
 import org.jbpm.util.ClassLoaderUtil;
 
@@ -81,24 +83,25 @@
   };
 
   public void testForNonSerializableClasses() throws URISyntaxException {
-    File classDir = new File(ClassLoaderUtil.class.getProtectionDomain()
-      .getCodeSource()
-      .getLocation()
-      .getPath());
+    URL location = ClassLoaderUtil.class.getProtectionDomain().getCodeSource().getLocation();
+    File classDir = new File(new URI(location.toString()));
 
     File[] files = classDir.listFiles();
+    if (files == null) return;
+
+    // scan top level packages
     for (int i = 0; i < files.length; i++) {
       File file = files[i];
-      String fileName = file.getName();
       if (file.isDirectory()) {
-        scanForClasses(file, fileName);
+        scanForClasses(file, file.getName());
       }
-      // no classes in the anonymous package
     }
   }
 
   private static void scanForClasses(File classDir, String packageName) {
     File[] files = classDir.listFiles();
+    if (files == null) return;
+
     for (int i = 0; i < files.length; i++) {
       File file = files[i];
       String fileName = file.getName();
@@ -117,8 +120,10 @@
       Class clazz = Class.forName(className);
 
       if (!Serializable.class.isAssignableFrom(clazz)
-        && !Modifier.isAbstract(clazz.getModifiers()) && !isAnonymous(clazz)
-        && !isUtility(clazz) && !isExcused(className)) {
+        && !Modifier.isAbstract(clazz.getModifiers())
+        && !isAnonymous(clazz)
+        && !isUtility(clazz)
+        && !isExcused(className)) {
         fail(className + " is NOT Serializable");
       }
     }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mock/Jndi.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mock/Jndi.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mock/Jndi.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -27,6 +27,7 @@
 
 import javax.naming.Context;
 import javax.naming.Name;
+import javax.naming.NameAlreadyBoundException;
 import javax.naming.NameParser;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
@@ -34,7 +35,7 @@
 
 public class Jndi {
   
-  static Map repository = null;
+  static Map repository;
   
   public static void initialize() {
     System.setProperty("java.naming.factory.initial", "org.jbpm.mock.Jndi$MockInitialContextFactory");
@@ -64,17 +65,18 @@
       repository.remove(name);
     }
     public void bind(String name, Object obj) throws NamingException {
+      if (repository.containsKey(name)) {
+        throw new NameAlreadyBoundException(name);
+      }
       repository.put(name, obj);
     }
-
     public void rebind(String name, Object obj) throws NamingException {
       repository.put(name, obj);
     }
-
-    
     public void close() throws NamingException {
-      throw new UnsupportedOperationException();
+      repository.clear();
     }
+
     public String getNameInNamespace() throws NamingException {
       throw new UnsupportedOperationException();
     }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -41,6 +41,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.jbpm.command.Command;
 import org.jbpm.ejb.LocalCommandService;
 import org.jbpm.ejb.LocalCommandServiceHome;
@@ -96,14 +97,14 @@
 
   private static final long serialVersionUID = 1L;
 
-  MessageDrivenContext messageDrivenContext;
-  LocalCommandService commandService;
+  private MessageDrivenContext messageDrivenContext;
+  private LocalCommandService commandService;
 
-  Destination deadLetterQueue;
-  ConnectionFactory jmsConnectionFactory;
-  Connection jmsConnection;
+  private Destination deadLetterQueue;
+  private ConnectionFactory jmsConnectionFactory;
+  private Connection jmsConnection;
 
-  transient final Log log = LogFactory.getLog(getClass());
+  private static final Log log = LogFactory.getLog(CommandListenerBean.class);
 
   public void onMessage(Message message) {
     try {
@@ -160,27 +161,21 @@
 
   private void discard(Message message) throws JMSException {
     if (deadLetterQueue == null) {
-      // lookup dead letter queue
+      if (log.isDebugEnabled()) {
+        log.debug("dead letter queue not available, rejecting: " + message);
+      }
+      messageDrivenContext.setRollbackOnly();
+    }
+    else {
+      // send message to dead letter queue
+      Session jmsSession = createSession();
       try {
-        Context jndiContext = new InitialContext();
-        deadLetterQueue = (Destination) jndiContext.lookup("java:comp/env/jms/DeadLetterQueue");
+        jmsSession.createProducer(deadLetterQueue).send(message);
       }
-      catch (NamingException e) {
-        if (log.isDebugEnabled()) {
-          log.debug("failed to retrieve dead letter queue, rejecting: " + message);
-        }
-        messageDrivenContext.setRollbackOnly();
-        return;
+      finally {
+        jmsSession.close();
       }
     }
-    // send message to dead letter queue
-    Session jmsSession = createSession();
-    try {
-      jmsSession.createProducer(deadLetterQueue).send(message);
-    }
-    finally {
-      jmsSession.close();
-    }
   }
 
   private void sendResult(Serializable result, Destination destination, String correlationId)
@@ -233,11 +228,18 @@
   public void ejbCreate() {
     try {
       Context jndiContext = new InitialContext();
+      jmsConnectionFactory = (ConnectionFactory) jndiContext.lookup("java:comp/env/jms/JbpmConnectionFactory");
 
       LocalCommandServiceHome commandServiceHome = (LocalCommandServiceHome) jndiContext.lookup("java:comp/env/ejb/LocalCommandServiceBean");
       commandService = commandServiceHome.create();
 
-      jmsConnectionFactory = (ConnectionFactory) jndiContext.lookup("java:comp/env/jms/JbpmConnectionFactory");
+      try {
+        deadLetterQueue = (Destination) jndiContext.lookup("java:comp/env/jms/DeadLetterQueue");
+      }
+      catch (NamingException e) {
+        // dead letter queue will not be available
+      }
+      jndiContext.close();
     }
     catch (NamingException e) {
       throw new EJBException("error retrieving command service home", e);

Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -112,15 +112,17 @@
    * default jbpm configuration file will be used (jbpm.cfg.xml).
    */
   public void ejbCreate() throws CreateException {
-    String jbpmCfgResource = null;
+    String jbpmCfgResource;
     try {
-      Context initial = new InitialContext();
-      jbpmCfgResource = (String) initial.lookup("java:comp/env/JbpmCfgResource");
+      Context jndiContext = new InitialContext();
+      jbpmCfgResource = (String) jndiContext.lookup("java:comp/env/JbpmCfgResource");
     }
     catch (NamingException e) {
       if (log.isDebugEnabled()) {
-        log.debug("could not fetch configuration resource from jndi: " + e.getMessage());
+        log.debug("could not fetch configuration resource: " + e.getMessage());
       }
+      // use default configuration resource
+      jbpmCfgResource = null;
     }
 
     jbpmConfiguration = JbpmConfiguration.getInstance(jbpmCfgResource);

Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/JobListenerBean.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/JobListenerBean.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/JobListenerBean.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -3,21 +3,23 @@
 import javax.jms.JMSException;
 import javax.jms.Message;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import org.jbpm.command.Command;
 
 /**
- * Message-driven bean that listens for {@link Message messages} containing a
- * reference to a pending {@linkplain Job job}. to support asynchronous
- * continuations.
+ * Message-driven bean that listens for {@link Message messages} containing a reference to a
+ * pending {@linkplain Job job}. to support asynchronous continuations.
  * 
- * The message must have a property called <code>jobId</code> of type
- * <code>long</code> which references a pending <literal>Job</literal> in the
- * database. The message body, if any, is ignored.
+ * The message must have a property called <code>jobId</code> of type <code>long</code> which
+ * references a pending <literal>Job</literal> in the database. The message body, if any, is
+ * ignored.
  * 
  * <h3>Environment</h3>
  * 
- * This bean extends the {@link CommandListenerBean} and inherits its
- * environment entries and resources available for customization.
+ * This bean extends the {@link CommandListenerBean} and inherits its environment entries and
+ * resources available for customization.
  * 
  * @author Tom Baeyens
  * @author Alejandro Guizar
@@ -25,6 +27,7 @@
 public class JobListenerBean extends CommandListenerBean {
 
   private static final long serialVersionUID = 1L;
+  private static final Log log = LogFactory.getLog(JobListenerBean.class);
 
   protected Command extractCommand(Message message) throws JMSException {
     // checking for jobId property

Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/TimerEntityBean.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/TimerEntityBean.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/TimerEntityBean.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -9,12 +9,10 @@
 import javax.ejb.EntityContext;
 import javax.ejb.TimedObject;
 import javax.ejb.TimerService;
-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.ejb.LocalCommandService;
 import org.jbpm.ejb.LocalCommandServiceHome;
 import org.jbpm.graph.exe.ProcessInstance;
@@ -22,6 +20,7 @@
 import org.jbpm.job.Timer;
 import org.jbpm.scheduler.ejbtimer.ExecuteTimerCommand;
 import org.jbpm.scheduler.ejbtimer.TimerInfo;
+import org.jbpm.util.JndiUtil;
 
 /**
  * Entity bean that interacts with the EJB timer service to schedule jBPM {@linkplain Timer
@@ -81,14 +80,10 @@
 
   public void ejbActivate() {
     try {
-      Context initial = new InitialContext();
-      LocalCommandServiceHome commandServiceHome =
-        (LocalCommandServiceHome) initial.lookup("java:comp/env/ejb/LocalCommandServiceBean");
+      LocalCommandServiceHome commandServiceHome = (LocalCommandServiceHome) JndiUtil
+        .lookup("java:comp/env/ejb/LocalCommandServiceBean", LocalCommandServiceHome.class);
       commandService = commandServiceHome.create();
     }
-    catch (NamingException e) {
-      throw new EJBException("failed to retrieve command service home", e);
-    }
     catch (CreateException e) {
       throw new EJBException("command service creation failed", e);
     }
@@ -169,7 +164,11 @@
     Collection timers = entityContext.getTimerService().getTimers();
     boolean debug = log.isDebugEnabled();
     if (debug) {
-      log.debug("retrieved " + timers.size() + " ejb timer(s) by name '" + timerName + "' for "
+      log.debug("retrieved "
+        + timers.size()
+        + " ejb timer(s) by name '"
+        + timerName
+        + "' for "
         + token);
     }
 

Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -24,18 +24,16 @@
 import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
 import javax.jms.JMSException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 
 import org.jbpm.JbpmException;
 import org.jbpm.ejb.impl.JobListenerBean;
 import org.jbpm.svc.Service;
 import org.jbpm.svc.ServiceFactory;
+import org.jbpm.util.JndiUtil;
 
 /**
- * The JMS message service leverages the reliable communication infrastructure available through JMS
- * interfaces to deliver asynchronous continuation messages to the {@link JobListenerBean}.
+ * The JMS message service leverages the reliable communication infrastructure available through
+ * JMS interfaces to deliver asynchronous continuation messages to the {@link JobListenerBean}.
  * 
  * <h3>Configuration</h3>
  * 
@@ -64,26 +62,16 @@
   private ConnectionFactory connectionFactory;
   private Destination destination;
 
-  public ConnectionFactory getConnectionFactory() {
+  public synchronized ConnectionFactory getConnectionFactory() {
     if (connectionFactory == null) {
-      try {
-        connectionFactory = (ConnectionFactory) lookup(connectionFactoryJndiName);
-      }
-      catch (NamingException e) {
-        throw new JbpmException("could not retrieve message connection factory", e);
-      }
+      connectionFactory = (ConnectionFactory) JndiUtil.lookup(connectionFactoryJndiName, ConnectionFactory.class);
     }
     return connectionFactory;
   }
 
-  public Destination getDestination() {
+  public synchronized Destination getDestination() {
     if (destination == null) {
-      try {
-        destination = (Destination) lookup(destinationJndiName);
-      }
-      catch (NamingException e) {
-        throw new JbpmException("could not retrieve job destination", e);
-      }
+      destination = (Destination) JndiUtil.lookup(destinationJndiName, Destination.class);
     }
     return destination;
   }
@@ -92,16 +80,6 @@
     return isCommitEnabled;
   }
 
-  private static Object lookup(String name) throws NamingException {
-    Context initial = new InitialContext();
-    try {
-      return initial.lookup(name);
-    }
-    finally {
-      initial.close();
-    }
-  }
-
   public Service openService() {
     try {
       return new JmsMessageService(this);

Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerServiceFactory.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -1,12 +1,9 @@
 package org.jbpm.scheduler.ejbtimer;
 
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.jbpm.JbpmException;
+import org.jbpm.ejb.LocalTimerEntityHome;
 import org.jbpm.svc.Service;
 import org.jbpm.svc.ServiceFactory;
+import org.jbpm.util.JndiUtil;
 
 /**
  * @author Tom Baeyens
@@ -20,27 +17,13 @@
 
   private LocalTimerServiceHome timerServiceHome;
 
-  public LocalTimerServiceHome getTimerServiceHome() {
+  public synchronized LocalTimerServiceHome getTimerServiceHome() {
     if (timerServiceHome == null) {
-      try {
-        timerServiceHome = (LocalTimerServiceHome) lookup(timerServiceHomeJndiName);
-      } catch (NamingException e) {
-        throw new JbpmException("ejb timer service lookup problem", e);
-      }
+      timerServiceHome = (LocalTimerServiceHome) JndiUtil.lookup(timerServiceHomeJndiName, LocalTimerEntityHome.class);
     }
     return timerServiceHome;
   }
 
-  private static Object lookup(String name) throws NamingException {
-    Context initial = new InitialContext();
-    try {
-      return initial.lookup(name);
-    }
-    finally {
-      initial.close();
-    }
-  }
-
   public Service openService() {
     return new EjbSchedulerService(getTimerServiceHome());
   }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/EntitySchedulerServiceFactory.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -9,11 +9,11 @@
 import org.jbpm.job.Timer;
 import org.jbpm.svc.Service;
 import org.jbpm.svc.ServiceFactory;
+import org.jbpm.util.JndiUtil;
 
 /**
- * The entity scheduler service builds on the transactional notification 
- * service for timed events provided by the EJB container to schedule business
- * process {@linkplain Timer timers}.
+ * The entity scheduler service builds on the transactional notification service for timed
+ * events provided by the EJB container to schedule business process {@linkplain Timer timers}.
  * 
  * <h3>Configuration</h3>
  * 
@@ -24,7 +24,7 @@
  * </ul>
  * 
  * Refer to the jBPM manual for details.
- *
+ * 
  * @author Tom Baeyens
  * @author Alejandro Guizar
  * @author Fady Matar
@@ -37,27 +37,13 @@
 
   private LocalTimerEntityHome timerEntityHome;
 
-  public LocalTimerEntityHome getTimerEntityHome() {
+  public synchronized LocalTimerEntityHome getTimerEntityHome() {
     if (timerEntityHome == null) {
-      try {
-        timerEntityHome = (LocalTimerEntityHome) lookup(timerEntityHomeJndiName);
-      } catch (NamingException e) {
-        throw new JbpmException("ejb timer entity lookup problem", e);
-      }
+      timerEntityHome = (LocalTimerEntityHome) JndiUtil.lookup(timerEntityHomeJndiName, LocalTimerEntityHome.class);
     }
     return timerEntityHome;
   }
 
-  private static Object lookup(String name) throws NamingException {
-    Context initial = new InitialContext();
-    try {
-      return initial.lookup(name);
-    }
-    finally {
-      initial.close();
-    }
-  }
-
   public Service openService() {
     return new EntitySchedulerService(getTimerEntityHome());
   }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/TimerServiceBean.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/TimerServiceBean.java	2010-05-05 09:13:37 UTC (rev 6300)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/scheduler/ejbtimer/TimerServiceBean.java	2010-05-05 23:19:51 UTC (rev 6301)
@@ -31,9 +31,6 @@
 import javax.ejb.SessionContext;
 import javax.ejb.TimedObject;
 import javax.ejb.TimerService;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -44,6 +41,7 @@
 import org.jbpm.graph.exe.ProcessInstance;
 import org.jbpm.graph.exe.Token;
 import org.jbpm.job.Timer;
+import org.jbpm.util.JndiUtil;
 
 /**
  * Session bean that interacts with the EJB timer service to schedule jBPM {@linkplain Timer
@@ -60,13 +58,10 @@
 
   public void ejbCreate() {
     try {
-      Context initial = new InitialContext();
-      LocalCommandServiceHome commandServiceHome = (LocalCommandServiceHome) initial.lookup("java:comp/env/ejb/LocalCommandServiceBean");
+      LocalCommandServiceHome commandServiceHome = (LocalCommandServiceHome) JndiUtil
+        .lookup("java:comp/env/ejb/LocalCommandServiceBean", LocalCommandServiceHome.class);
       commandService = commandServiceHome.create();
     }
-    catch (NamingException e) {
-      throw new EJBException("failed to retrieve command service home", e);
-    }
     catch (CreateException e) {
       throw new EJBException("command service creation failed", e);
     }



More information about the jbpm-commits mailing list