[1/2] activemq-artemis git commit: ARTEMIS-1163 Refactory to polimorphic connectionfactory creation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[1/2] activemq-artemis git commit: ARTEMIS-1163 Refactory to polimorphic connectionfactory creation

clebertsuconic-2
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 1463a5116 -> 17e3f6fb3


ARTEMIS-1163 Refactory  to polimorphic  connectionfactory creation

Move logic to create a connectionfactory from the ActiveMQJMSClient class
to the JMSFactoryType enum to eliminate conditional logic in favor of polymorphism.


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/7b5f141a
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/7b5f141a
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/7b5f141a

Branch: refs/heads/master
Commit: 7b5f141a4c98f6c851818a74e7424d5113e3a1fb
Parents: 1463a51
Author: klausboeing <[hidden email]>
Authored: Sat May 13 13:12:07 2017 -0300
Committer: Clebert Suconic <[hidden email]>
Committed: Tue May 16 14:13:05 2017 -0400

----------------------------------------------------------------------
 .../artemis/api/jms/ActiveMQJMSClient.java      |  74 +------
 .../artemis/api/jms/JMSFactoryType.java         | 195 ++++++++++++++++++-
 2 files changed, 198 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7b5f141a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/ActiveMQJMSClient.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/ActiveMQJMSClient.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/ActiveMQJMSClient.java
index 6c146f0..9cf0c4d 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/ActiveMQJMSClient.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/ActiveMQJMSClient.java
@@ -23,12 +23,6 @@ import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
 import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
 import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
-import org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory;
-import org.apache.activemq.artemis.jms.client.ActiveMQQueueConnectionFactory;
-import org.apache.activemq.artemis.jms.client.ActiveMQTopicConnectionFactory;
-import org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory;
-import org.apache.activemq.artemis.jms.client.ActiveMQXAQueueConnectionFactory;
-import org.apache.activemq.artemis.jms.client.ActiveMQXATopicConnectionFactory;
 import org.apache.activemq.artemis.uri.ConnectionFactoryParser;
 
 /**
@@ -64,22 +58,7 @@ public class ActiveMQJMSClient {
     */
    public static ActiveMQConnectionFactory createConnectionFactoryWithHA(final DiscoveryGroupConfiguration groupConfiguration,
                                                                          JMSFactoryType jmsFactoryType) {
-      ActiveMQConnectionFactory factory = null;
-      if (jmsFactoryType.equals(JMSFactoryType.CF)) {
-         factory = new ActiveMQJMSConnectionFactory(true, groupConfiguration);
-      } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_CF)) {
-         factory = new ActiveMQQueueConnectionFactory(true, groupConfiguration);
-      } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_CF)) {
-         factory = new ActiveMQTopicConnectionFactory(true, groupConfiguration);
-      } else if (jmsFactoryType.equals(JMSFactoryType.XA_CF)) {
-         factory = new ActiveMQXAConnectionFactory(true, groupConfiguration);
-      } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_XA_CF)) {
-         factory = new ActiveMQXAQueueConnectionFactory(true, groupConfiguration);
-      } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_XA_CF)) {
-         factory = new ActiveMQXATopicConnectionFactory(true, groupConfiguration);
-      }
-
-      return factory;
+      return jmsFactoryType.createConnectionFactoryWithHA(groupConfiguration);
    }
 
    /**
@@ -93,22 +72,7 @@ public class ActiveMQJMSClient {
     */
    public static ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final DiscoveryGroupConfiguration groupConfiguration,
                                                                             JMSFactoryType jmsFactoryType) {
-      ActiveMQConnectionFactory factory = null;
-      if (jmsFactoryType.equals(JMSFactoryType.CF)) {
-         factory = new ActiveMQJMSConnectionFactory(false, groupConfiguration);
-      } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_CF)) {
-         factory = new ActiveMQQueueConnectionFactory(false, groupConfiguration);
-      } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_CF)) {
-         factory = new ActiveMQTopicConnectionFactory(false, groupConfiguration);
-      } else if (jmsFactoryType.equals(JMSFactoryType.XA_CF)) {
-         factory = new ActiveMQXAConnectionFactory(false, groupConfiguration);
-      } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_XA_CF)) {
-         factory = new ActiveMQXAQueueConnectionFactory(false, groupConfiguration);
-      } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_XA_CF)) {
-         factory = new ActiveMQXATopicConnectionFactory(false, groupConfiguration);
-      }
-
-      return factory;
+      return jmsFactoryType.createConnectionFactoryWithoutHA(groupConfiguration);
    }
 
    /**
@@ -129,22 +93,7 @@ public class ActiveMQJMSClient {
     */
    public static ActiveMQConnectionFactory createConnectionFactoryWithHA(JMSFactoryType jmsFactoryType,
                                                                          final TransportConfiguration... initialServers) {
-      ActiveMQConnectionFactory factory = null;
-      if (jmsFactoryType.equals(JMSFactoryType.CF)) {
-         factory = new ActiveMQJMSConnectionFactory(true, initialServers);
-      } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_CF)) {
-         factory = new ActiveMQQueueConnectionFactory(true, initialServers);
-      } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_CF)) {
-         factory = new ActiveMQTopicConnectionFactory(true, initialServers);
-      } else if (jmsFactoryType.equals(JMSFactoryType.XA_CF)) {
-         factory = new ActiveMQXAConnectionFactory(true, initialServers);
-      } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_XA_CF)) {
-         factory = new ActiveMQXAQueueConnectionFactory(true, initialServers);
-      } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_XA_CF)) {
-         factory = new ActiveMQXATopicConnectionFactory(true, initialServers);
-      }
-
-      return factory;
+      return jmsFactoryType.createConnectionFactoryWithHA(initialServers);
    }
 
    /**
@@ -160,22 +109,7 @@ public class ActiveMQJMSClient {
     */
    public static ActiveMQConnectionFactory createConnectionFactoryWithoutHA(JMSFactoryType jmsFactoryType,
                                                                             final TransportConfiguration... transportConfigurations) {
-      ActiveMQConnectionFactory factory = null;
-      if (jmsFactoryType.equals(JMSFactoryType.CF)) {
-         factory = new ActiveMQJMSConnectionFactory(false, transportConfigurations);
-      } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_CF)) {
-         factory = new ActiveMQQueueConnectionFactory(false, transportConfigurations);
-      } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_CF)) {
-         factory = new ActiveMQTopicConnectionFactory(false, transportConfigurations);
-      } else if (jmsFactoryType.equals(JMSFactoryType.XA_CF)) {
-         factory = new ActiveMQXAConnectionFactory(false, transportConfigurations);
-      } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_XA_CF)) {
-         factory = new ActiveMQXAQueueConnectionFactory(false, transportConfigurations);
-      } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_XA_CF)) {
-         factory = new ActiveMQXATopicConnectionFactory(false, transportConfigurations);
-      }
-
-      return factory;
+      return jmsFactoryType.createConnectionFactoryWithoutHA(transportConfigurations);
    }
 
    /**

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7b5f141a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/JMSFactoryType.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/JMSFactoryType.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/JMSFactoryType.java
index 67d3f57..b2e83f4 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/JMSFactoryType.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/JMSFactoryType.java
@@ -16,9 +16,144 @@
  */
 package org.apache.activemq.artemis.api.jms;
 
