[jboss-svn-commits] JBL Code SVN: r32885 - in labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration: msg and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri May 14 07:01:43 EDT 2010


Author: kevin.conner at jboss.com
Date: 2010-05-14 07:01:42 -0400 (Fri, 14 May 2010)
New Revision: 32885

Added:
   labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/AbstractJmsServiceFactory.java
Modified:
   labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/msg/JmsMessageServiceFactory.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/JmsSchedulerServiceFactory.java
Log:
Add support for JMSProviderAdapter: JBESB-3317

Added: labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/AbstractJmsServiceFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/AbstractJmsServiceFactory.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/AbstractJmsServiceFactory.java	2010-05-14 11:01:42 UTC (rev 32885)
@@ -0,0 +1,187 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.soa.esb.services.jbpm.integration;
+
+import javax.jms.ConnectionFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.jms.jndi.JMSProviderAdapter;
+import org.jboss.jms.jndi.JNDIProviderAdapter;
+import org.jbpm.JbpmException;
+import org.jbpm.svc.ServiceFactory;
+
+/**
+ * Abstract base JMS service factory.
+ */
+public abstract class AbstractJmsServiceFactory implements ServiceFactory
+{
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 2312177513288418710L;
+
+    /**
+     * The JNDI name of a jms provider adapter.
+     */
+    String providerAdapterJNDI;
+    /**
+     * The JNDI name for locating the JMS connection factory.
+     */
+    String connectionFactoryJndiName = "java:/JmsXA";
+    /**
+     * A flag indicating whether commit should be invoked on the JMS session.
+     */
+    boolean isCommitEnabled = false;
+    /**
+     * The JMS connection factory associated with the scheduler.
+     */
+    private ConnectionFactory connectionFactory;
+
+    /**
+     * The JMS provider adapter.
+     */
+    private JMSProviderAdapter jmsProviderAdapter ;
+
+    /**
+     * Get the commitEnabled flag.
+     * @return true if commit is to be invoked on the JMS session, false otherwise.
+     */
+    public boolean isCommitEnabled()
+    {
+      return isCommitEnabled;
+    }
+
+    /**
+     * Lookup a name within JNDI.
+     * @param name The JNDI name to locate.
+     * @return The object bound to the name.
+     * @throws NamingException For errors locating the specified object within JNDI.
+     */
+    protected Object lookup(String name) throws NamingException
+    {
+      final JMSProviderAdapter adapter = getJMSProviderAdapter() ;
+      final Context initial = adapter.getInitialContext() ;
+      try
+      {
+        return initial.lookup(name);
+      }
+      finally
+      {
+        initial.close();
+      }
+    }
+
+    /**
+     * Get the JMS provider adapter.
+     * @return The JMS provider adapter.
+     * @throws NamingException For errors locating the adapter within JNDI.
+     */
+    protected JMSProviderAdapter getJMSProviderAdapter()
+      throws NamingException
+    {
+      if (jmsProviderAdapter == null)
+      {
+        if (providerAdapterJNDI != null)
+        {
+          final String lookup ;
+          if (!providerAdapterJNDI.startsWith("java:"))
+          {
+            lookup = "java:" + providerAdapterJNDI ;
+          }
+          else
+          {
+            lookup = providerAdapterJNDI ;
+          }
+          
+          final Context initial = new InitialContext();
+          final Object adapter ;
+          try
+          {
+            adapter = initial.lookup(lookup);
+          }
+          finally
+          {
+            initial.close();
+          }
+          if ((adapter != null) && (adapter instanceof JMSProviderAdapter))
+          {
+            jmsProviderAdapter = (JMSProviderAdapter)adapter ;
+          }
+          else
+          {
+            jmsProviderAdapter = new JNDIProviderAdapter() ;
+          }
+        }
+        else
+        {
+          jmsProviderAdapter = new JNDIProviderAdapter() ;
+        }
+      }
+      return jmsProviderAdapter ;
+    }
+    
+    /**
+     * Get the JMS connection factory associated with this service factory.
+     * @return The associated JMS connection factory.
+     */
+    protected ConnectionFactory getConnectionFactory()
+    {
+      if (connectionFactory == null)
+      {
+        try
+        {
+          final JMSProviderAdapter adapter = getJMSProviderAdapter() ;
+          final String jndiName ;
+          final String adapterQueueFactory = adapter.getQueueFactoryRef() ;
+          if (adapterQueueFactory != null)
+          {
+              jndiName = adapterQueueFactory ;
+          }
+          else
+          {
+              final String adapterFactory = adapter.getFactoryRef() ;
+              if (adapterFactory != null)
+              {
+                  jndiName = adapterFactory ;
+              }
+              else
+              {
+                  jndiName = connectionFactoryJndiName ;
+              }
+          }
+          connectionFactory = (ConnectionFactory)lookup(jndiName);
+        }
+        catch (NamingException e)
+        {
+          throw new JbpmException("could not retrieve message connection factory", e);
+        }
+      }
+      return connectionFactory;
+    }
+
+    /**
+     * Close this factory.
+     */
+    public void close()
+    {
+      jmsProviderAdapter = null;
+      connectionFactory = null;
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/AbstractJmsServiceFactory.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/msg/JmsMessageServiceFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/msg/JmsMessageServiceFactory.java	2010-05-14 10:03:13 UTC (rev 32884)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/msg/JmsMessageServiceFactory.java	2010-05-14 11:01:42 UTC (rev 32885)
@@ -21,16 +21,13 @@
  */
 package org.jboss.soa.esb.services.jbpm.integration.msg;
 
-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.jboss.soa.esb.services.jbpm.integration.AbstractJmsServiceFactory;
 import org.jbpm.JbpmException;
 import org.jbpm.svc.Service;
-import org.jbpm.svc.ServiceFactory;
 
 /**
  * Based on the jBPM JmsMessageServiceFactory, this service delivers messages to the
@@ -49,20 +46,17 @@
  * <li><code>idleInterval</code></li>
  * <li><code>maxIdleInterval</code></li>
  * <li><code>maxRetryJobs</code></li>
+ * <li><code>providerAdapterJNDI</code></li>
  * </ul>
  * 
  * @author Tom Baeyens
  * @author Alejandro Guizar
  */
-public final class JmsMessageServiceFactory implements ServiceFactory
+public final class JmsMessageServiceFactory extends AbstractJmsServiceFactory
 {
   private static final long serialVersionUID = 1L;
 
   /**
-   * The JNDI name for locating the JMS connection factory.
-   */
-  String connectionFactoryJndiName = "java:/JmsXA";
-  /**
    * The JNDI name for locating the jBPM job queue destination.
    */
   String destinationJndiName = "queue/JbpmJobQueue";
@@ -75,10 +69,6 @@
    */
   String dlqJndiName = "queue/JbpmDLQ";
   /**
-   * A flag indicating whether commit should be invoked on the JMS session.
-   */
-  boolean isCommitEnabled = false;
-  /**
    * The default idle interval for the retry executor.
    */
   int idleInterval = 15000; // 15 secs
@@ -92,10 +82,6 @@
   int maxRetryJobs = 20;
 
   /**
-   * The JMS connection factory associated with the scheduler.
-   */
-  private ConnectionFactory connectionFactory;
-  /**
    * The JMS destination for the jBPM job queue.
    */
   private Destination destination;
@@ -125,26 +111,6 @@
     retryExecutorThread = new Thread(retryExecutor) ;
     retryExecutorThread.start() ;
   }
-  
-  /**
-   * Get the JMS connection factory associated with this scheduler.
-   * @return The associated JMS connection factory.
-   */
-  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;
-  }
 
   /**
    * Get the jBPM job queue destination associated with this message service.
@@ -207,41 +173,13 @@
   }
 
   /**
-   * Get the commitEnabled flag.
-   * @return true if commit is to be invoked on the JMS session, false otherwise.
-   */
-  public boolean isCommitEnabled()
-  {
-    return isCommitEnabled;
-  }
-
-  /**
-   * Lookup a name within JNDI.
-   * @param name The JNDI name to locate.
-   * @return The object bound to the name.
-   * @throws NamingException For errors locating the specified object within JNDI.
-   */
-  private static Object lookup(String name) throws NamingException
-  {
-    Context initial = new InitialContext();
-    try
-    {
-      return initial.lookup(name);
-    }
-    finally
-    {
-      initial.close();
-    }
-  }
-
-  /**
    * Create a JMS message service based on this factory.
    */
   public Service openService()
   {
     try
     {
-      return new JmsMessageService(getConnectionFactory(), getDestination(), isCommitEnabled);
+      return new JmsMessageService(getConnectionFactory(), getDestination(), isCommitEnabled());
     }
     catch (JMSException e)
     {
@@ -254,7 +192,7 @@
    */
   public void close()
   {
-    connectionFactory = null;
+    super.close() ;
     destination = null;
     commandDestination = null;
     dlqDestination = null;

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/JmsSchedulerServiceFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/JmsSchedulerServiceFactory.java	2010-05-14 10:03:13 UTC (rev 32884)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/JmsSchedulerServiceFactory.java	2010-05-14 11:01:42 UTC (rev 32885)
@@ -21,22 +21,29 @@
  */
 package org.jboss.soa.esb.services.jbpm.integration.timer;
 
-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.jboss.soa.esb.services.jbpm.integration.AbstractJmsServiceFactory;
 import org.jbpm.JbpmConfiguration;
 import org.jbpm.JbpmException;
 import org.jbpm.svc.Service;
-import org.jbpm.svc.ServiceFactory;
 
 /**
  * Implementation of a scheduler service using quartz.
+ * <h3>Configuration</h3>
+ * 
+ * The JMS message service factory exposes the following configurable fields.
+ * 
+ * <ul>
+ * <li><code>connectionFactoryJndiName</code></li>
+ * <li><code>destinationJndiName</code></li>
+ * <li><code>isCommitEnabled</code></li>
+ * <li><code>providerAdapterJNDI</code></li>
+ * </ul>
  */
-public class JmsSchedulerServiceFactory implements ServiceFactory
+public class JmsSchedulerServiceFactory extends AbstractJmsServiceFactory
 {
     /**
      * Serial Version UID for this class.
@@ -44,48 +51,15 @@
     private static final long serialVersionUID = 1642915732295620551L;
     
     /**
-     * The JNDI name for locating the JMS connection factory.
-     */
-    String connectionFactoryJndiName = "java:/JmsXA";
-    /**
      * The JNDI name for locating the jBPM timer queue destination.
      */
     String destinationJndiName = "queue/JbpmTimerQueue";
     /**
-     * A flag indicating whether commit should be invoked on the JMS session.
-     */
-    boolean isCommitEnabled = false;
-
-    /**
-     * The JMS connection factory associated with the scheduler.
-     */
-    private ConnectionFactory connectionFactory;
-    /**
      * The JMS destination for the scheduler.
      */
     private Destination destination;
 
     /**
-     * Get the JMS connection factory associated with this scheduler.
-     * @return The associated JMS connection factory.
-     */
-    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;
-    }
-
-    /**
      * Get the JMS destination associated with this scheduler.
      * @return The associated JMS destination.
      */
@@ -106,34 +80,6 @@
     }
 
     /**
-     * Get the commitEnabled flag.
-     * @return true if commit is to be invoked on the JMS session, false otherwise.
-     */
-    public boolean isCommitEnabled()
-    {
-      return isCommitEnabled;
-    }
-
-    /**
-     * Lookup a name within JNDI.
-     * @param name The JNDI name to locate.
-     * @return The object bound to the name.
-     * @throws NamingException For errors locating the specified object within JNDI.
-     */
-    private static Object lookup(String name) throws NamingException
-    {
-      Context initial = new InitialContext();
-      try
-      {
-        return initial.lookup(name);
-      }
-      finally
-      {
-        initial.close();
-      }
-    }
-
-    /**
      * Create a JMS scheduler service based on this factory.
      */
     public Service openService()
@@ -141,7 +87,7 @@
       try
       {
         return new JmsSchedulerService(JbpmConfiguration.getInstance().getCurrentJbpmContext(),
-            getConnectionFactory(), getDestination(), isCommitEnabled);
+            getConnectionFactory(), getDestination(), isCommitEnabled());
       }
       catch (JMSException e)
       {
@@ -154,7 +100,7 @@
      */
     public void close()
     {
-      connectionFactory = null;
+      super.close() ;
       destination = null;
     }
 }



More information about the jboss-svn-commits mailing list