You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2015/01/20 22:24:33 UTC

[2/2] qpid-jms git commit: Configure the transport type in the factory definition file.

Configure the transport type in the factory definition file.

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

Branch: refs/heads/master
Commit: 3fc5f20abaf46e4c11eaf63622b71ff9a48d0dfe
Parents: 698a2ea
Author: Timothy Bish <ta...@gmail.com>
Authored: Tue Jan 20 16:24:24 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Tue Jan 20 16:24:24 2015 -0500

----------------------------------------------------------------------
 .../qpid/jms/provider/amqp/AmqpProvider.java    | 23 ++++--------
 .../jms/provider/amqp/AmqpProviderFactory.java  | 23 +++++++++++-
 .../provider/amqp/AmqpSslProviderFactory.java   | 37 --------------------
 .../org/apache/qpid/jms/util/FactoryFinder.java | 32 ++++++++++++++---
 .../services/org/apache/qpid/jms/provider/amqp  |  1 +
 .../org/apache/qpid/jms/provider/amqp+nio       |  1 +
 .../org/apache/qpid/jms/provider/amqp+nio+ssl   |  3 +-
 .../org/apache/qpid/jms/provider/amqp+ssl       |  3 +-
 .../services/org/apache/qpid/jms/provider/amqps |  3 +-
 9 files changed, 63 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3fc5f20a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProvider.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProvider.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProvider.java