+import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
+import org.apache.activemq.artemis.api.core.TransportConfiguration;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory;
+import org.apache.activemq.artemis.jms.client.ActiveMQQueueConnectionFactory;
+import org.apache.activemq.artemis.jms.client.ActiveMQTopicConnectionFactory;
+import org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory;
+import org.apache.activemq.artemis.jms.client.ActiveMQXATopicConnectionFactory;
+import org.apache.activemq.artemis.jms.client.ActiveMQXAQueueConnectionFactory;
+
 // XXX no javadocs
 public enum JMSFactoryType {
-   CF, QUEUE_CF, TOPIC_CF, XA_CF, QUEUE_XA_CF, TOPIC_XA_CF;
+   CF {
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQJMSConnectionFactory(true, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQJMSConnectionFactory(false, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final TransportConfiguration... initialServers) {
+         return new ActiveMQJMSConnectionFactory(true, initialServers);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final TransportConfiguration... transportConfigurations) {
+         return new ActiveMQJMSConnectionFactory(false, transportConfigurations);
+      }
+   },
+   QUEUE_CF {
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQQueueConnectionFactory(true, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQQueueConnectionFactory(false, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final TransportConfiguration... initialServers) {
+         return new ActiveMQQueueConnectionFactory(true, initialServers);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final TransportConfiguration... transportConfigurations) {
+         return new ActiveMQQueueConnectionFactory(false, transportConfigurations);
+      }
+   },
+   TOPIC_CF {
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQTopicConnectionFactory(true, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQTopicConnectionFactory(false, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final TransportConfiguration... initialServers) {
+         return new ActiveMQTopicConnectionFactory(true, initialServers);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final TransportConfiguration... transportConfigurations) {
+         return new ActiveMQTopicConnectionFactory(false, transportConfigurations);
+      }
+   },
+   XA_CF {
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQXAConnectionFactory(true, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQXAConnectionFactory(false, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final TransportConfiguration... initialServers) {
+         return new ActiveMQXAConnectionFactory(true, initialServers);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final TransportConfiguration... transportConfigurations) {
+         return new ActiveMQXAConnectionFactory(false, transportConfigurations);
+      }
+   },
+   QUEUE_XA_CF {
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQXAQueueConnectionFactory(true, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQXAQueueConnectionFactory(false, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final TransportConfiguration... initialServers) {
+         return new ActiveMQXAQueueConnectionFactory(true, initialServers);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final TransportConfiguration... transportConfigurations) {
+         return new ActiveMQXAQueueConnectionFactory(false, transportConfigurations);
+      }
+   },
+   TOPIC_XA_CF {
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQXATopicConnectionFactory(true, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final DiscoveryGroupConfiguration groupConfiguration) {
+         return new ActiveMQXATopicConnectionFactory(false, groupConfiguration);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithHA(final TransportConfiguration... initialServers) {
+         return new ActiveMQXATopicConnectionFactory(true, initialServers);
+      }
+
+      @Override
+      public ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final TransportConfiguration... transportConfigurations) {
+         return new ActiveMQXATopicConnectionFactory(false, transportConfigurations);
+      }
+   };
 
    public int intValue() {
       int val = 0;
@@ -72,4 +207,62 @@ public enum JMSFactoryType {
       }
       return type;
    }
+
+   /**
+    * Creates an ActiveMQConnectionFactory that receives cluster topology updates from the cluster as
+    * servers leave or join and new backups are appointed or removed.
+    * <p>
+    * The discoveryAddress and discoveryPort parameters in this method are used to listen for UDP
+    * broadcasts which contain connection information for members of the cluster. The broadcasted
+    * connection information is simply used to make an initial connection to the cluster, once that
+    * connection is made, up to date cluster topology information is downloaded and automatically
+    * updated whenever the cluster topology changes. If the topology includes backup servers that
+    * information is also propagated to the client so that it can know which server to failover onto
+    * in case of live server failure.
+    *
+    * @param groupConfiguration
+    * @return the ActiveMQConnectionFactory
+    */
+   public abstract ActiveMQConnectionFactory createConnectionFactoryWithHA(final DiscoveryGroupConfiguration groupConfiguration);
+
+   /**
+    * Create an ActiveMQConnectionFactory which creates session factories from a set of live servers, no HA backup information is propagated to the client
+    * <p>
+    * The UDP address and port are used to listen for live servers in the cluster
+    *
+    * @param groupConfiguration
+    * @return the ActiveMQConnectionFactory
+    */
+   public abstract ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final DiscoveryGroupConfiguration groupConfiguration);
+
+   /**
+    * Create an ActiveMQConnectionFactory which will receive cluster topology updates from the cluster
+    * as servers leave or join and new backups are appointed or removed.
+    * <p>
+    * The initial list of servers supplied in this method is simply to make an initial connection to
+    * the cluster, once that connection is made, up to date cluster topology information is
+    * downloaded and automatically updated whenever the cluster topology changes. If the topology
+    * includes backup servers that information is also propagated to the client so that it can know
+    * which server to failover onto in case of live server failure.
+    *
+    * @param initialServers The initial set of servers used to make a connection to the cluster.
+    *                       Each one is tried in turn until a successful connection is made. Once a connection
+    *                       is made, the cluster topology is downloaded and the rest of the list is ignored.
+    * @return the ActiveMQConnectionFactory
+    */
+   public abstract ActiveMQConnectionFactory createConnectionFactoryWithHA(final TransportConfiguration... initialServers);
+
+   /**
+    * Create an ActiveMQConnectionFactory which creates session factories using a static list of
+    * transportConfigurations.
+    * <p>
+    * The ActiveMQConnectionFactory is not updated automatically as the cluster topology changes, and
+    * no HA backup information is propagated to the client
+    *
+    * @param transportConfigurations
+    * @return the ActiveMQConnectionFactory
+    */
+   public abstract ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final TransportConfiguration... transportConfigurations);
+
+
 }

Reply | Threaded
Open this post in threaded view
|

[2/2] activemq-artemis git commit: This closes #1269

clebertsuconic-2
This closes #1269


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/17e3f6fb
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/17e3f6fb
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/17e3f6fb

Branch: refs/heads/master
Commit: 17e3f6fb3794270a05fed292f33498f5cd3e64a8
Parents: 1463a51 7b5f141
Author: Clebert Suconic <[hidden email]>
Authored: Tue May 16 14:16:25 2017 -0400
Committer: Clebert Suconic <[hidden email]>
Committed: Tue May 16 14:16:25 2017 -0400

----------------------------------------------------------------------
 .../artemis/api/jms/ActiveMQJMSClient.java      |  74 +------
 .../artemis/api/jms/JMSFactoryType.java         | 195 ++++++++++++++++++-
 2 files changed, 198 insertions(+), 71 deletions(-)
----------------------------------------------------------------------