activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1463790 - in /activemq/trunk/activemq-pool/src: main/java/org/apache/activemq/pool/XaPooledConnectionFactory.java test/java/org/apache/activemq/pool/XAConnectionPoolTest.java
Date Tue, 02 Apr 2013 23:19:42 GMT
Author: gtully
Date: Tue Apr  2 23:19:42 2013
New Revision: 1463790

URL: http://svn.apache.org/r1463790
Log:
https://issues.apache.org/jira/browse/AMQ-4426 - allow objectfactory prop config via jndi,
java:/amq/pcf config properties as strings in java:/amq/conf/pfc context

Modified:
    activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/XaPooledConnectionFactory.java
    activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/XAConnectionPoolTest.java

Modified: activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/XaPooledConnectionFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/XaPooledConnectionFactory.java?rev=1463790&r1=1463789&r2=1463790&view=diff
==============================================================================
--- activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/XaPooledConnectionFactory.java
(original)
+++ activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/XaPooledConnectionFactory.java
Tue Apr  2 23:19:42 2013
@@ -23,46 +23,32 @@ import javax.jms.QueueConnection;
 import javax.jms.QueueConnectionFactory;
 import javax.jms.TopicConnection;
 import javax.jms.TopicConnectionFactory;
+import javax.naming.Binding;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.Name;
+import javax.naming.NamingEnumeration;
 import javax.naming.spi.ObjectFactory;
 import javax.transaction.TransactionManager;
 
 import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.util.IntrospectionSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A pooled connection factory that automatically enlists
  * sessions in the current active XA transaction if any.
  */
-public class XaPooledConnectionFactory extends PooledConnectionFactory implements ObjectFactory,
Serializable, QueueConnectionFactory, TopicConnectionFactory
-{
+public class XaPooledConnectionFactory extends PooledConnectionFactory implements ObjectFactory,
+        Serializable, QueueConnectionFactory, TopicConnectionFactory {
 
+    private static final transient Logger LOG = LoggerFactory.getLogger(XaPooledConnectionFactory.class);
     private TransactionManager transactionManager;
     private boolean tmFromJndi = false;
     private String tmJndiName = "java:/TransactionManager";
-
-    public String getTmJndiName() {
-        return tmJndiName;
-    }
-
-    public void setTmJndiName(String tmJndiName) {
-        this.tmJndiName = tmJndiName;
-    }
-
-    public boolean isTmFromJndi() {
-        return tmFromJndi;
-    }
-
-    /**
-     * Allow transaction manager resolution from JNDI (ee deployment)
-     * @param tmFromJndi
-     */
-    public void setTmFromJndi(boolean tmFromJndi) {
-        this.tmFromJndi = tmFromJndi;
-    }
+    private String brokerUrl = null;
 
     public XaPooledConnectionFactory() {
         super();
@@ -81,7 +67,9 @@ public class XaPooledConnectionFactory e
             try {
                 transactionManager = (TransactionManager) new InitialContext().lookup(getTmJndiName());
             } catch (Throwable ignored) {
-                ignored.printStackTrace();
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("exception on tmFromJndi: " + getTmJndiName(), ignored);
+                }
             }
         }
         return transactionManager;
@@ -99,12 +87,61 @@ public class XaPooledConnectionFactory e
     @Override
     public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,
?> environment) throws Exception {
         setTmFromJndi(true);
+        configFromJndiConf(obj);
         if (environment != null) {
             IntrospectionSupport.setProperties(this, environment);
         }
         return this;
     }
 
+    private void configFromJndiConf(Object rootContextName) {
+        if (rootContextName instanceof String) {
+            String name = (String) rootContextName;
+            name = name.substring(0, name.lastIndexOf('/')) + "/conf" + name.substring(name.lastIndexOf('/'));
+            try {
+                InitialContext ctx = new InitialContext();
+                NamingEnumeration bindings = ctx.listBindings(name);
+
+                while (bindings.hasMore()) {
+                    Binding bd = (Binding)bindings.next();
+                    IntrospectionSupport.setProperty(this, bd.getName(), bd.getObject());
+                }
+
+            } catch (Exception ignored) {
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("exception on config from jndi: " + name, ignored);
+                }
+            }
+        }
+    }
+
+    public void setBrokerUrl(String url) {
+        if (brokerUrl == null || !brokerUrl.equals(url)) {
+            brokerUrl = url;
+            setConnectionFactory(new ActiveMQConnectionFactory(brokerUrl));
+        }
+    }
+
+    public String getTmJndiName() {
+        return tmJndiName;
+    }
+
+    public void setTmJndiName(String tmJndiName) {
+        this.tmJndiName = tmJndiName;
+    }
+
+    public boolean isTmFromJndi() {
+        return tmFromJndi;
+    }
+
+    /**
+     * Allow transaction manager resolution from JNDI (ee deployment)
+     * @param tmFromJndi
+     */
+    public void setTmFromJndi(boolean tmFromJndi) {
+        this.tmFromJndi = tmFromJndi;
+    }
+
     @Override
     public QueueConnection createQueueConnection() throws JMSException {
         return (QueueConnection) createConnection();

Modified: activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/XAConnectionPoolTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/XAConnectionPoolTest.java?rev=1463790&r1=1463789&r2=1463790&view=diff
==============================================================================
--- activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/XAConnectionPoolTest.java
(original)
+++ activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/XAConnectionPoolTest.java
Tue Apr  2 23:19:42 2013
@@ -40,6 +40,7 @@ import javax.transaction.SystemException
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 import javax.transaction.xa.XAResource;
+import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.ActiveMQXAConnectionFactory;
 import org.apache.activemq.ActiveMQXASession;
 import org.apache.activemq.command.ActiveMQTopic;
@@ -157,14 +158,14 @@ public class XAConnectionPoolTest extend
 
     public void testBindable() throws Exception {
         XaPooledConnectionFactory pcf = new XaPooledConnectionFactory();
-        assertTrue(pcf  instanceof ObjectFactory);
+        assertTrue(pcf instanceof ObjectFactory);
         assertTrue(((ObjectFactory)pcf).getObjectInstance(null, null, null, null) instanceof
XaPooledConnectionFactory);
         assertTrue(pcf.isTmFromJndi());
     }
 
     public void testBindableEnvOverrides() throws Exception {
         XaPooledConnectionFactory pcf = new XaPooledConnectionFactory();
-        assertTrue(pcf  instanceof ObjectFactory);
+        assertTrue(pcf instanceof ObjectFactory);
         Hashtable<String, String> environment = new Hashtable<String, String>();
         environment.put("tmFromJndi", String.valueOf(Boolean.FALSE));
         assertTrue(((ObjectFactory) pcf).getObjectInstance(null, null, null, environment)
instanceof XaPooledConnectionFactory);
@@ -173,7 +174,7 @@ public class XAConnectionPoolTest extend
 
     public void testSenderAndPublisherDest() throws Exception {
         XaPooledConnectionFactory pcf = new XaPooledConnectionFactory();
-        pcf.setConnectionFactory(new ActiveMQXAConnectionFactory("vm://test?broker.persistent=false"));
+        pcf.setConnectionFactory(new ActiveMQConnectionFactory("vm://test?broker.persistent=false"));
 
         QueueConnection connection = pcf.createQueueConnection();
         QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);



Mime
View raw message