index dea1750..2ac41d6 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProvider.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProvider.java
@@ -91,13 +91,12 @@ public class AmqpProvider implements Provider, TransportListener {
     // NOTE: Limit default channel max to signed short range to deal with
     //       brokers that don't currently handle the unsigned range well.
     private static final int DEFAULT_CHANNEL_MAX = 32767;
-    private static final String DEFAULT_TRANSPORT_KEY = "tcp";
     private static final AtomicInteger PROVIDER_SEQUENCE = new AtomicInteger();
 
     private ProviderListener listener;
     private AmqpConnection connection;
     private org.apache.qpid.jms.transports.Transport transport;
-    private String transportKey = DEFAULT_TRANSPORT_KEY;
+    private String transportType = AmqpProviderFactory.DEFAULT_TRANSPORT_TYPE;
     private boolean traceFrames;
     private boolean traceBytes;
     private boolean presettleConsumers;
@@ -155,7 +154,7 @@ public class AmqpProvider implements Provider, TransportListener {
         checkClosed();
 
         try {
-            transport = TransportFactory.create(getTransportKey(), getRemoteURI());
+            transport = TransportFactory.create(getTransportType(), getRemoteURI());
         } catch (Exception e) {
             throw IOExceptionSupport.create(e);
         }
@@ -919,22 +918,12 @@ public class AmqpProvider implements Provider, TransportListener {
         this.channelMax = channelMax;
     }
 
-    /**
-     * @return the transportKey that will be used to create the network level connection.
-     */
-    public String getTransportKey() {
-        return transportKey;
+    String getTransportType() {
+        return transportType;
     }
 
-    /**
-     * Sets the transport key used to lookup a Transport instance when an attempt
-     * is made to connect to a remote peer.
-     *
-     * @param transportKey
-     *        the tansportKey to used when looking up a Transport to use.
-     */
-    void setTransportKey(String transportKey) {
-        this.transportKey = transportKey;
+    void setTransportType(String transportType) {
+        this.transportType = transportType;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3fc5f20a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProviderFactory.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProviderFactory.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProviderFactory.java
index 5181d71..814b6c9 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProviderFactory.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProviderFactory.java
@@ -28,6 +28,10 @@ import org.apache.qpid.jms.util.PropertyUtil;
  */
 public class AmqpProviderFactory extends ProviderFactory {
 
+    public static final String DEFAULT_TRANSPORT_TYPE = "tcp";
+
+    private String transportType = DEFAULT_TRANSPORT_TYPE;
+
     @Override
     public Provider createProvider(URI remoteURI) throws Exception {
 
@@ -36,7 +40,9 @@ public class AmqpProviderFactory extends ProviderFactory {
 
         remoteURI = PropertyUtil.replaceQuery(remoteURI, map);
 
-        Provider result = new AmqpProvider(remoteURI);
+        AmqpProvider result = new AmqpProvider(remoteURI);
+
+        result.setTransportType(getTransportType());
 
         if (!PropertyUtil.setProperties(result, providerOptions)) {
             String msg = ""
@@ -54,4 +60,19 @@ public class AmqpProviderFactory extends ProviderFactory {
     public String getName() {
         return "AMQP";
     }
+
+    /**
+     * @return the transport type used for this provider factory such as 'tcp' or 'ssl'
+     */
+    public String getTransportType() {
+        return transportType;
+    }
+
+    /**
+     * @param transport
+     *        the transport type name to use when creating a new provider.
+     */
+    public void setTransportType(String transportType) {
+        this.transportType = transportType;
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3fc5f20a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSslProviderFactory.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSslProviderFactory.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSslProviderFactory.java
deleted file mode 100644
index a19af00..0000000
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSslProviderFactory.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.qpid.jms.provider.amqp;
-
-import java.net.URI;
-
-import org.apache.qpid.jms.provider.Provider;
-
-/**
- * Extends the AmqpProviderFactory to create an SSL based Provider instance.
- */
-public class AmqpSslProviderFactory extends AmqpProviderFactory {
-
-    @Override
-    public Provider createProvider(URI remoteURI) throws Exception {
-        AmqpProvider provider = new AmqpProvider(remoteURI);
-        // TODO - Would be better if we could do away with this and define
-        //        the transport key in the properties file used to find the
-        //        AmqpProcvider instance.
-        provider.setTransportKey("ssl");
-        return provider;
-    }
-}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3fc5f20a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
index baf9c27..2678188 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
@@ -147,18 +147,38 @@ public class FactoryFinder<T extends Object> {
      */
     protected static class StandaloneObjectFactory implements ObjectFactory {
         final ConcurrentHashMap<String, Class<?>> classMap = new ConcurrentHashMap<String, Class<?>>();
+        final ConcurrentHashMap<String, Properties> propertiesMap = new ConcurrentHashMap<String, Properties>();
 
         @Override
         public Object create(final String path) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException {
             Class<?> clazz = classMap.get(path);
+            Properties properties = propertiesMap.get(path);
+
             if (clazz == null) {
-                clazz = loadClass(loadProperties(path));
-                Class<?> previous = classMap.putIfAbsent(path, clazz);
-                if (previous != null) {
-                    clazz = previous;
+                properties = loadProperties(path);
+                clazz = loadClass(properties);
+                Class<?> previousClass = classMap.putIfAbsent(path, clazz);
+                Properties previousProperties = propertiesMap.putIfAbsent(path, properties);
+                if (previousClass != null) {
+                    clazz = previousClass;
+                }
+                if (previousProperties != null) {
+                    properties = previousProperties;
                 }
             }
-            return clazz.newInstance();
+
+            Object factory = clazz.newInstance();
+
+            if (!PropertyUtil.setProperties(factory, properties)) {
+                String msg = ""
+                    + " Not all provider options could be set on the found factory."
+                    + " Check the options are spelled correctly."
+                    + " Given parameters=[" + properties + "]."
+                    + " This provider instance cannot be started.";
+                throw new IllegalArgumentException(msg);
+            }
+
+            return factory;
         }
 
         static public Class<?> loadClass(Properties properties) throws ClassNotFoundException, IOException {
@@ -166,6 +186,8 @@ public class FactoryFinder<T extends Object> {
             String className = properties.getProperty("class");
             if (className == null) {
                 throw new IOException("Expected property is missing: class");
+            } else {
+                properties.remove("class");
             }
             Class<?> clazz = null;
             ClassLoader loader = Thread.currentThread().getContextClassLoader();

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3fc5f20a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp b/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp
index fe3ecca..56741dc 100644
--- a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp
+++ b/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp
@@ -15,3 +15,4 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 class=org.apache.qpid.jms.provider.amqp.AmqpProviderFactory
+transportType=tcp
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3fc5f20a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+nio
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+nio b/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+nio
index fe3ecca..56741dc 100644
--- a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+nio
+++ b/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+nio
@@ -15,3 +15,4 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 class=org.apache.qpid.jms.provider.amqp.AmqpProviderFactory
+transportType=tcp
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3fc5f20a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+nio+ssl
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+nio+ssl b/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+nio+ssl
index 69cd431..1f9b566 100644
--- a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+nio+ssl
+++ b/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+nio+ssl
@@ -14,4 +14,5 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-class=org.apache.qpid.jms.provider.amqp.AmqpSslProviderFactory
+class=org.apache.qpid.jms.provider.amqp.AmqProviderFactory
+transportType=ssl
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3fc5f20a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+ssl
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+ssl b/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+ssl
index 69cd431..414957b 100644
--- a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+ssl
+++ b/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqp+ssl
@@ -14,4 +14,5 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-class=org.apache.qpid.jms.provider.amqp.AmqpSslProviderFactory
+class=org.apache.qpid.jms.provider.amqp.AmqpProviderFactory
+transportType=ssl
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3fc5f20a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqps
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqps b/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqps
index 69cd431..414957b 100644
--- a/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqps
+++ b/qpid-jms-client/src/main/resources/META-INF/services/org/apache/qpid/jms/provider/amqps
@@ -14,4 +14,5 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-class=org.apache.qpid.jms.provider.amqp.AmqpSslProviderFactory
+class=org.apache.qpid.jms.provider.amqp.AmqpProviderFactory
+transportType=ssl
\ No newline at end of file


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