qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject [09/13] qpid-jms git commit: make the defaulting mechanism more general, applicable to any property
Date Fri, 30 Jan 2015 17:15:30 GMT
make the defaulting mechanism more general, applicable to any property


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/2459143f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/2459143f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/2459143f

Branch: refs/heads/master
Commit: 2459143f4c60da2389ae33437f155c410b0c5e84
Parents: 883f979
Author: Robert Gemmell <robbie@apache.org>
Authored: Fri Jan 30 13:00:23 2015 +0000
Committer: Robert Gemmell <robbie@apache.org>
Committed: Fri Jan 30 13:00:23 2015 +0000

----------------------------------------------------------------------
 .../qpid/jms/jndi/JmsInitialContextFactory.java | 43 +++++++++++++-------
 .../jms/jndi/JmsInitialContextFactoryTest.java  |  2 +-
 2 files changed, 29 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/2459143f/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
b/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
index 3620406..dbb222b 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
@@ -19,6 +19,7 @@ package org.apache.qpid.jms.jndi;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -51,12 +52,12 @@ public class JmsInitialContextFactory implements InitialContextFactory
{
     static final String[] DEFAULT_CONNECTION_FACTORY_NAMES = {
         "ConnectionFactory", "QueueConnectionFactory", "TopicConnectionFactory" };
 
-    static final String DEFAULT_REMOTE_URI_PROP = "defaultRemoteURI";
     static final String DEFAULT_REMOTE_URI = "amqp://localhost:5672";
 
     static final String CONNECTION_FACTORY_KEY_PREFIX = "connectionfactory.";
     static final String QUEUE_KEY_PREFIX = "queue.";
     static final String TOPIC_KEY_PREFIX = "topic.";
+    static final String CONNECTION_FACTORY_DEFAULT_KEY_PREFIX = "default." + CONNECTION_FACTORY_KEY_PREFIX;
 
     @SuppressWarnings("unchecked")
     @Override
@@ -65,13 +66,8 @@ public class JmsInitialContextFactory implements InitialContextFactory
{
         Hashtable<Object, Object> environmentCopy = new Hashtable<Object, Object>();
         environmentCopy.putAll(environment);
 
-        String defaultRemoteURI = DEFAULT_REMOTE_URI;
-        if (environment.containsKey(DEFAULT_REMOTE_URI_PROP)) {
-            defaultRemoteURI = String.valueOf(environment.get(DEFAULT_REMOTE_URI_PROP));
-        }
-
         Map<String, Object> bindings = new ConcurrentHashMap<String, Object>();
-        createConnectionFactories(environmentCopy, defaultRemoteURI, bindings);
+        createConnectionFactories(environmentCopy, bindings);
         createQueues(environmentCopy, bindings);
         createTopics(environmentCopy, bindings);
 
@@ -99,13 +95,14 @@ public class JmsInitialContextFactory implements InitialContextFactory
{
         return createContext(environmentCopy, bindings);
     }
 
-    private void createConnectionFactories(Hashtable<Object, Object> environment, String
defaultRemoteURI, Map<String, Object> bindings) throws NamingException {
+    private void createConnectionFactories(Hashtable<Object, Object> environment, Map<String,
Object> bindings) throws NamingException {
         List<String> names = getConnectionFactoryNames(environment);
+        Map<String, String> defaults = getConnectionFactoryDefaults(environment);
         for (String name : names) {
             JmsConnectionFactory factory = null;
 
             try {
-                factory = createConnectionFactory(name, defaultRemoteURI, environment);
+                factory = createConnectionFactory(name, defaults, environment);
             } catch (Exception e) {
                 throw new NamingException("Invalid ConnectionFactory definition");
             }
@@ -121,22 +118,22 @@ public class JmsInitialContextFactory implements InitialContextFactory
{
         return new ReadOnlyContext(environment, bindings);
     }
 
-    protected JmsConnectionFactory createConnectionFactory(String name, String defaultRemoteURI,
Hashtable<Object, Object> environment) throws URISyntaxException {
+    protected JmsConnectionFactory createConnectionFactory(String name, Map<String, String>
defaults, Hashtable<Object, Object> environment) throws URISyntaxException {
         String cfNameKey = CONNECTION_FACTORY_KEY_PREFIX + name;
         Map<String, String> props = new LinkedHashMap<String, String>();
 
-        // Use the default URI if none is defined for this factory in the environment
-        String uri = defaultRemoteURI;
+        // Add the defaults which apply to all connection factories
+        props.putAll(defaults);
+
+        // Add any URI entry for this specific factory name
         Object o = environment.get(cfNameKey);
         if (o != null) {
             String value = String.valueOf(o);
             if (value.trim().length() != 0) {
-                uri = value;
+                props.put(JmsConnectionFactory.REMOTE_URI_PROP, value);
             }
         }
 
-        props.put(JmsConnectionFactory.REMOTE_URI_PROP, uri);
-
         //TODO: support gathering up any other per-factory properties from the environment
 
         return createConnectionFactory(props);
@@ -161,6 +158,22 @@ public class JmsInitialContextFactory implements InitialContextFactory
{
         return list;
     }
 
+    protected Map<String, String> getConnectionFactoryDefaults(Map<Object, Object>
environment) {
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put(JmsConnectionFactory.REMOTE_URI_PROP, DEFAULT_REMOTE_URI);
+
+        for (Iterator<Entry<Object, Object>> iter = environment.entrySet().iterator();
iter.hasNext();) {
+            Map.Entry<Object, Object> entry = iter.next();
+            String key = String.valueOf(entry.getKey());
+            if (key.startsWith(CONNECTION_FACTORY_DEFAULT_KEY_PREFIX)) {
+                String jndiName = key.substring(CONNECTION_FACTORY_DEFAULT_KEY_PREFIX.length());
+                map.put(jndiName, String.valueOf(entry.getValue()));
+            }
+        }
+
+        return Collections.unmodifiableMap(map);
+    }
+
     protected void createQueues(Hashtable<Object, Object> environment, Map<String,
Object> bindings) {
         for (Iterator<Entry<Object, Object>> iter = environment.entrySet().iterator();
iter.hasNext();) {
             Map.Entry<Object, Object> entry = iter.next();

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/2459143f/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
index 6c3a5ae..b2132c5 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
@@ -63,7 +63,7 @@ public class JmsInitialContextFactoryTest extends QpidJmsTestCase {
         String updatedDefaultURI = "amqp://example.com:1234";
 
         Hashtable<Object, Object> env = new Hashtable<Object, Object>();
-        env.put(JmsInitialContextFactory.DEFAULT_REMOTE_URI_PROP, updatedDefaultURI);
+        env.put(JmsInitialContextFactory.CONNECTION_FACTORY_DEFAULT_KEY_PREFIX + JmsConnectionFactory.REMOTE_URI_PROP,
updatedDefaultURI);
         Context ctx = createInitialContext(env);
 
         for (String factoryName : JmsInitialContextFactory.DEFAULT_CONNECTION_FACTORY_NAMES)
{


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message