Author: igarashitm
Date: 2011-08-25 15:23:40 -0400 (Thu, 25 Aug 2011)
New Revision: 11225
Added:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/DiscoveryGroupConstants.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/AbstractServerLocator.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/SimpleUDPServerLocatorImpl.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/StaticServerLocatorImpl.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BroadcastGroupConstants.java
branches/HORNETQ-316/hornetq-jgroups-discovery/
branches/HORNETQ-316/hornetq-jgroups-discovery/pom.xml
branches/HORNETQ-316/hornetq-jgroups-discovery/src/
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/BroadcastGroupConstants.java
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/DiscoveryGroupConstants.java
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsBroadcastGroupImpl.java
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsDiscoveryGroupImpl.java
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsServerLocatorImpl.java
branches/HORNETQ-316/tests/config/test-jgroups-file_ping.xml
branches/HORNETQ-316/tests/config/test-jgroups-file_ping_2.xml
branches/HORNETQ-316/tests/config/test-jgroups-file_ping_3.xml
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/discovery/JGroupsDiscoveryTest.java
Removed:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorImpl.java
Modified:
branches/HORNETQ-316/build-hornetq.xml
branches/HORNETQ-316/distribution/hornetq/src/main/assembly/dep.xml
branches/HORNETQ-316/examples/jms/symmetric-cluster/src/org/hornetq/jms/example/SymmetricClusterExample.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/DiscoveryGroupConfiguration.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/client/HornetQClient.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/management/HornetQServerControl.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorInternal.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BridgeConfiguration.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BroadcastGroupConfiguration.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/ClusterConnectionConfiguration.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/deployers/impl/FileConfigurationParser.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/BridgeControlImpl.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/BroadcastGroupControlImpl.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/ClusterConnectionControlImpl.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/HornetQServerControlImpl.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/BroadcastGroup.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/BroadcastGroupImpl.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/ClusterConnectionImpl.java
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
branches/HORNETQ-316/hornetq-core/src/main/resources/schema/hornetq-configuration.xsd
branches/HORNETQ-316/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/ConnectionFactoryProperties.java
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/HornetQResourceAdapter.java
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/Util.java
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/main/java/org/hornetq/rest/MessageServiceManager.java
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/test/java/org/hornetq/rest/test/RawAckTest.java
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/test/java/org/hornetq/rest/test/RawRestartTest.java
branches/HORNETQ-316/pom.xml
branches/HORNETQ-316/tests/integration-tests/pom.xml
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionFactoryTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeReconnectTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeStartTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeWithPagingTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackAutoTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackManualTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailoverTestBase.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/MultipleLivesMultipleBackupsFailoverTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteFailoverTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteMultipleLivesMultipleBackupsFailoverTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteSingleLiveMultipleBackupsFailoverTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/SecurityFailoverTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/remote/FailoverWithSharedStoreTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/topology/HAClientTopologyWithDiscoveryTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/discovery/DiscoveryTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/HornetQConnectionFactoryTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionFactoryOnGCest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/server/JMSServerDeployerTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BridgeControlTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BridgeControlUsingCoreTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BroadcastGroupControlTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/ClusterConnectionControl2Test.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/ClusterConnectionControlTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/HornetQServerControlTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/ra/ResourceAdapterTest.java
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSClusteredTestBase.java
branches/HORNETQ-316/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/config/impl/FileConfigurationTest.java
branches/HORNETQ-316/tests/unit-tests/src/test/resources/ConfigurationTest-full-config.xml
Log:
HORNETQ-316: initial commit for support jgroups cluster discovery
Modified: branches/HORNETQ-316/build-hornetq.xml
===================================================================
--- branches/HORNETQ-316/build-hornetq.xml 2011-08-25 05:25:43 UTC (rev 11224)
+++ branches/HORNETQ-316/build-hornetq.xml 2011-08-25 19:23:40 UTC (rev 11225)
@@ -71,6 +71,8 @@
<property name="spring.integration.sources.jar.name"
value="hornetq-spring-integration-sources.jar"/>
<property name="twitter.integration.jar.name"
value="hornetq-twitter-integration.jar"/>
<property name="twitter.integration.sources.jar.name"
value="hornetq-twitter-integration-sources.jar"/>
+ <property name="jgroups.discovery.jar.name"
value="hornetq-jgroups-discovery.jar"/>
+ <property name="jgroups.discovery.sources.jar.name"
value="hornetq-jgroups-discovery.jar"/>
<property name="bootstrap.jar.name"
value="hornetq-bootstrap.jar"/>
<property name="bootstrap.sources.jar.name"
value="hornetq-bootstrap-sources.jar"/>
<property name="logging.jar.name"
value="hornetq-logging.jar"/>
@@ -89,6 +91,7 @@
<property name="resources.jar.name"
value="hornetq-resources.jar"/>
<property name="resources.sources.jar.name"
value="hornetq-resources-sources.jar"/>
<property name="twitter4j.jar.name"
value="twitter4j-core.jar"/>
+ <property name="jgroups.jar.name" value="jgroups.jar"/>
<property name="eap.examples.zip.name"
value="hornetq-eap-examples.zip"/>
<!--source and build dirs-->
@@ -102,6 +105,7 @@
<property name="hornetq.integration.as.module.jar"
value="hornetq-jboss-as-integration"/>
<property name="hornetq.bootstrap.module.jar"
value="hornetq-bootstrap"/>
<property name="hornetq.twitter.module.jar"
value="hornetq-twitter-integration"/>
+ <property name="hornetq.jgroups.module.jar"
value="hornetq-jgroups-discovery"/>
<property name="hornetq.service.module.jar"
value="hornetq-service-sar"/>
<property name="hornetq.ra.rar.module.jar"
value="hornetq-ra/hornetq-ra-rar"/>
<property name="target.core.jar.dir"
value="${hornetq.core.module.jar}/target"/>
@@ -112,6 +116,7 @@
<property name="target.integration.as.jar.dir"
value="${hornetq.integration.as.module.jar}/target"/>
<property name="target.bootstrap.jar.dir"
value="${hornetq.bootstrap.module.jar}/target"/>
<property name="target.twitter.jar.dir"
value="${hornetq.twitter.module.jar}/target"/>
+ <property name="target.jgroups.jar.dir"
value="${hornetq.jgroups.module.jar}/target"/>
<property name="target.service.jar.dir"
value="${hornetq.service.module.jar}/target"/>
<property name="target.ra.rar.jar.dir"
value="${hornetq.ra.rar.module.jar}/target"/>
<property name="build.core.client.java5.classes.dir"
value="${build.dir}/classes/core-client-java5"/>
@@ -120,6 +125,7 @@
<property name="build.jboss.integration.classes.dir"
value="${build.dir}/classes/jboss-integration"/>
<property name="build.spring.integration.classes.dir"
value="${build.dir}/classes/spring-integration"/>
<property name="build.twitter.integration.classes.dir"
value="${build.dir}/classes/twitter-integration"/>
+ <property name="build.jgroups.discovery.classes.dir"
value="${build.dir}/classes/jgroups-discovery"/>
<property name="build.service.classes.dir"
value="${build.dir}/classes/service"/>
<property name="build.bootstrap.classes.dir"
value="${build.dir}/classes/bootstrap"/>
<property name="build.ra.classes.dir"
value="${build.dir}/classes/ra"/>
@@ -277,6 +283,11 @@
<path refid="org.twitter4j.classpath"/>
</path>
+ <path id="jgroups.discovery.compilation.classpath">
+ <path location="${build.core.classes.dir}"/>
+ <path refid="jgroups.jgroups.classpath"/>
+ </path>
+
<path id="spring.integration.compilation.classpath">
<path refid="core.target.jar"/>
<path location="${build.jms.classes.dir}"/>
@@ -317,6 +328,7 @@
<path refid="junit.junit.classpath"/>
<path refid="org.twitter4j.classpath"/>
<path refid="org.springframework.classpath"/>
+ <path refid="jgroups.jgroups.classpath"/>
<path location="${build.jars.dir}/${ra.jar.name}"/>
<path location="${build.jars.dir}/${jms.jar.name}"/>
<path location="${build.jars.dir}/${jboss.integration.jar.name}"/>
@@ -324,7 +336,8 @@
<path location="${build.jars.dir}/${logging.jar.name}"/>
<path
location="${build.jars.dir}/${spring.integration.jar.name}"/>
<path
location="${build.jars.dir}/${twitter.integration.jar.name}"/>
- </path>
+ <path location="${build.jars.dir}/${jgroups.discovery.jar.name}"/>
+ path>
<path id="jms.test.compilation.classpath">
<path refid="jboss.integration.compilation.classpath"/>
@@ -463,6 +476,7 @@
<mkdir dir="${build.jboss.integration.classes.dir}"/>
<mkdir dir="${build.spring.integration.classes.dir}"/>
<mkdir dir="${build.twitter.integration.classes.dir}"/>
+ <mkdir dir="${build.jgroups.discovery.classes.dir}"/>
<mkdir dir="${build.service.classes.dir}"/>
<mkdir dir="${build.bootstrap.classes.dir}"/>
<mkdir dir="${build.ra.classes.dir}"/>
@@ -908,11 +922,13 @@
<copy
file="${target.integration.as.jar.dir}/hornetq-jboss-as-integration-2.2.3-SNAPSHOT.jar"
tofile="${build.distro.lib.dir}/hornetq-jboss-as-integration.jar"/>
<copy
file="${target.bootstrap.jar.dir}/hornetq-bootstrap-2.2.3-SNAPSHOT.jar"
tofile="${build.distro.lib.dir}/hornetq-bootstrap.jar"/>
<copy
file="${target.twitter.jar.dir}/hornetq-twitter-integration-2.2.3-SNAPSHOT.jar"
tofile="${build.distro.lib.dir}/hornetq-twitter-integration.jar"/>
+ <copy
file="${target.jgroups.jar.dir}/hornetq-jgroups-discovery-2.2.3-SNAPSHOT.jar"
tofile="${build.distro.lib.dir}/hornetq-jgroups-discovery.jar"/>
<copy
file="${target.service.jar.dir}/hornetq-service-sar-2.2.3-SNAPSHOT.jar"
tofile="${build.distro.lib.dir}/hornetq-service.jar"/>
<copy file="${target.ra.rar.jar.dir}/hornetq-rar-2.2.3-SNAPSHOT.rar"
tofile="${build.distro.lib.dir}/hornetq-rar.rar"/>
<copy file="${org.jboss.netty.lib}/${netty.jar.name}"
tofile="${build.distro.lib.dir}/netty.jar"/>
<copy file="${org.twitter4j.lib}/${twitter4j.jar.name}"
tofile="${build.distro.lib.dir}/${twitter4j.jar.name}"/>
+ <copy file="${org.jgroups.lib}/${jgroups.jar.name}"
tofile="${build.distro.lib.dir}/${jgroups.jar.name}"/>
<copy todir="${build.distro.config.dir}">
<fileset dir="distribution/src/main/resources/config">
<include name="*.xml"/>
Modified: branches/HORNETQ-316/distribution/hornetq/src/main/assembly/dep.xml
===================================================================
--- branches/HORNETQ-316/distribution/hornetq/src/main/assembly/dep.xml 2011-08-25
05:25:43 UTC (rev 11224)
+++ branches/HORNETQ-316/distribution/hornetq/src/main/assembly/dep.xml 2011-08-25
19:23:40 UTC (rev 11225)
@@ -199,6 +199,18 @@
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
+ <include>org.hornetq:hornetq-jgroups-discovery</include>
+ </includes>
+ <binaries>
+ <includeDependencies>false</includeDependencies>
+ <outputDirectory>lib</outputDirectory>
+ <unpack>false</unpack>
+
<outputFileNameMapping>${module.artifactId}.${module.extension}</outputFileNameMapping>
+ </binaries>
+ </moduleSet>
+ <moduleSet>
+ <useAllReactorProjects>true</useAllReactorProjects>
+ <includes>
<include>org.hornetq.rest:hornetq-rest</include>
</includes>
<binaries>
Modified:
branches/HORNETQ-316/examples/jms/symmetric-cluster/src/org/hornetq/jms/example/SymmetricClusterExample.java
===================================================================
---
branches/HORNETQ-316/examples/jms/symmetric-cluster/src/org/hornetq/jms/example/SymmetricClusterExample.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/examples/jms/symmetric-cluster/src/org/hornetq/jms/example/SymmetricClusterExample.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -81,7 +81,11 @@
// connection factory directly we avoid having to worry about a JNDI look-up.
// In an app server environment you could use HA-JNDI to lookup from the
clustered JNDI servers without
// having to know about a specific one.
- DiscoveryGroupConfiguration groupConfiguration = new
DiscoveryGroupConfiguration("231.7.7.7", 9876);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(DiscoveryGroupConstants.GROUP_ADDRESS_NAME, "231.7.7.7");
+ params.put(DiscoveryGroupConstants.GROUP_PORT_NAME, 9876);
+
+ DiscoveryGroupConfiguration groupConfiguration = new
DiscoveryGroupConfiguration(SimpleUDPServerLocatorImpl.class.getName(), params,
UUIDGenerator.getInstance().generateStringUUID());
ConnectionFactory cf =
(ConnectionFactory)HornetQJMSClient.createConnectionFactoryWithHA(groupConfiguration,
JMSFactoryType.CF);
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/DiscoveryGroupConfiguration.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/DiscoveryGroupConfiguration.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/DiscoveryGroupConfiguration.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -14,6 +14,7 @@
package org.hornetq.api.core;
import java.io.Serializable;
+import java.util.Map;
import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.core.logging.Logger;
@@ -34,149 +35,33 @@
private static final Logger log =
Logger.getLogger(DiscoveryGroupConfiguration.class);
+ private String serverLocatorClassName;
- private String name;
-
- private String localBindAddress;
+ private final String name;
- private String groupAddress;
-
- private int groupPort;
-
- private long refreshTimeout;
+ private final Map<String, Object> params;
- private long discoveryInitialWaitTimeout;
-
- public DiscoveryGroupConfiguration(final String name,
- final String localBindAddress,
- final String groupAddress,
- final int groupPort,
- final long refreshTimeout,
- final long discoveryInitialWaitTimeout)
+ public DiscoveryGroupConfiguration(final String clazz, final Map<String, Object>
params, final String name)
{
- this.name = name;
- this.groupAddress = groupAddress;
- this.localBindAddress = localBindAddress;
- this.groupPort = groupPort;
- this.refreshTimeout = refreshTimeout;
- this.discoveryInitialWaitTimeout = discoveryInitialWaitTimeout;
- }
+ this.serverLocatorClassName = clazz;
+
+ this.params = params;
- public DiscoveryGroupConfiguration(final String groupAddress,
- final int groupPort)
- {
- this(UUIDGenerator.getInstance().generateStringUUID(), null, groupAddress,
groupPort, HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT);
+ this.name = name;
}
-
- public String getName()
- {
- return name;
- }
- public String getLocalBindAddress()
+ public String getServerLocatorClassName()
{
- return localBindAddress;
+ return this.serverLocatorClassName;
}
- public String getGroupAddress()
+ public Map<String, Object> getParams()
{
- return groupAddress;
+ return this.params;
}
- public int getGroupPort()
+ public String getName()
{
- return groupPort;
+ return this.name;
}
-
- public long getRefreshTimeout()
- {
- return refreshTimeout;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(final String name)
- {
- this.name = name;
- }
-
- /**
- * @param localBindAddress the localBindAddress to set
- */
- public void setLocalBindAdress(final String localBindAddress)
- {
- this.localBindAddress = localBindAddress;
- }
-
- /**
- * @param groupAddress the groupAddress to set
- */
- public void setGroupAddress(final String groupAddress)
- {
- this.groupAddress = groupAddress;
- }
-
- /**
- * @param groupPort the groupPort to set
- */
- public void setGroupPort(final int groupPort)
- {
- this.groupPort = groupPort;
- }
-
- /**
- * @param refreshTimeout the refreshTimeout to set
- */
- public void setRefreshTimeout(final long refreshTimeout)
- {
- this.refreshTimeout = refreshTimeout;
- }
-
- /**
- * @return the discoveryInitialWaitTimeout
- */
- public long getDiscoveryInitialWaitTimeout()
- {
- return discoveryInitialWaitTimeout;
- }
-
- /**
- * @param discoveryInitialWaitTimeout the discoveryInitialWaitTimeout to set
- */
- public void setDiscoveryInitialWaitTimeout(long discoveryInitialWaitTimeout)
- {
- this.discoveryInitialWaitTimeout = discoveryInitialWaitTimeout;
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- DiscoveryGroupConfiguration that = (DiscoveryGroupConfiguration) o;
-
- if (discoveryInitialWaitTimeout != that.discoveryInitialWaitTimeout) return false;
- if (groupPort != that.groupPort) return false;
- if (refreshTimeout != that.refreshTimeout) return false;
- if (groupAddress != null ? !groupAddress.equals(that.groupAddress) :
that.groupAddress != null) return false;
- if (localBindAddress != null ? !localBindAddress.equals(that.localBindAddress) :
that.localBindAddress != null)
- return false;
- if (name != null ? !name.equals(that.name) : that.name != null) return false;
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- int result = name != null ? name.hashCode() : 0;
- result = 31 * result + (localBindAddress != null ? localBindAddress.hashCode() :
0);
- result = 31 * result + (groupAddress != null ? groupAddress.hashCode() : 0);
- result = 31 * result + groupPort;
- result = 31 * result + (int) (refreshTimeout ^ (refreshTimeout >>> 32));
- result = 31 * result + (int) (discoveryInitialWaitTimeout ^
(discoveryInitialWaitTimeout >>> 32));
- return result;
- }
}
Added:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/DiscoveryGroupConstants.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/DiscoveryGroupConstants.java
(rev 0)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/DiscoveryGroupConstants.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.api.core;
+
+/**
+ * A DiscoveryGroupConstants
+ *
+ * @author "<a href=\"tm.igarashi(a)gmail.com\">Tomohisa
Igarashi</a>"
+ *
+ */
+public class DiscoveryGroupConstants
+{
+ // for static discovery
+ public static final String STATIC_CONNECTORS_CONNECTOR_NAMES_NAME =
"static-connector-names";
+ public static final String STATIC_CONNECTORS_LIST_NAME =
"static-connector-list";
+
+ // for simple UDP discovery
+ public static final String LOCAL_BIND_ADDRESS_NAME = "local-bind-address";
+ public static final String GROUP_ADDRESS_NAME = "group-address";
+ public static final String GROUP_PORT_NAME = "group-port";
+ public static final String INITIAL_WAIT_TIMEOUT_NAME =
"initial-wait-timeout";
+ public static final String REFRESH_TIMEOUT_NAME = "refresh-timeout";
+}
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/client/HornetQClient.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/client/HornetQClient.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/client/HornetQClient.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -12,10 +12,18 @@
*/
package org.hornetq.api.core.client;
+import java.lang.reflect.Constructor;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.loadbalance.RoundRobinConnectionLoadBalancingPolicy;
-import org.hornetq.core.client.impl.ServerLocatorImpl;
+import org.hornetq.core.client.impl.StaticServerLocatorImpl;
+import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.UUIDGenerator;
/**
* Utility class for creating HornetQ {@link ClientSessionFactory} objects.
@@ -28,6 +36,8 @@
*/
public class HornetQClient
{
+ private static final Logger log = Logger.getLogger(HornetQClient.class);
+
public static final String DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME =
RoundRobinConnectionLoadBalancingPolicy.class.getCanonicalName();
public static final long DEFAULT_CLIENT_FAILURE_CHECK_PERIOD = 30000;
@@ -109,21 +119,36 @@
*/
public static ServerLocator createServerLocatorWithoutHA(TransportConfiguration...
transportConfigurations)
{
- return new ServerLocatorImpl(false, transportConfigurations);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME,
Arrays.asList(transportConfigurations));
+ DiscoveryGroupConfiguration config = new
DiscoveryGroupConfiguration(StaticServerLocatorImpl.class.getName(), params,
UUIDGenerator.getInstance().generateStringUUID());
+ return createServerLocatorWithoutHA(config);
}
/**
* Create a ServerLocator which creates session factories from a set of live servers,
no HA backup information is propagated to the client
- *
- * The UDP address and port are used to listen for live servers in the cluster
- *
- * @param discoveryAddress The UDP group address to listen for updates
- * @param discoveryPort the UDP port to listen for updates
+ *
+ * @param groupConfiguration The configuration for server discovery
* @return the ServerLocator
*/
public static ServerLocator createServerLocatorWithoutHA(final
DiscoveryGroupConfiguration groupConfiguration)
{
- return new ServerLocatorImpl(false, groupConfiguration);
+ ServerLocator serverLocator = null;
+ String className = groupConfiguration.getServerLocatorClassName();
+ try
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class<?> clazz = loader.loadClass(className);
+ Constructor<?> constructor = clazz.getConstructor(boolean.class,
DiscoveryGroupConfiguration.class);
+ serverLocator = (ServerLocator)constructor.newInstance(Boolean.FALSE,
groupConfiguration);
+ }
+ catch(Exception e)
+ {
+ log.fatal("Could not instantiate ServerLocator implementation class:
", e);
+ return null;
+ }
+
+ return serverLocator;
}
/**
@@ -137,7 +162,10 @@
*/
public static ServerLocator createServerLocatorWithHA(TransportConfiguration...
initialServers)
{
- return new ServerLocatorImpl(true, initialServers);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME,
Arrays.asList(initialServers));
+ DiscoveryGroupConfiguration config = new
DiscoveryGroupConfiguration(StaticServerLocatorImpl.class.getName(), params,
UUIDGenerator.getInstance().generateStringUUID());
+ return createServerLocatorWithHA(config);
}
/**
@@ -152,7 +180,23 @@
*/
public static ServerLocator createServerLocatorWithHA(final
DiscoveryGroupConfiguration groupConfiguration)
{
- return new ServerLocatorImpl(true, groupConfiguration);
+ ServerLocator serverLocator = null;
+ String className = groupConfiguration.getServerLocatorClassName();
+
+ try
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class<?> clazz = loader.loadClass(className);
+ Constructor<?> constructor = clazz.getConstructor(boolean.class,
DiscoveryGroupConfiguration.class);
+ serverLocator = (ServerLocator)constructor.newInstance(Boolean.TRUE,
groupConfiguration);
+ }
+ catch(Exception e)
+ {
+ log.fatal("Could not instantiate ServerLocator implementation class",
e);
+ return null;
+ }
+
+ return serverLocator;
}
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/management/HornetQServerControl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/management/HornetQServerControl.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/api/core/management/HornetQServerControl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -577,8 +577,7 @@
@Parameter(name="useDuplicateDetection", desc="Use
duplicate detection") boolean useDuplicateDetection,
@Parameter(name="confirmationWindowSize",
desc="Confirmation window size") int confirmationWindowSize,
@Parameter(name="clientFailureCheckPeriod",
desc="Period to check client failure") long clientFailureCheckPeriod,
- @Parameter(name="staticConnectorNames", desc="comma
separated list of connector names or name of discovery group if
'useDiscoveryGroup' is set to true") String connectorNames,
- @Parameter(name="useDiscoveryGroup", desc="use
discovery group")boolean useDiscoveryGroup,
+ @Parameter(name="discoveryGroupName", desc="name of
discovery group") String connectorNames,
@Parameter(name="ha", desc="Is it using HA")
boolean ha,
@Parameter(name="user", desc="User name") String
user,
@Parameter(name="password", desc="User
password") String password) throws Exception;
@@ -589,4 +588,17 @@
@Operation(desc = "force the server to stop and notify clients to failover",
impact = MBeanOperationInfo.UNKNOWN)
void forceFailover() throws Exception;
+
+
+ @Operation(desc = "create static discovery group", impact =
MBeanOperationInfo.UNKNOWN)
+ void createStaticDiscoveryGroup(@Parameter(name="name", desc="Name of
the discovery group") String name,
+ @Parameter(name="connectors",
desc="List of the connector name with comma separated") String connectors)
throws Exception;
+
+ @Operation(desc = "create simple UDP discovery group", impact =
MBeanOperationInfo.UNKNOWN)
+ void createSimpleUDPDiscoveryGroup(@Parameter(name="name", desc="Name
of the discovery group") String name,
+ @Parameter(name="localBindAddress",
desc="Local bind address") String localBindAddress,
+ @Parameter(name="groupAddress",
desc="Discovery group address") String groupAddress,
+ @Parameter(name="groupPort",
desc="Discovery group port") int groupPort,
+ @Parameter(name="refreshTimeout",
desc="Refresh timeout") long refreshTimeout,
+ @Parameter(name="initialWaitTimeout",
desc="initial wait timeout to discover") long initialWaitTimeout) throws
Exception;
}
Added:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/AbstractServerLocator.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/AbstractServerLocator.java
(rev 0)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/AbstractServerLocator.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,1068 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.core.client.impl;
+
+import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.*;
+import java.util.concurrent.*;
+
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.Interceptor;
+import org.hornetq.api.core.Pair;
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.ClusterTopologyListener;
+import org.hornetq.api.core.client.HornetQClient;
+import org.hornetq.api.core.client.loadbalance.ConnectionLoadBalancingPolicy;
+import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.HornetQThreadFactory;
+import org.hornetq.utils.UUIDGenerator;
+
+/**
+ * A AbstractServerLocator
+ *
+ * @author Tim Fox
+ */
+public abstract class AbstractServerLocator implements ServerLocatorInternal,
Serializable
+{
+ private static final long serialVersionUID = -1615857864410205260L;
+
+ private static final Logger log = Logger.getLogger(AbstractServerLocator.class);
+
+ private final boolean ha;
+
+ private boolean finalizeCheck = true;
+
+ private boolean clusterConnection;
+
+ private final Set<ClusterTopologyListener> topologyListeners = new
HashSet<ClusterTopologyListener>();
+
+ private Set<ClientSessionFactory> factories = new
HashSet<ClientSessionFactory>();
+
+ private TransportConfiguration[] initialConnectors;
+
+ private DiscoveryGroupConfiguration discoveryGroupConfiguration;
+
+ private Topology topology = new Topology();
+
+ private Pair<TransportConfiguration, TransportConfiguration>[] topologyArray;
+
+ private boolean receivedTopology;
+
+ private boolean compressLargeMessage;
+
+ private ExecutorService threadPool;
+
+ private ScheduledExecutorService scheduledThreadPool;
+
+ private ConnectionLoadBalancingPolicy loadBalancingPolicy;
+
+ private boolean readOnly;
+
+ // Settable attributes:
+
+ private boolean cacheLargeMessagesClient;
+
+ private long clientFailureCheckPeriod;
+
+ private long connectionTTL;
+
+ private long callTimeout;
+
+ private int minLargeMessageSize;
+
+ private int consumerWindowSize;
+
+ private int consumerMaxRate;
+
+ private int confirmationWindowSize;
+
+ private int producerWindowSize;
+
+ private int producerMaxRate;
+
+ private boolean blockOnAcknowledge;
+
+ private boolean blockOnDurableSend;
+
+ private boolean blockOnNonDurableSend;
+
+ private boolean autoGroup;
+
+ private boolean preAcknowledge;
+
+ private String connectionLoadBalancingPolicyClassName;
+
+ private int ackBatchSize;
+
+ private boolean useGlobalPools;
+
+ private int scheduledThreadPoolMaxSize;
+
+ private int threadPoolMaxSize;
+
+ private long retryInterval;
+
+ private double retryIntervalMultiplier;
+
+ private long maxRetryInterval;
+
+ private int reconnectAttempts;
+
+ private int initialConnectAttempts;
+
+ private boolean failoverOnInitialConnection;
+
+ private int initialMessagePacketSize;
+
+ private volatile boolean closed;
+
+ private final List<Interceptor> interceptors = new
CopyOnWriteArrayList<Interceptor>();
+
+ private static ExecutorService globalThreadPool;
+
+ private static ScheduledExecutorService globalScheduledThreadPool;
+
+ private String groupID;
+
+ private String nodeID;
+
+ private TransportConfiguration clusterTransportConfiguration;
+
+ private boolean backup;
+
+ private final Exception e = new Exception();
+
+ // To be called when there are ServerLocator being finalized.
+ // To be used on test assertions
+ public static Runnable finalizeCallback = null;
+
+ public static synchronized void clearThreadPools()
+ {
+
+ if (globalThreadPool != null)
+ {
+ globalThreadPool.shutdown();
+ try
+ {
+ if (!globalThreadPool.awaitTermination(10, TimeUnit.SECONDS))
+ {
+ throw new IllegalStateException("Couldn't finish the
globalThreadPool");
+ }
+ }
+ catch (InterruptedException e)
+ {
+ }
+ finally
+ {
+ globalThreadPool = null;
+ }
+ }
+
+ if (globalScheduledThreadPool != null)
+ {
+ globalScheduledThreadPool.shutdown();
+ try
+ {
+ if (!globalScheduledThreadPool.awaitTermination(10, TimeUnit.SECONDS))
+ {
+ throw new IllegalStateException("Couldn't finish the
globalScheduledThreadPool");
+ }
+ }
+ catch (InterruptedException e)
+ {
+ }
+ finally
+ {
+ globalScheduledThreadPool = null;
+ }
+ }
+ }
+
+ private static synchronized ExecutorService getGlobalThreadPool()
+ {
+ if (globalThreadPool == null)
+ {
+ ThreadFactory factory = new
HornetQThreadFactory("HornetQ-client-global-threads", true,
getThisClassLoader());
+
+ globalThreadPool = Executors.newCachedThreadPool(factory);
+ }
+
+ return globalThreadPool;
+ }
+
+ public static synchronized ScheduledExecutorService getGlobalScheduledThreadPool()
+ {
+ if (globalScheduledThreadPool == null)
+ {
+ ThreadFactory factory = new
HornetQThreadFactory("HornetQ-client-global-scheduled-threads",
+ true,
+ getThisClassLoader());
+
+ globalScheduledThreadPool =
Executors.newScheduledThreadPool(HornetQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE,
+
+ factory);
+ }
+
+ return globalScheduledThreadPool;
+ }
+
+ protected void setThreadPools()
+ {
+ if (useGlobalPools)
+ {
+ threadPool = getGlobalThreadPool();
+
+ scheduledThreadPool = getGlobalScheduledThreadPool();
+ }
+ else
+ {
+ ThreadFactory factory = new
HornetQThreadFactory("HornetQ-client-factory-threads-" +
System.identityHashCode(this),
+ true,
+ getThisClassLoader());
+
+ if (threadPoolMaxSize == -1)
+ {
+ threadPool = Executors.newCachedThreadPool(factory);
+ }
+ else
+ {
+ threadPool = Executors.newFixedThreadPool(threadPoolMaxSize, factory);
+ }
+
+ factory = new
HornetQThreadFactory("HornetQ-client-factory-pinger-threads-" +
System.identityHashCode(this),
+ true,
+ getThisClassLoader());
+
+ scheduledThreadPool =
Executors.newScheduledThreadPool(scheduledThreadPoolMaxSize, factory);
+ }
+ }
+
+ private static ClassLoader getThisClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return ClientSessionFactoryImpl.class.getClassLoader();
+ }
+ });
+
+ }
+
+ protected void instantiateLoadBalancingPolicy()
+ {
+ if (connectionLoadBalancingPolicyClassName == null)
+ {
+ throw new IllegalStateException("Please specify a load balancing policy
class name on the session factory");
+ }
+
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Class<?> clazz =
loader.loadClass(connectionLoadBalancingPolicyClassName);
+ loadBalancingPolicy = (ConnectionLoadBalancingPolicy)clazz.newInstance();
+ return null;
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Unable to instantiate load
balancing policy \"" + connectionLoadBalancingPolicyClassName +
+ "\"",
+ e);
+ }
+ }
+ });
+ }
+
+ public AbstractServerLocator(final boolean useHA,
+ final DiscoveryGroupConfiguration
discoveryGroupConfiguration)
+ {
+ e.fillInStackTrace();
+ this.ha = useHA;
+
+ this.discoveryGroupConfiguration = discoveryGroupConfiguration;
+
+ this.nodeID = UUIDGenerator.getInstance().generateStringUUID();
+
+ clientFailureCheckPeriod = HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD;
+
+ connectionTTL = HornetQClient.DEFAULT_CONNECTION_TTL;
+
+ callTimeout = HornetQClient.DEFAULT_CALL_TIMEOUT;
+
+ minLargeMessageSize = HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
+
+ consumerWindowSize = HornetQClient.DEFAULT_CONSUMER_WINDOW_SIZE;
+
+ consumerMaxRate = HornetQClient.DEFAULT_CONSUMER_MAX_RATE;
+
+ confirmationWindowSize = HornetQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE;
+
+ producerWindowSize = HornetQClient.DEFAULT_PRODUCER_WINDOW_SIZE;
+
+ producerMaxRate = HornetQClient.DEFAULT_PRODUCER_MAX_RATE;
+
+ blockOnAcknowledge = HornetQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE;
+
+ blockOnDurableSend = HornetQClient.DEFAULT_BLOCK_ON_DURABLE_SEND;
+
+ blockOnNonDurableSend = HornetQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND;
+
+ autoGroup = HornetQClient.DEFAULT_AUTO_GROUP;
+
+ preAcknowledge = HornetQClient.DEFAULT_PRE_ACKNOWLEDGE;
+
+ ackBatchSize = HornetQClient.DEFAULT_ACK_BATCH_SIZE;
+
+ connectionLoadBalancingPolicyClassName =
HornetQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME;
+
+ useGlobalPools = HornetQClient.DEFAULT_USE_GLOBAL_POOLS;
+
+ scheduledThreadPoolMaxSize = HornetQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE;
+
+ threadPoolMaxSize = HornetQClient.DEFAULT_THREAD_POOL_MAX_SIZE;
+
+ retryInterval = HornetQClient.DEFAULT_RETRY_INTERVAL;
+
+ retryIntervalMultiplier = HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER;
+
+ maxRetryInterval = HornetQClient.DEFAULT_MAX_RETRY_INTERVAL;
+
+ reconnectAttempts = HornetQClient.DEFAULT_RECONNECT_ATTEMPTS;
+
+ initialConnectAttempts = HornetQClient.INITIAL_CONNECT_ATTEMPTS;
+
+ failoverOnInitialConnection =
HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION;
+
+ cacheLargeMessagesClient = HornetQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT;
+
+ initialMessagePacketSize = HornetQClient.DEFAULT_INITIAL_MESSAGE_PACKET_SIZE;
+
+ cacheLargeMessagesClient = HornetQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT;
+
+ compressLargeMessage = HornetQClient.DEFAULT_COMPRESS_LARGE_MESSAGES;
+
+ clusterConnection = false;
+ }
+
+ protected TransportConfiguration selectConnector()
+ {
+ if (receivedTopology)
+ {
+ int pos = loadBalancingPolicy.select(topologyArray.length);
+
+ Pair<TransportConfiguration, TransportConfiguration> pair =
topologyArray[pos];
+
+ return pair.a;
+ }
+ else
+ {
+ // Get from initialconnectors
+
+ int pos = loadBalancingPolicy.select(initialConnectors.length);
+
+ return initialConnectors[pos];
+ }
+ }
+
+ protected int getConnectorLength()
+ {
+ if(receivedTopology)
+ {
+ return topologyArray.length;
+ }
+ else if(initialConnectors == null)
+ {
+ return -1;
+ }
+ else
+ {
+ return initialConnectors.length;
+ }
+ }
+
+ public void disableFinalizeCheck()
+ {
+ finalizeCheck = false;
+ }
+
+ public synchronized boolean isHA()
+ {
+ return ha;
+ }
+
+ public synchronized boolean isCacheLargeMessagesClient()
+ {
+ return cacheLargeMessagesClient;
+ }
+
+ public synchronized void setCacheLargeMessagesClient(final boolean cached)
+ {
+ cacheLargeMessagesClient = cached;
+ }
+
+ public synchronized long getClientFailureCheckPeriod()
+ {
+ return clientFailureCheckPeriod;
+ }
+
+ public synchronized void setClientFailureCheckPeriod(final long
clientFailureCheckPeriod)
+ {
+ checkWrite();
+ this.clientFailureCheckPeriod = clientFailureCheckPeriod;
+ }
+
+ public synchronized long getConnectionTTL()
+ {
+ return connectionTTL;
+ }
+
+ public synchronized void setConnectionTTL(final long connectionTTL)
+ {
+ checkWrite();
+ this.connectionTTL = connectionTTL;
+ }
+
+ public synchronized long getCallTimeout()
+ {
+ return callTimeout;
+ }
+
+ public synchronized void setCallTimeout(final long callTimeout)
+ {
+ checkWrite();
+ this.callTimeout = callTimeout;
+ }
+
+ public synchronized int getMinLargeMessageSize()
+ {
+ return minLargeMessageSize;
+ }
+
+ public synchronized void setMinLargeMessageSize(final int minLargeMessageSize)
+ {
+ checkWrite();
+ this.minLargeMessageSize = minLargeMessageSize;
+ }
+
+ public synchronized int getConsumerWindowSize()
+ {
+ return consumerWindowSize;
+ }
+
+ public synchronized void setConsumerWindowSize(final int consumerWindowSize)
+ {
+ checkWrite();
+ this.consumerWindowSize = consumerWindowSize;
+ }
+
+ public synchronized int getConsumerMaxRate()
+ {
+ return consumerMaxRate;
+ }
+
+ public synchronized void setConsumerMaxRate(final int consumerMaxRate)
+ {
+ checkWrite();
+ this.consumerMaxRate = consumerMaxRate;
+ }
+
+ public synchronized int getConfirmationWindowSize()
+ {
+ return confirmationWindowSize;
+ }
+
+ public synchronized void setConfirmationWindowSize(final int confirmationWindowSize)
+ {
+ checkWrite();
+ this.confirmationWindowSize = confirmationWindowSize;
+ }
+
+ public synchronized int getProducerWindowSize()
+ {
+ return producerWindowSize;
+ }
+
+ public synchronized void setProducerWindowSize(final int producerWindowSize)
+ {
+ checkWrite();
+ this.producerWindowSize = producerWindowSize;
+ }
+
+ public synchronized int getProducerMaxRate()
+ {
+ return producerMaxRate;
+ }
+
+ public synchronized void setProducerMaxRate(final int producerMaxRate)
+ {
+ checkWrite();
+ this.producerMaxRate = producerMaxRate;
+ }
+
+ public synchronized boolean isBlockOnAcknowledge()
+ {
+ return blockOnAcknowledge;
+ }
+
+ public synchronized void setBlockOnAcknowledge(final boolean blockOnAcknowledge)
+ {
+ checkWrite();
+ this.blockOnAcknowledge = blockOnAcknowledge;
+ }
+
+ public synchronized boolean isBlockOnDurableSend()
+ {
+ return blockOnDurableSend;
+ }
+
+ public synchronized void setBlockOnDurableSend(final boolean blockOnDurableSend)
+ {
+ checkWrite();
+ this.blockOnDurableSend = blockOnDurableSend;
+ }
+
+ public synchronized boolean isBlockOnNonDurableSend()
+ {
+ return blockOnNonDurableSend;
+ }
+
+ public synchronized void setBlockOnNonDurableSend(final boolean
blockOnNonDurableSend)
+ {
+ checkWrite();
+ this.blockOnNonDurableSend = blockOnNonDurableSend;
+ }
+
+ public synchronized boolean isAutoGroup()
+ {
+ return autoGroup;
+ }
+
+ public synchronized void setAutoGroup(final boolean autoGroup)
+ {
+ checkWrite();
+ this.autoGroup = autoGroup;
+ }
+
+ public synchronized boolean isPreAcknowledge()
+ {
+ return preAcknowledge;
+ }
+
+ public synchronized void setPreAcknowledge(final boolean preAcknowledge)
+ {
+ checkWrite();
+ this.preAcknowledge = preAcknowledge;
+ }
+
+ public synchronized int getAckBatchSize()
+ {
+ return ackBatchSize;
+ }
+
+ public synchronized void setAckBatchSize(final int ackBatchSize)
+ {
+ checkWrite();
+ this.ackBatchSize = ackBatchSize;
+ }
+
+ public synchronized boolean isUseGlobalPools()
+ {
+ return useGlobalPools;
+ }
+
+ public synchronized void setUseGlobalPools(final boolean useGlobalPools)
+ {
+ checkWrite();
+ this.useGlobalPools = useGlobalPools;
+ }
+
+ public synchronized int getScheduledThreadPoolMaxSize()
+ {
+ return scheduledThreadPoolMaxSize;
+ }
+
+ public synchronized void setScheduledThreadPoolMaxSize(final int
scheduledThreadPoolMaxSize)
+ {
+ checkWrite();
+ this.scheduledThreadPoolMaxSize = scheduledThreadPoolMaxSize;
+ }
+
+ public synchronized int getThreadPoolMaxSize()
+ {
+ return threadPoolMaxSize;
+ }
+
+ public synchronized void setThreadPoolMaxSize(final int threadPoolMaxSize)
+ {
+ checkWrite();
+ this.threadPoolMaxSize = threadPoolMaxSize;
+ }
+
+ public synchronized long getRetryInterval()
+ {
+ return retryInterval;
+ }
+
+ public synchronized void setRetryInterval(final long retryInterval)
+ {
+ checkWrite();
+ this.retryInterval = retryInterval;
+ }
+
+ public synchronized long getMaxRetryInterval()
+ {
+ return maxRetryInterval;
+ }
+
+ public synchronized void setMaxRetryInterval(final long retryInterval)
+ {
+ checkWrite();
+ maxRetryInterval = retryInterval;
+ }
+
+ public synchronized double getRetryIntervalMultiplier()
+ {
+ return retryIntervalMultiplier;
+ }
+
+ public synchronized void setRetryIntervalMultiplier(final double
retryIntervalMultiplier)
+ {
+ checkWrite();
+ this.retryIntervalMultiplier = retryIntervalMultiplier;
+ }
+
+ public synchronized int getReconnectAttempts()
+ {
+ return reconnectAttempts;
+ }
+
+ public synchronized void setReconnectAttempts(final int reconnectAttempts)
+ {
+ checkWrite();
+ this.reconnectAttempts = reconnectAttempts;
+ }
+
+ public void setInitialConnectAttempts(int initialConnectAttempts)
+ {
+ checkWrite();
+ this.initialConnectAttempts = initialConnectAttempts;
+ }
+
+ public int getInitialConnectAttempts()
+ {
+ return initialConnectAttempts;
+ }
+
+ public synchronized boolean isFailoverOnInitialConnection()
+ {
+ return this.failoverOnInitialConnection;
+ }
+
+ public synchronized void setFailoverOnInitialConnection(final boolean failover)
+ {
+ checkWrite();
+ this.failoverOnInitialConnection = failover;
+ }
+
+ public synchronized String getConnectionLoadBalancingPolicyClassName()
+ {
+ return connectionLoadBalancingPolicyClassName;
+ }
+
+ public synchronized void setConnectionLoadBalancingPolicyClassName(final String
loadBalancingPolicyClassName)
+ {
+ checkWrite();
+ connectionLoadBalancingPolicyClassName = loadBalancingPolicyClassName;
+ }
+
+ public TransportConfiguration[] getStaticTransportConfigurations()
+ {
+ return this.initialConnectors;
+ }
+
+ public DiscoveryGroupConfiguration getDiscoveryGroupConfiguration()
+ {
+ return discoveryGroupConfiguration;
+ }
+
+ public void addInterceptor(final Interceptor interceptor)
+ {
+ interceptors.add(interceptor);
+ }
+
+ public boolean removeInterceptor(final Interceptor interceptor)
+ {
+ return interceptors.remove(interceptor);
+ }
+
+ public synchronized int getInitialMessagePacketSize()
+ {
+ return initialMessagePacketSize;
+ }
+
+ public synchronized void setInitialMessagePacketSize(final int size)
+ {
+ checkWrite();
+ initialMessagePacketSize = size;
+ }
+
+ public void setGroupID(final String groupID)
+ {
+ checkWrite();
+ this.groupID = groupID;
+ }
+
+ public String getGroupID()
+ {
+ return groupID;
+ }
+
+ public boolean isCompressLargeMessage()
+ {
+ return compressLargeMessage;
+ }
+
+ public void setCompressLargeMessage(boolean compress)
+ {
+ this.compressLargeMessage = compress;
+ }
+
+ private void checkWrite()
+ {
+ if (readOnly)
+ {
+ throw new IllegalStateException("Cannot set attribute on SessionFactory
after it has been used");
+ }
+ }
+
+ public void setNodeID(String nodeID)
+ {
+ this.nodeID = nodeID;
+ }
+
+ public String getNodeID()
+ {
+ return nodeID;
+ }
+
+ public void setClusterConnection(boolean clusterConnection)
+ {
+ this.clusterConnection = clusterConnection;
+ }
+
+ public boolean isClusterConnection()
+ {
+ return clusterConnection;
+ }
+
+ public TransportConfiguration getClusterTransportConfiguration()
+ {
+ return clusterTransportConfiguration;
+ }
+
+ public void setClusterTransportConfiguration(TransportConfiguration tc)
+ {
+ this.clusterTransportConfiguration = tc;
+ }
+
+ public boolean isBackup()
+ {
+ return backup;
+ }
+
+ public void setBackup(boolean backup)
+ {
+ this.backup = backup;
+ }
+
+ protected boolean isReceivedTopology()
+ {
+ return this.receivedTopology;
+ }
+
+ protected boolean doFinalizeCheck()
+ {
+ return this.finalizeCheck;
+ }
+
+ protected ConnectionLoadBalancingPolicy getLoadBalancingPolicy()
+ {
+ return this.loadBalancingPolicy;
+ }
+
+ protected ExecutorService getThreadPool()
+ {
+ return threadPool;
+ }
+
+ protected ScheduledExecutorService getScheduledThreadPool()
+ {
+ return scheduledThreadPool;
+ }
+
+ protected List<Interceptor> getInterceptors()
+ {
+ return this.interceptors;
+ }
+
+ protected TransportConfiguration[] getInitialConnectors()
+ {
+ return this.initialConnectors;
+ }
+
+ protected void setInitialConnectors(TransportConfiguration[] initialConnectors)
+ {
+ this.initialConnectors = initialConnectors;
+ }
+
+ protected boolean isReadOnly()
+ {
+ return this.readOnly;
+ }
+
+ protected void setReadOnly(boolean readOnly)
+ {
+ this.readOnly = readOnly;
+ }
+
+ protected boolean isClosed()
+ {
+ return this.closed;
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ if (finalizeCheck)
+ {
+ close();
+ }
+
+ super.finalize();
+ }
+
+ public void close()
+ {
+ if (closed)
+ {
+ return;
+ }
+
+
+ for (ClientSessionFactory factory : factories)
+ {
+ factory.close();
+ }
+
+ factories.clear();
+
+ if (!useGlobalPools)
+ {
+ if (threadPool != null)
+ {
+ threadPool.shutdown();
+
+ try
+ {
+ if (!threadPool.awaitTermination(10000, TimeUnit.MILLISECONDS))
+ {
+ log.warn("Timed out waiting for pool to terminate");
+ }
+ }
+ catch (InterruptedException ignore)
+ {
+ }
+ }
+
+ if (scheduledThreadPool != null)
+ {
+ scheduledThreadPool.shutdown();
+
+ try
+ {
+ if (!scheduledThreadPool.awaitTermination(10000, TimeUnit.MILLISECONDS))
+ {
+ log.warn("Timed out waiting for scheduled pool to
terminate");
+ }
+ }
+ catch (InterruptedException ignore)
+ {
+ }
+ }
+ }
+ readOnly = false;
+
+ closed = true;
+ }
+
+ public synchronized void notifyNodeDown(final String nodeID)
+ {
+ boolean removed = false;
+
+ if (!ha)
+ {
+ return;
+ }
+
+ removed = topology.removeMember(nodeID);
+
+ if (!topology.isEmpty())
+ {
+ updateArraysAndPairs();
+
+ if (topology.nodes() == 1 && topology.getMember(this.nodeID) != null)
+ {
+ receivedTopology = false;
+ }
+ }
+ else
+ {
+ topologyArray = null;
+
+ receivedTopology = false;
+ }
+
+ if (removed)
+ {
+ for (ClusterTopologyListener listener : topologyListeners)
+ {
+ listener.nodeDown(nodeID);
+ }
+ }
+ }
+
+ public synchronized void notifyNodeUp(final String nodeID,
+ final Pair<TransportConfiguration,
TransportConfiguration> connectorPair,
+ final boolean last)
+ {
+ if (!ha)
+ {
+ return;
+ }
+
+ topology.addMember(nodeID, new TopologyMember(connectorPair));
+
+ TopologyMember actMember = topology.getMember(nodeID);
+
+ if (actMember.getConnector().a != null && actMember.getConnector().b !=
null)
+ {
+ for (ClientSessionFactory factory : factories)
+ {
+
((ClientSessionFactoryInternal)factory).setBackupConnector(actMember.getConnector().a,
+
actMember.getConnector().b);
+ }
+ }
+
+ if (connectorPair.a != null)
+ {
+ updateArraysAndPairs();
+ }
+
+ if (last)
+ {
+ receivedTopology = true;
+ }
+
+ for (ClusterTopologyListener listener : topologyListeners)
+ {
+ listener.nodeUP(nodeID, connectorPair, last);
+ }
+
+ // Notify if waiting on getting topology
+ notify();
+ }
+
+ private void updateArraysAndPairs()
+ {
+ topologyArray = (Pair<TransportConfiguration,
TransportConfiguration>[])Array.newInstance(Pair.class,
+
topology.members());
+
+ int count = 0;
+ for (TopologyMember pair : topology.getMembers())
+ {
+ topologyArray[count++] = pair.getConnector();
+ }
+ }
+
+ public synchronized void factoryClosed(final ClientSessionFactory factory)
+ {
+ factories.remove(factory);
+
+ if (factories.isEmpty())
+ {
+ // Go back to using the broadcast or static list
+
+ receivedTopology = false;
+
+ topology = null;
+
+ }
+ }
+
+ public Topology getTopology()
+ {
+ return topology;
+ }
+
+ public void addClusterTopologyListener(final ClusterTopologyListener listener)
+ {
+ topologyListeners.add(listener);
+ if(topology.members() > 0)
+ {
+ log.debug("ServerLocatorImpl.addClusterTopologyListener");
+ }
+ }
+
+ public void removeClusterTopologyListener(final ClusterTopologyListener listener)
+ {
+ topologyListeners.remove(listener);
+ }
+
+ public synchronized void addFactory(ClientSessionFactoryInternal factory)
+ {
+ if (factory != null)
+ {
+ TransportConfiguration backup =
topology.getBackupForConnector(factory.getConnectorConfiguration());
+ factory.setBackupConnector(factory.getConnectorConfiguration(), backup);
+ factories.add(factory);
+ }
+ }
+
+ public static void shutdown()
+ {
+ if (globalScheduledThreadPool != null)
+ {
+ globalScheduledThreadPool.shutdown();
+ globalScheduledThreadPool = null;
+ }
+ if (globalThreadPool != null)
+ {
+ globalThreadPool.shutdown();
+ globalThreadPool = null;
+ }
+ }
+
+ public boolean isStaticDirectConnection(TransportConfiguration conf)
+ {
+ return false;
+ }
+}
Deleted:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorImpl.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -1,1505 +0,0 @@
-/*
- * Copyright 2010 Red Hat, Inc.
- * Red Hat 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.hornetq.core.client.impl;
-
-import java.io.Serializable;
-import java.lang.reflect.Array;
-import java.net.InetAddress;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.*;
-import java.util.concurrent.*;
-
-import org.hornetq.api.core.DiscoveryGroupConfiguration;
-import org.hornetq.api.core.HornetQException;
-import org.hornetq.api.core.Interceptor;
-import org.hornetq.api.core.Pair;
-import org.hornetq.api.core.TransportConfiguration;
-import org.hornetq.api.core.client.ClientSessionFactory;
-import org.hornetq.api.core.client.ClusterTopologyListener;
-import org.hornetq.api.core.client.HornetQClient;
-import org.hornetq.api.core.client.loadbalance.ConnectionLoadBalancingPolicy;
-import org.hornetq.core.cluster.DiscoveryEntry;
-import org.hornetq.core.cluster.DiscoveryGroup;
-import org.hornetq.core.cluster.DiscoveryListener;
-import org.hornetq.core.cluster.impl.DiscoveryGroupImpl;
-import org.hornetq.core.logging.Logger;
-import org.hornetq.utils.HornetQThreadFactory;
-import org.hornetq.utils.UUIDGenerator;
-
-/**
- * A ServerLocatorImpl
- *
- * @author Tim Fox
- */
-public class ServerLocatorImpl implements ServerLocatorInternal, DiscoveryListener,
Serializable
-{
- private static final long serialVersionUID = -1615857864410205260L;
-
- private static final Logger log = Logger.getLogger(ServerLocatorImpl.class);
-
- private final boolean ha;
-
- private boolean finalizeCheck = true;
-
- private boolean clusterConnection;
-
- private final Set<ClusterTopologyListener> topologyListeners = new
HashSet<ClusterTopologyListener>();
-
- private Set<ClientSessionFactory> factories = new
HashSet<ClientSessionFactory>();
-
- private TransportConfiguration[] initialConnectors;
-
- private DiscoveryGroupConfiguration discoveryGroupConfiguration;
-
- private StaticConnector staticConnector = new StaticConnector();
-
- private Topology topology = new Topology();
-
- private Pair<TransportConfiguration, TransportConfiguration>[] topologyArray;
-
- private boolean receivedTopology;
-
- private boolean compressLargeMessage;
-
- private ExecutorService threadPool;
-
- private ScheduledExecutorService scheduledThreadPool;
-
- private DiscoveryGroup discoveryGroup;
-
- private ConnectionLoadBalancingPolicy loadBalancingPolicy;
-
- private boolean readOnly;
-
- // Settable attributes:
-
- private boolean cacheLargeMessagesClient;
-
- private long clientFailureCheckPeriod;
-
- private long connectionTTL;
-
- private long callTimeout;
-
- private int minLargeMessageSize;
-
- private int consumerWindowSize;
-
- private int consumerMaxRate;
-
- private int confirmationWindowSize;
-
- private int producerWindowSize;
-
- private int producerMaxRate;
-
- private boolean blockOnAcknowledge;
-
- private boolean blockOnDurableSend;
-
- private boolean blockOnNonDurableSend;
-
- private boolean autoGroup;
-
- private boolean preAcknowledge;
-
- private String connectionLoadBalancingPolicyClassName;
-
- private int ackBatchSize;
-
- private boolean useGlobalPools;
-
- private int scheduledThreadPoolMaxSize;
-
- private int threadPoolMaxSize;
-
- private long retryInterval;
-
- private double retryIntervalMultiplier;
-
- private long maxRetryInterval;
-
- private int reconnectAttempts;
-
- private int initialConnectAttempts;
-
- private boolean failoverOnInitialConnection;
-
- private int initialMessagePacketSize;
-
- private volatile boolean closed;
-
- private volatile boolean closing;
-
- private final List<Interceptor> interceptors = new
CopyOnWriteArrayList<Interceptor>();
-
- private static ExecutorService globalThreadPool;
-
- private static ScheduledExecutorService globalScheduledThreadPool;
-
- private String groupID;
-
- private String nodeID;
-
- private TransportConfiguration clusterTransportConfiguration;
-
- private boolean backup;
-
- private final Exception e = new Exception();
-
- // To be called when there are ServerLocator being finalized.
- // To be used on test assertions
- public static Runnable finalizeCallback = null;
-
- public static synchronized void clearThreadPools()
- {
-
- if (globalThreadPool != null)
- {
- globalThreadPool.shutdown();
- try
- {
- if (!globalThreadPool.awaitTermination(10, TimeUnit.SECONDS))
- {
- throw new IllegalStateException("Couldn't finish the
globalThreadPool");
- }
- }
- catch (InterruptedException e)
- {
- }
- finally
- {
- globalThreadPool = null;
- }
- }
-
- if (globalScheduledThreadPool != null)
- {
- globalScheduledThreadPool.shutdown();
- try
- {
- if (!globalScheduledThreadPool.awaitTermination(10, TimeUnit.SECONDS))
- {
- throw new IllegalStateException("Couldn't finish the
globalScheduledThreadPool");
- }
- }
- catch (InterruptedException e)
- {
- }
- finally
- {
- globalScheduledThreadPool = null;
- }
- }
- }
-
- private static synchronized ExecutorService getGlobalThreadPool()
- {
- if (globalThreadPool == null)
- {
- ThreadFactory factory = new
HornetQThreadFactory("HornetQ-client-global-threads", true,
getThisClassLoader());
-
- globalThreadPool = Executors.newCachedThreadPool(factory);
- }
-
- return globalThreadPool;
- }
-
- public static synchronized ScheduledExecutorService getGlobalScheduledThreadPool()
- {
- if (globalScheduledThreadPool == null)
- {
- ThreadFactory factory = new
HornetQThreadFactory("HornetQ-client-global-scheduled-threads",
- true,
- getThisClassLoader());
-
- globalScheduledThreadPool =
Executors.newScheduledThreadPool(HornetQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE,
-
- factory);
- }
-
- return globalScheduledThreadPool;
- }
-
- private void setThreadPools()
- {
- if (useGlobalPools)
- {
- threadPool = getGlobalThreadPool();
-
- scheduledThreadPool = getGlobalScheduledThreadPool();
- }
- else
- {
- ThreadFactory factory = new
HornetQThreadFactory("HornetQ-client-factory-threads-" +
System.identityHashCode(this),
- true,
- getThisClassLoader());
-
- if (threadPoolMaxSize == -1)
- {
- threadPool = Executors.newCachedThreadPool(factory);
- }
- else
- {
- threadPool = Executors.newFixedThreadPool(threadPoolMaxSize, factory);
- }
-
- factory = new
HornetQThreadFactory("HornetQ-client-factory-pinger-threads-" +
System.identityHashCode(this),
- true,
- getThisClassLoader());
-
- scheduledThreadPool =
Executors.newScheduledThreadPool(scheduledThreadPoolMaxSize, factory);
- }
- }
-
- private static ClassLoader getThisClassLoader()
- {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
- {
- public ClassLoader run()
- {
- return ClientSessionFactoryImpl.class.getClassLoader();
- }
- });
-
- }
-
- private void instantiateLoadBalancingPolicy()
- {
- if (connectionLoadBalancingPolicyClassName == null)
- {
- throw new IllegalStateException("Please specify a load balancing policy
class name on the session factory");
- }
-
- AccessController.doPrivileged(new PrivilegedAction<Object>()
- {
- public Object run()
- {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try
- {
- Class<?> clazz =
loader.loadClass(connectionLoadBalancingPolicyClassName);
- loadBalancingPolicy = (ConnectionLoadBalancingPolicy)clazz.newInstance();
- return null;
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("Unable to instantiate load
balancing policy \"" + connectionLoadBalancingPolicyClassName +
- "\"",
- e);
- }
- }
- });
- }
-
- private synchronized void initialise() throws Exception
- {
- if (!readOnly)
- {
- setThreadPools();
-
- instantiateLoadBalancingPolicy();
-
- if (discoveryGroupConfiguration != null)
- {
- InetAddress groupAddress =
InetAddress.getByName(discoveryGroupConfiguration.getGroupAddress());
-
- InetAddress lbAddress;
-
- if (discoveryGroupConfiguration.getLocalBindAddress() != null)
- {
- lbAddress =
InetAddress.getByName(discoveryGroupConfiguration.getLocalBindAddress());
- }
- else
- {
- lbAddress = null;
- }
-
- discoveryGroup = new DiscoveryGroupImpl(nodeID,
-
discoveryGroupConfiguration.getName(),
- lbAddress,
- groupAddress,
-
discoveryGroupConfiguration.getGroupPort(),
-
discoveryGroupConfiguration.getRefreshTimeout());
-
- discoveryGroup.registerListener(this);
-
- discoveryGroup.start();
- }
-
- readOnly = true;
- }
- }
-
- private ServerLocatorImpl(final boolean useHA,
- final DiscoveryGroupConfiguration
discoveryGroupConfiguration,
- final TransportConfiguration[] transportConfigs)
- {
- e.fillInStackTrace();
- this.ha = useHA;
-
- this.discoveryGroupConfiguration = discoveryGroupConfiguration;
-
- this.initialConnectors = transportConfigs;
-
- this.nodeID = UUIDGenerator.getInstance().generateStringUUID();
-
- clientFailureCheckPeriod = HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD;
-
- connectionTTL = HornetQClient.DEFAULT_CONNECTION_TTL;
-
- callTimeout = HornetQClient.DEFAULT_CALL_TIMEOUT;
-
- minLargeMessageSize = HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
-
- consumerWindowSize = HornetQClient.DEFAULT_CONSUMER_WINDOW_SIZE;
-
- consumerMaxRate = HornetQClient.DEFAULT_CONSUMER_MAX_RATE;
-
- confirmationWindowSize = HornetQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE;
-
- producerWindowSize = HornetQClient.DEFAULT_PRODUCER_WINDOW_SIZE;
-
- producerMaxRate = HornetQClient.DEFAULT_PRODUCER_MAX_RATE;
-
- blockOnAcknowledge = HornetQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE;
-
- blockOnDurableSend = HornetQClient.DEFAULT_BLOCK_ON_DURABLE_SEND;
-
- blockOnNonDurableSend = HornetQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND;
-
- autoGroup = HornetQClient.DEFAULT_AUTO_GROUP;
-
- preAcknowledge = HornetQClient.DEFAULT_PRE_ACKNOWLEDGE;
-
- ackBatchSize = HornetQClient.DEFAULT_ACK_BATCH_SIZE;
-
- connectionLoadBalancingPolicyClassName =
HornetQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME;
-
- useGlobalPools = HornetQClient.DEFAULT_USE_GLOBAL_POOLS;
-
- scheduledThreadPoolMaxSize = HornetQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE;
-
- threadPoolMaxSize = HornetQClient.DEFAULT_THREAD_POOL_MAX_SIZE;
-
- retryInterval = HornetQClient.DEFAULT_RETRY_INTERVAL;
-
- retryIntervalMultiplier = HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER;
-
- maxRetryInterval = HornetQClient.DEFAULT_MAX_RETRY_INTERVAL;
-
- reconnectAttempts = HornetQClient.DEFAULT_RECONNECT_ATTEMPTS;
-
- initialConnectAttempts = HornetQClient.INITIAL_CONNECT_ATTEMPTS;
-
- failoverOnInitialConnection =
HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION;
-
- cacheLargeMessagesClient = HornetQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT;
-
- initialMessagePacketSize = HornetQClient.DEFAULT_INITIAL_MESSAGE_PACKET_SIZE;
-
- cacheLargeMessagesClient = HornetQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT;
-
- compressLargeMessage = HornetQClient.DEFAULT_COMPRESS_LARGE_MESSAGES;
-
- clusterConnection = false;
- }
-
- /**
- * Create a ServerLocatorImpl using UDP discovery to lookup cluster
- *
- * @param discoveryAddress
- * @param discoveryPort
- */
- public ServerLocatorImpl(final boolean useHA, final DiscoveryGroupConfiguration
groupConfiguration)
- {
- this(useHA, groupConfiguration, null);
- }
-
- /**
- * Create a ServerLocatorImpl using a static list of live servers
- *
- * @param transportConfigs
- */
- public ServerLocatorImpl(final boolean useHA, final TransportConfiguration...
transportConfigs)
- {
- this(useHA, null, transportConfigs);
- }
-
- private TransportConfiguration selectConnector()
- {
- if (receivedTopology)
- {
- int pos = loadBalancingPolicy.select(topologyArray.length);
-
- Pair<TransportConfiguration, TransportConfiguration> pair =
topologyArray[pos];
-
- return pair.a;
- }
- else
- {
- // Get from initialconnectors
-
- int pos = loadBalancingPolicy.select(initialConnectors.length);
-
- return initialConnectors[pos];
- }
- }
-
- public void start(Executor executor) throws Exception
- {
- initialise();
-
- executor.execute(new Runnable()
- {
- public void run()
- {
- try
- {
- connect();
- }
- catch (Exception e)
- {
- if (!closing)
- {
- log.warn("did not connect the cluster connection to other
nodes", e);
- }
- }
- }
- });
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.api.core.client.ServerLocator#disableFinalizeCheck()
- */
- public void disableFinalizeCheck()
- {
- finalizeCheck = false;
- }
-
- public ClientSessionFactory connect() throws Exception
- {
- ClientSessionFactoryInternal sf;
- // static list of initial connectors
- if (initialConnectors != null && discoveryGroup == null)
- {
- sf = (ClientSessionFactoryInternal)staticConnector.connect();
- }
- // wait for discovery group to get the list of initial connectors
- else
- {
- sf = (ClientSessionFactoryInternal)createSessionFactory();
- }
- addFactory(sf);
- return sf;
- }
-
- public ClientSessionFactory createSessionFactory(final TransportConfiguration
transportConfiguration) throws Exception
- {
- if (closed)
- {
- throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
- }
-
- try
- {
- initialise();
- }
- catch (Exception e)
- {
- throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
- }
-
- ClientSessionFactoryInternal factory = new ClientSessionFactoryImpl(this,
-
transportConfiguration,
- callTimeout,
-
clientFailureCheckPeriod,
- connectionTTL,
- retryInterval,
-
retryIntervalMultiplier,
-
maxRetryInterval,
-
reconnectAttempts,
- threadPool,
-
scheduledThreadPool,
- interceptors);
-
- factory.connect(reconnectAttempts, failoverOnInitialConnection);
-
- addFactory(factory);
-
- return factory;
- }
-
- public ClientSessionFactory createSessionFactory() throws Exception
- {
- if (closed)
- {
- throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
- }
-
- try
- {
- initialise();
- }
- catch (Exception e)
- {
- throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
- }
-
- if (initialConnectors == null && discoveryGroup != null)
- {
- // Wait for an initial broadcast to give us at least one node in the cluster
- long timeout = clusterConnection ? 0 :
discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout();
- boolean ok = discoveryGroup.waitForBroadcast(timeout);
-
- if (!ok)
- {
- throw new HornetQException(HornetQException.CONNECTION_TIMEDOUT,
- "Timed out waiting to receive initial
broadcast from cluster");
- }
- }
-
- ClientSessionFactoryInternal factory = null;
-
- synchronized (this)
- {
- boolean retry;
- int attempts = 0;
- do
- {
- retry = false;
-
- TransportConfiguration tc = selectConnector();
-
- // try each factory in the list until we find one which works
-
- try
- {
- factory = new ClientSessionFactoryImpl(this,
- tc,
- callTimeout,
- clientFailureCheckPeriod,
- connectionTTL,
- retryInterval,
- retryIntervalMultiplier,
- maxRetryInterval,
- reconnectAttempts,
- threadPool,
- scheduledThreadPool,
- interceptors);
- factory.connect(initialConnectAttempts, failoverOnInitialConnection);
- }
- catch (HornetQException e)
- {
- factory.close();
- factory = null;
- if (e.getCode() == HornetQException.NOT_CONNECTED)
- {
- attempts++;
-
- if (topologyArray != null && attempts == topologyArray.length)
- {
- throw new HornetQException(HornetQException.NOT_CONNECTED,
- "Cannot connect to server(s). Tried
with all available servers.");
- }
- if (topologyArray == null && initialConnectors != null
&& attempts == initialConnectors.length)
- {
- throw new HornetQException(HornetQException.NOT_CONNECTED,
- "Cannot connect to server(s). Tried
with all available servers.");
- }
- retry = true;
- }
- else
- {
- throw e;
- }
- }
- }
- while (retry);
-
- if (ha)
- {
- long toWait = 30000;
- long start = System.currentTimeMillis();
- while (!receivedTopology && toWait > 0)
- {
- // Now wait for the topology
-
- try
- {
- wait(toWait);
- }
- catch (InterruptedException ignore)
- {
- }
-
- long now = System.currentTimeMillis();
-
- toWait -= now - start;
-
- start = now;
- }
-
- if (toWait <= 0)
- {
- throw new HornetQException(HornetQException.CONNECTION_TIMEDOUT,
- "Timed out waiting to receive cluster
topology");
- }
- }
-
- addFactory(factory);
-
- return factory;
- }
- }
-
- public synchronized boolean isHA()
- {
- return ha;
- }
-
- public synchronized boolean isCacheLargeMessagesClient()
- {
- return cacheLargeMessagesClient;
- }
-
- public synchronized void setCacheLargeMessagesClient(final boolean cached)
- {
- cacheLargeMessagesClient = cached;
- }
-
- public synchronized long getClientFailureCheckPeriod()
- {
- return clientFailureCheckPeriod;
- }
-
- public synchronized void setClientFailureCheckPeriod(final long
clientFailureCheckPeriod)
- {
- checkWrite();
- this.clientFailureCheckPeriod = clientFailureCheckPeriod;
- }
-
- public synchronized long getConnectionTTL()
- {
- return connectionTTL;
- }
-
- public synchronized void setConnectionTTL(final long connectionTTL)
- {
- checkWrite();
- this.connectionTTL = connectionTTL;
- }
-
- public synchronized long getCallTimeout()
- {
- return callTimeout;
- }
-
- public synchronized void setCallTimeout(final long callTimeout)
- {
- checkWrite();
- this.callTimeout = callTimeout;
- }
-
- public synchronized int getMinLargeMessageSize()
- {
- return minLargeMessageSize;
- }
-
- public synchronized void setMinLargeMessageSize(final int minLargeMessageSize)
- {
- checkWrite();
- this.minLargeMessageSize = minLargeMessageSize;
- }
-
- public synchronized int getConsumerWindowSize()
- {
- return consumerWindowSize;
- }
-
- public synchronized void setConsumerWindowSize(final int consumerWindowSize)
- {
- checkWrite();
- this.consumerWindowSize = consumerWindowSize;
- }
-
- public synchronized int getConsumerMaxRate()
- {
- return consumerMaxRate;
- }
-
- public synchronized void setConsumerMaxRate(final int consumerMaxRate)
- {
- checkWrite();
- this.consumerMaxRate = consumerMaxRate;
- }
-
- public synchronized int getConfirmationWindowSize()
- {
- return confirmationWindowSize;
- }
-
- public synchronized void setConfirmationWindowSize(final int confirmationWindowSize)
- {
- checkWrite();
- this.confirmationWindowSize = confirmationWindowSize;
- }
-
- public synchronized int getProducerWindowSize()
- {
- return producerWindowSize;
- }
-
- public synchronized void setProducerWindowSize(final int producerWindowSize)
- {
- checkWrite();
- this.producerWindowSize = producerWindowSize;
- }
-
- public synchronized int getProducerMaxRate()
- {
- return producerMaxRate;
- }
-
- public synchronized void setProducerMaxRate(final int producerMaxRate)
- {
- checkWrite();
- this.producerMaxRate = producerMaxRate;
- }
-
- public synchronized boolean isBlockOnAcknowledge()
- {
- return blockOnAcknowledge;
- }
-
- public synchronized void setBlockOnAcknowledge(final boolean blockOnAcknowledge)
- {
- checkWrite();
- this.blockOnAcknowledge = blockOnAcknowledge;
- }
-
- public synchronized boolean isBlockOnDurableSend()
- {
- return blockOnDurableSend;
- }
-
- public synchronized void setBlockOnDurableSend(final boolean blockOnDurableSend)
- {
- checkWrite();
- this.blockOnDurableSend = blockOnDurableSend;
- }
-
- public synchronized boolean isBlockOnNonDurableSend()
- {
- return blockOnNonDurableSend;
- }
-
- public synchronized void setBlockOnNonDurableSend(final boolean
blockOnNonDurableSend)
- {
- checkWrite();
- this.blockOnNonDurableSend = blockOnNonDurableSend;
- }
-
- public synchronized boolean isAutoGroup()
- {
- return autoGroup;
- }
-
- public synchronized void setAutoGroup(final boolean autoGroup)
- {
- checkWrite();
- this.autoGroup = autoGroup;
- }
-
- public synchronized boolean isPreAcknowledge()
- {
- return preAcknowledge;
- }
-
- public synchronized void setPreAcknowledge(final boolean preAcknowledge)
- {
- checkWrite();
- this.preAcknowledge = preAcknowledge;
- }
-
- public synchronized int getAckBatchSize()
- {
- return ackBatchSize;
- }
-
- public synchronized void setAckBatchSize(final int ackBatchSize)
- {
- checkWrite();
- this.ackBatchSize = ackBatchSize;
- }
-
- public synchronized boolean isUseGlobalPools()
- {
- return useGlobalPools;
- }
-
- public synchronized void setUseGlobalPools(final boolean useGlobalPools)
- {
- checkWrite();
- this.useGlobalPools = useGlobalPools;
- }
-
- public synchronized int getScheduledThreadPoolMaxSize()
- {
- return scheduledThreadPoolMaxSize;
- }
-
- public synchronized void setScheduledThreadPoolMaxSize(final int
scheduledThreadPoolMaxSize)
- {
- checkWrite();
- this.scheduledThreadPoolMaxSize = scheduledThreadPoolMaxSize;
- }
-
- public synchronized int getThreadPoolMaxSize()
- {
- return threadPoolMaxSize;
- }
-
- public synchronized void setThreadPoolMaxSize(final int threadPoolMaxSize)
- {
- checkWrite();
- this.threadPoolMaxSize = threadPoolMaxSize;
- }
-
- public synchronized long getRetryInterval()
- {
- return retryInterval;
- }
-
- public synchronized void setRetryInterval(final long retryInterval)
- {
- checkWrite();
- this.retryInterval = retryInterval;
- }
-
- public synchronized long getMaxRetryInterval()
- {
- return maxRetryInterval;
- }
-
- public synchronized void setMaxRetryInterval(final long retryInterval)
- {
- checkWrite();
- maxRetryInterval = retryInterval;
- }
-
- public synchronized double getRetryIntervalMultiplier()
- {
- return retryIntervalMultiplier;
- }
-
- public synchronized void setRetryIntervalMultiplier(final double
retryIntervalMultiplier)
- {
- checkWrite();
- this.retryIntervalMultiplier = retryIntervalMultiplier;
- }
-
- public synchronized int getReconnectAttempts()
- {
- return reconnectAttempts;
- }
-
- public synchronized void setReconnectAttempts(final int reconnectAttempts)
- {
- checkWrite();
- this.reconnectAttempts = reconnectAttempts;
- }
-
- public void setInitialConnectAttempts(int initialConnectAttempts)
- {
- checkWrite();
- this.initialConnectAttempts = initialConnectAttempts;
- }
-
- public int getInitialConnectAttempts()
- {
- return initialConnectAttempts;
- }
-
- public synchronized boolean isFailoverOnInitialConnection()
- {
- return this.failoverOnInitialConnection;
- }
-
- public synchronized void setFailoverOnInitialConnection(final boolean failover)
- {
- checkWrite();
- this.failoverOnInitialConnection = failover;
- }
-
- public synchronized String getConnectionLoadBalancingPolicyClassName()
- {
- return connectionLoadBalancingPolicyClassName;
- }
-
- public synchronized void setConnectionLoadBalancingPolicyClassName(final String
loadBalancingPolicyClassName)
- {
- checkWrite();
- connectionLoadBalancingPolicyClassName = loadBalancingPolicyClassName;
- }
-
- public TransportConfiguration[] getStaticTransportConfigurations()
- {
- return this.initialConnectors;
- }
-
- public DiscoveryGroupConfiguration getDiscoveryGroupConfiguration()
- {
- return discoveryGroupConfiguration;
- }
-
- public void addInterceptor(final Interceptor interceptor)
- {
- interceptors.add(interceptor);
- }
-
- public boolean removeInterceptor(final Interceptor interceptor)
- {
- return interceptors.remove(interceptor);
- }
-
- public synchronized int getInitialMessagePacketSize()
- {
- return initialMessagePacketSize;
- }
-
- public synchronized void setInitialMessagePacketSize(final int size)
- {
- checkWrite();
- initialMessagePacketSize = size;
- }
-
- public void setGroupID(final String groupID)
- {
- checkWrite();
- this.groupID = groupID;
- }
-
- public String getGroupID()
- {
- return groupID;
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.api.core.client.ServerLocator#isCompressLargeMessage()
- */
- public boolean isCompressLargeMessage()
- {
- return compressLargeMessage;
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.api.core.client.ServerLocator#setCompressLargeMessage(boolean)
- */
- public void setCompressLargeMessage(boolean compress)
- {
- this.compressLargeMessage = compress;
- }
-
- private void checkWrite()
- {
- if (readOnly)
- {
- throw new IllegalStateException("Cannot set attribute on SessionFactory
after it has been used");
- }
- }
-
- public void setNodeID(String nodeID)
- {
- this.nodeID = nodeID;
- }
-
- public String getNodeID()
- {
- return nodeID;
- }
-
- public void setClusterConnection(boolean clusterConnection)
- {
- this.clusterConnection = clusterConnection;
- }
-
- public boolean isClusterConnection()
- {
- return clusterConnection;
- }
-
- public TransportConfiguration getClusterTransportConfiguration()
- {
- return clusterTransportConfiguration;
- }
-
- public void setClusterTransportConfiguration(TransportConfiguration tc)
- {
- this.clusterTransportConfiguration = tc;
- }
-
- public boolean isBackup()
- {
- return backup;
- }
-
- public void setBackup(boolean backup)
- {
- this.backup = backup;
- }
-
- @Override
- protected void finalize() throws Throwable
- {
- if (finalizeCheck)
- {
- close();
- }
-
- super.finalize();
- }
-
- public void close()
- {
- if (closed)
- {
- return;
- }
-
- closing = true;
-
- if (discoveryGroup != null)
- {
- try
- {
- discoveryGroup.stop();
- }
- catch (Exception e)
- {
- log.error("Failed to stop discovery group", e);
- }
- }
- else
- {
- staticConnector.disconnect();
- }
-
- for (ClientSessionFactory factory : factories)
- {
- factory.close();
- }
-
- factories.clear();
-
- if (!useGlobalPools)
- {
- if (threadPool != null)
- {
- threadPool.shutdown();
-
- try
- {
- if (!threadPool.awaitTermination(10000, TimeUnit.MILLISECONDS))
- {
- log.warn("Timed out waiting for pool to terminate");
- }
- }
- catch (InterruptedException ignore)
- {
- }
- }
-
- if (scheduledThreadPool != null)
- {
- scheduledThreadPool.shutdown();
-
- try
- {
- if (!scheduledThreadPool.awaitTermination(10000, TimeUnit.MILLISECONDS))
- {
- log.warn("Timed out waiting for scheduled pool to
terminate");
- }
- }
- catch (InterruptedException ignore)
- {
- }
- }
- }
- readOnly = false;
-
- closed = true;
- }
-
- public synchronized void notifyNodeDown(final String nodeID)
- {
- boolean removed = false;
-
- if (!ha)
- {
- return;
- }
-
- removed = topology.removeMember(nodeID);
-
- if (!topology.isEmpty())
- {
- updateArraysAndPairs();
-
- if (topology.nodes() == 1 && topology.getMember(this.nodeID) != null)
- {
- receivedTopology = false;
- }
- }
- else
- {
- topologyArray = null;
-
- receivedTopology = false;
- }
-
- if (removed)
- {
- for (ClusterTopologyListener listener : topologyListeners)
- {
- listener.nodeDown(nodeID);
- }
- }
- }
-
- public synchronized void notifyNodeUp(final String nodeID,
- final Pair<TransportConfiguration,
TransportConfiguration> connectorPair,
- final boolean last)
- {
- if (!ha)
- {
- return;
- }
-
- topology.addMember(nodeID, new TopologyMember(connectorPair));
-
- TopologyMember actMember = topology.getMember(nodeID);
-
- if (actMember.getConnector().a != null && actMember.getConnector().b !=
null)
- {
- for (ClientSessionFactory factory : factories)
- {
-
((ClientSessionFactoryInternal)factory).setBackupConnector(actMember.getConnector().a,
-
actMember.getConnector().b);
- }
- }
-
- if (connectorPair.a != null)
- {
- updateArraysAndPairs();
- }
-
- if (last)
- {
- receivedTopology = true;
- }
-
- for (ClusterTopologyListener listener : topologyListeners)
- {
- listener.nodeUP(nodeID, connectorPair, last);
- }
-
- // Notify if waiting on getting topology
- notify();
- }
-
- private void updateArraysAndPairs()
- {
- topologyArray = (Pair<TransportConfiguration,
TransportConfiguration>[])Array.newInstance(Pair.class,
-
topology.members());
-
- int count = 0;
- for (TopologyMember pair : topology.getMembers())
- {
- topologyArray[count++] = pair.getConnector();
- }
- }
-
- public synchronized void connectorsChanged()
- {
- List<DiscoveryEntry> newConnectors = discoveryGroup.getDiscoveryEntries();
-
- this.initialConnectors =
(TransportConfiguration[])Array.newInstance(TransportConfiguration.class,
-
newConnectors.size());
-
- int count = 0;
- for (DiscoveryEntry entry : newConnectors)
- {
- this.initialConnectors[count++] = entry.getConnector();
- }
-
- if (ha && clusterConnection && !receivedTopology &&
initialConnectors.length > 0)
- {
- // FIXME the node is alone in the cluster. We create a connection to the new
node
- // to trigger the node notification to form the cluster.
- try
- {
- connect();
- }
- catch (Exception e)
- {
- e.printStackTrace(); // To change body of catch statement use File | Settings
| File Templates.
- }
- }
- }
-
- public synchronized void factoryClosed(final ClientSessionFactory factory)
- {
- factories.remove(factory);
-
- if (factories.isEmpty())
- {
- // Go back to using the broadcast or static list
-
- receivedTopology = false;
-
- topology = null;
-
- }
- }
-
- public Topology getTopology()
- {
- return topology;
- }
-
- public void addClusterTopologyListener(final ClusterTopologyListener listener)
- {
- topologyListeners.add(listener);
- if(topology.members() > 0)
- {
- log.debug("ServerLocatorImpl.addClusterTopologyListener");
- }
- }
-
- public void removeClusterTopologyListener(final ClusterTopologyListener listener)
- {
- topologyListeners.remove(listener);
- }
-
- public synchronized void addFactory(ClientSessionFactoryInternal factory)
- {
- if (factory != null)
- {
- TransportConfiguration backup =
topology.getBackupForConnector(factory.getConnectorConfiguration());
- factory.setBackupConnector(factory.getConnectorConfiguration(), backup);
- factories.add(factory);
- }
- }
-
- public static void shutdown()
- {
- if (globalScheduledThreadPool != null)
- {
- globalScheduledThreadPool.shutdown();
- globalScheduledThreadPool = null;
- }
- if (globalThreadPool != null)
- {
- globalThreadPool.shutdown();
- globalThreadPool = null;
- }
- }
-
- class StaticConnector implements Serializable
- {
- private List<Connector> connectors;
-
- public ClientSessionFactory connect() throws HornetQException
- {
- if (closed)
- {
- throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
- }
-
- try
- {
- initialise();
- }
- catch (Exception e)
- {
- throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
- }
-
- ClientSessionFactory csf = null;
-
- createConnectors();
-
- try
- {
-
- List<Future<ClientSessionFactory>> futuresList = new
ArrayList<Future<ClientSessionFactory>>();
-
- for (Connector conn : connectors)
- {
- futuresList.add(threadPool.submit(conn));
- }
-
- for (int i = 0, futuresSize = futuresList.size(); i < futuresSize; i++)
- {
- Future<ClientSessionFactory> future = futuresList.get(i);
- try
- {
- csf = future.get();
- if (csf != null)
- break;
- }
- catch (Exception e)
- {
- log.debug("unable to connect with static connector " +
connectors.get(i).initialConnector);
- }
- }
- if (csf == null && !closed)
- {
- throw new HornetQException(HornetQException.NOT_CONNECTED, "Failed to
connect to any static connectors");
- }
- }
- catch (Exception e)
- {
- throw new HornetQException(HornetQException.NOT_CONNECTED, "Failed to
connect to any static connectors", e);
- }
-
- if (csf == null && !closed)
- {
- throw new HornetQException(HornetQException.NOT_CONNECTED, "Failed to
connect to any static connectors");
- }
- return csf;
- }
-
- private synchronized void createConnectors()
- {
- connectors = new ArrayList<Connector>();
- for (TransportConfiguration initialConnector : initialConnectors)
- {
- ClientSessionFactoryInternal factory = new
ClientSessionFactoryImpl(ServerLocatorImpl.this,
-
initialConnector,
-
callTimeout,
-
clientFailureCheckPeriod,
-
connectionTTL,
-
retryInterval,
-
retryIntervalMultiplier,
-
maxRetryInterval,
-
reconnectAttempts,
-
threadPool,
-
scheduledThreadPool,
-
interceptors);
- connectors.add(new Connector(initialConnector, factory));
- }
- }
-
- public synchronized void disconnect()
- {
- if (connectors != null)
- {
- for (Connector connector : connectors)
- {
- connector.disconnect();
- }
- }
- }
-
- public void finalize() throws Throwable
- {
- if (!closed && finalizeCheck)
- {
- log.warn("I'm closing a core ServerLocator you left open. Please
make sure you close all ServerLocators explicitly " + "before letting them go
out of scope! " +
- System.identityHashCode(this));
-
- log.warn("The ServerLocator you didn't close was created
here:", e);
-
- if (ServerLocatorImpl.finalizeCallback != null)
- {
- ServerLocatorImpl.finalizeCallback.run();
- }
-
- close();
- }
-
- super.finalize();
- }
-
- class Connector implements Callable<ClientSessionFactory>
- {
- private TransportConfiguration initialConnector;
-
- private volatile ClientSessionFactoryInternal factory;
-
- private boolean isConnected = false;
-
- private boolean interrupted = false;
-
- private Exception e;
-
- public Connector(TransportConfiguration initialConnector,
ClientSessionFactoryInternal factory)
- {
- this.initialConnector = initialConnector;
- this.factory = factory;
- }
-
- public ClientSessionFactory call() throws HornetQException
- {
- try
- {
- factory.connect(reconnectAttempts, failoverOnInitialConnection);
- }
- catch (HornetQException e)
- {
- if (!interrupted)
- {
- this.e = e;
- throw e;
- }
- /*if(factory != null)
- {
- factory.close();
- factory = null;
- }*/
- return null;
- }
- isConnected = true;
- for (Connector connector : connectors)
- {
- if (!connector.isConnected())
- {
- connector.disconnect();
- }
- }
- return factory;
- }
-
- public boolean isConnected()
- {
- return isConnected;
- }
-
- public void disconnect()
- {
- interrupted = true;
-
- if (factory != null)
- {
- factory.causeExit();
- factory.close();
- factory = null;
- }
- }
- }
- }
-}
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorInternal.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorInternal.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorInternal.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -56,4 +56,6 @@
void setBackup(boolean backup);
Topology getTopology();
+
+ boolean isStaticDirectConnection(TransportConfiguration con);
}
Added:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/SimpleUDPServerLocatorImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/SimpleUDPServerLocatorImpl.java
(rev 0)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/SimpleUDPServerLocatorImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,357 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.core.client.impl;
+
+import java.lang.reflect.Array;
+import java.net.InetAddress;
+import java.util.*;
+import java.util.concurrent.*;
+
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
+import org.hornetq.api.core.HornetQException;
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.HornetQClient;
+import org.hornetq.core.cluster.DiscoveryEntry;
+import org.hornetq.core.cluster.DiscoveryGroup;
+import org.hornetq.core.cluster.DiscoveryListener;
+import org.hornetq.core.cluster.impl.DiscoveryGroupImpl;
+import org.hornetq.core.config.impl.ConfigurationImpl;
+import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.ConfigurationHelper;
+
+/**
+ * A SimpleUDPServerLocatorImpl
+ *
+ * @author Tim Fox
+ * @author <a href="tm.igarashi(a)gmail.com">Tomohisa Igarashi</a>
+ */
+public class SimpleUDPServerLocatorImpl extends AbstractServerLocator implements
DiscoveryListener
+{
+ private static final long serialVersionUID = -1615857864410205260L;
+
+ private static final Logger log = Logger.getLogger(SimpleUDPServerLocatorImpl.class);
+
+ private String discoveryGroupName;
+
+ private InetAddress localBindAddress;
+
+ private InetAddress groupAddress;
+
+ private int groupPort;
+
+ private long refreshTimeout;
+
+ private long initialWaitTimeout;
+
+ private DiscoveryGroup discoveryGroup;
+
+ private volatile boolean closing;
+
+ // To be called when there are ServerLocator being finalized.
+ // To be used on test assertions
+ public static Runnable finalizeCallback = null;
+
+ private synchronized void initialise() throws Exception
+ {
+ if (!isReadOnly())
+ {
+ setThreadPools();
+
+ instantiateLoadBalancingPolicy();
+
+ this.discoveryGroupName = getDiscoveryGroupConfiguration().getName();
+
+ Map<String,Object> params = getDiscoveryGroupConfiguration().getParams();
+
+ String lbStr =
ConfigurationHelper.getStringProperty(DiscoveryGroupConstants.LOCAL_BIND_ADDRESS_NAME,
null, params);
+
+ if (lbStr != null)
+ {
+ this.localBindAddress = InetAddress.getByName(lbStr);
+ }
+ else
+ {
+ this.localBindAddress = null;
+ }
+
+ String gaddr =
ConfigurationHelper.getStringProperty(DiscoveryGroupConstants.GROUP_ADDRESS_NAME, null,
params);
+ if(gaddr != null)
+ {
+ this.groupAddress = InetAddress.getByName(gaddr);
+ }
+ this.groupPort =
ConfigurationHelper.getIntProperty(DiscoveryGroupConstants.GROUP_PORT_NAME, -1, params);
+ this.refreshTimeout =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME,
ConfigurationImpl.DEFAULT_BROADCAST_REFRESH_TIMEOUT, params);
+ this.initialWaitTimeout =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME,
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, params);
+
+ discoveryGroup = new DiscoveryGroupImpl(getNodeID(),
+ this.discoveryGroupName,
+ this.localBindAddress,
+ this.groupAddress,
+ this.groupPort,
+ this.refreshTimeout);
+
+ discoveryGroup.registerListener(this);
+
+ discoveryGroup.start();
+
+ setReadOnly(true);
+ }
+ }
+
+ public SimpleUDPServerLocatorImpl(final boolean useHA,
+ final DiscoveryGroupConfiguration
discoveryGroupConfiguration)
+ {
+ super(useHA, discoveryGroupConfiguration);
+ }
+
+ public void start(Executor executor) throws Exception
+ {
+ initialise();
+
+ executor.execute(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ connect();
+ }
+ catch (Exception e)
+ {
+ if (!closing)
+ {
+ log.warn("did not connect the cluster connection to other
nodes", e);
+ }
+ }
+ }
+ });
+ }
+
+ public ClientSessionFactory connect() throws Exception
+ {
+ ClientSessionFactoryInternal sf;
+
+ // wait for discovery group to get the list of initial connectors
+ sf = (ClientSessionFactoryInternal)createSessionFactory();
+
+ addFactory(sf);
+ return sf;
+ }
+
+ public ClientSessionFactory createSessionFactory(final TransportConfiguration
transportConfiguration) throws Exception
+ {
+ if (isClosed())
+ {
+ throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
+ }
+
+ try
+ {
+ initialise();
+ }
+ catch (Exception e)
+ {
+ throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
+ }
+
+ ClientSessionFactoryInternal factory = new ClientSessionFactoryImpl(this,
+
transportConfiguration,
+
getCallTimeout(),
+
getClientFailureCheckPeriod(),
+
getConnectionTTL(),
+
getRetryInterval(),
+
getRetryIntervalMultiplier(),
+
getMaxRetryInterval(),
+
getReconnectAttempts(),
+
getThreadPool(),
+
getScheduledThreadPool(),
+
getInterceptors());
+
+ factory.connect(getReconnectAttempts(), isFailoverOnInitialConnection());
+
+ addFactory(factory);
+
+ return factory;
+ }
+
+ public ClientSessionFactory createSessionFactory() throws Exception
+ {
+ if (isClosed())
+ {
+ throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
+ }
+
+ try
+ {
+ initialise();
+ }
+ catch (Exception e)
+ {
+ throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
+ }
+
+ if (getInitialConnectors() == null)
+ {
+ // Wait for an initial broadcast to give us at least one node in the cluster
+ long timeout = isClusterConnection() ? 0 : this.initialWaitTimeout;
+ boolean ok = discoveryGroup.waitForBroadcast(timeout);
+
+ if (!ok)
+ {
+ throw new HornetQException(HornetQException.CONNECTION_TIMEDOUT,
+ "Timed out waiting to receive initial
broadcast from cluster");
+ }
+ }
+
+ ClientSessionFactoryInternal factory = null;
+
+ synchronized (this)
+ {
+ boolean retry;
+ int attempts = 0;
+ do
+ {
+ retry = false;
+
+ TransportConfiguration tc = selectConnector();
+
+ // try each factory in the list until we find one which works
+
+ try
+ {
+ factory = new ClientSessionFactoryImpl(this,
+ tc,
+ getCallTimeout(),
+ getClientFailureCheckPeriod(),
+ getConnectionTTL(),
+ getRetryInterval(),
+ getRetryIntervalMultiplier(),
+ getMaxRetryInterval(),
+ getReconnectAttempts(),
+ getThreadPool(),
+ getScheduledThreadPool(),
+ getInterceptors());
+ factory.connect(getInitialConnectAttempts(),
isFailoverOnInitialConnection());
+ }
+ catch (HornetQException e)
+ {
+ factory.close();
+ factory = null;
+ if (e.getCode() == HornetQException.NOT_CONNECTED)
+ {
+ attempts++;
+
+ if (attempts == getConnectorLength())
+ {
+ throw new HornetQException(HornetQException.NOT_CONNECTED,
+ "Cannot connect to server(s). Tried
with all available servers.");
+ }
+ retry = true;
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+ while (retry);
+
+ if (isHA())
+ {
+ long toWait = 30000;
+ long start = System.currentTimeMillis();
+ while (!isReceivedTopology() && toWait > 0)
+ {
+ // Now wait for the topology
+
+ try
+ {
+ wait(toWait);
+ }
+ catch (InterruptedException ignore)
+ {
+ }
+
+ long now = System.currentTimeMillis();
+
+ toWait -= now - start;
+
+ start = now;
+ }
+
+ if (toWait <= 0)
+ {
+ throw new HornetQException(HornetQException.CONNECTION_TIMEDOUT,
+ "Timed out waiting to receive cluster
topology");
+ }
+ }
+
+ addFactory(factory);
+
+ return factory;
+ }
+ }
+
+ public void close()
+ {
+ if (isClosed())
+ {
+ return;
+ }
+
+ closing = true;
+
+ try
+ {
+ discoveryGroup.stop();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to stop discovery group", e);
+ }
+
+ super.close();
+ }
+
+ public synchronized void connectorsChanged()
+ {
+ List<DiscoveryEntry> newConnectors = discoveryGroup.getDiscoveryEntries();
+
+ TransportConfiguration[] initialConnectors =
(TransportConfiguration[])Array.newInstance(TransportConfiguration.class,
+
newConnectors.size());
+ int count = 0;
+ for (DiscoveryEntry entry : newConnectors)
+ {
+ initialConnectors[count++] = entry.getConnector();
+ }
+
+ if (isHA() && isClusterConnection() && !isReceivedTopology()
&& initialConnectors.length > 0)
+ {
+ // FIXME the node is alone in the cluster. We create a connection to the new
node
+ // to trigger the node notification to form the cluster.
+ try
+ {
+ connect();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); // To change body of catch statement use File | Settings
| File Templates.
+ }
+ }
+
+ setInitialConnectors(initialConnectors);
+ }
+}
Added:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/StaticServerLocatorImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/StaticServerLocatorImpl.java
(rev 0)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/client/impl/StaticServerLocatorImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,457 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.core.client.impl;
+
+import java.io.Serializable;
+import java.util.*;
+import java.util.concurrent.*;
+
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
+import org.hornetq.api.core.HornetQException;
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.ConfigurationHelper;
+
+/**
+ * A SimpleUDPServerLocatorImpl
+ *
+ * @author Tim Fox
+ * @author <a href="tm.igarashi(a)gmail.com">Tomohisa Igarashi</a>
+ */
+public class StaticServerLocatorImpl extends AbstractServerLocator
+{
+ private static final long serialVersionUID = -1615857864410205260L;
+
+ private static final Logger log = Logger.getLogger(StaticServerLocatorImpl.class);
+
+ private StaticConnector staticConnector = new StaticConnector();
+
+ private volatile boolean closing;
+
+ private final Exception e = new Exception();
+
+ // To be called when there are ServerLocator being finalized.
+ // To be used on test assertions
+ public static Runnable finalizeCallback = null;
+
+ private synchronized void initialise() throws Exception
+ {
+ if (!isReadOnly())
+ {
+ setThreadPools();
+
+ instantiateLoadBalancingPolicy();
+
+ setReadOnly(true);
+ }
+ }
+
+ public StaticServerLocatorImpl(final boolean useHA,
+ final DiscoveryGroupConfiguration
discoveryGroupConfiguration)
+ {
+ super(useHA, discoveryGroupConfiguration);
+
+ Map<String,Object> params = discoveryGroupConfiguration.getParams();
+ List<TransportConfiguration> initialConnectors =
(List<TransportConfiguration>)params.get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME);
+ setInitialConnectors(initialConnectors.toArray(new TransportConfiguration[0]));
+
+ e.fillInStackTrace();
+ }
+
+ public void start(Executor executor) throws Exception
+ {
+ initialise();
+
+ executor.execute(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ connect();
+ }
+ catch (Exception e)
+ {
+ if (!closing)
+ {
+ log.warn("did not connect the cluster connection to other
nodes", e);
+ }
+ }
+ }
+ });
+ }
+
+ public ClientSessionFactory connect() throws Exception
+ {
+ ClientSessionFactoryInternal sf;
+
+ sf = (ClientSessionFactoryInternal)staticConnector.connect();
+
+ addFactory(sf);
+ return sf;
+ }
+
+ public ClientSessionFactory createSessionFactory(final TransportConfiguration
transportConfiguration) throws Exception
+ {
+ if (isClosed())
+ {
+ throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
+ }
+
+ try
+ {
+ initialise();
+ }
+ catch (Exception e)
+ {
+ throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
+ }
+
+ ClientSessionFactoryInternal factory = new ClientSessionFactoryImpl(this,
+
transportConfiguration,
+
getCallTimeout(),
+
getClientFailureCheckPeriod(),
+
getConnectionTTL(),
+
getRetryInterval(),
+
getRetryIntervalMultiplier(),
+
getMaxRetryInterval(),
+
getReconnectAttempts(),
+
getThreadPool(),
+
getScheduledThreadPool(),
+
getInterceptors());
+
+ factory.connect(getReconnectAttempts(), isFailoverOnInitialConnection());
+
+ addFactory(factory);
+
+ return factory;
+ }
+
+ public ClientSessionFactory createSessionFactory() throws Exception
+ {
+ if (isClosed())
+ {
+ throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
+ }
+
+ try
+ {
+ initialise();
+ }
+ catch (Exception e)
+ {
+ throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
+ }
+
+ ClientSessionFactoryInternal factory = null;
+
+ synchronized (this)
+ {
+ boolean retry;
+ int attempts = 0;
+ do
+ {
+ retry = false;
+
+ TransportConfiguration tc = selectConnector();
+
+ // try each factory in the list until we find one which works
+
+ try
+ {
+ factory = new ClientSessionFactoryImpl(this,
+ tc,
+ getCallTimeout(),
+ getClientFailureCheckPeriod(),
+ getConnectionTTL(),
+ getRetryInterval(),
+ getRetryIntervalMultiplier(),
+ getMaxRetryInterval(),
+ getReconnectAttempts(),
+ getThreadPool(),
+ getScheduledThreadPool(),
+ getInterceptors());
+ factory.connect(getInitialConnectAttempts(),
isFailoverOnInitialConnection());
+ }
+ catch (HornetQException e)
+ {
+ factory.close();
+ factory = null;
+ if (e.getCode() == HornetQException.NOT_CONNECTED)
+ {
+ attempts++;
+
+ if (attempts == getConnectorLength())
+ {
+ throw new HornetQException(HornetQException.NOT_CONNECTED,
+ "Cannot connect to server(s). Tried
with all available servers.");
+ }
+ retry = true;
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+ while (retry);
+
+ if (isHA())
+ {
+ long toWait = 30000;
+ long start = System.currentTimeMillis();
+ while (!isReceivedTopology() && toWait > 0)
+ {
+ // Now wait for the topology
+
+ try
+ {
+ wait(toWait);
+ }
+ catch (InterruptedException ignore)
+ {
+ }
+
+ long now = System.currentTimeMillis();
+
+ toWait -= now - start;
+
+ start = now;
+ }
+
+ if (toWait <= 0)
+ {
+ throw new HornetQException(HornetQException.CONNECTION_TIMEDOUT,
+ "Timed out waiting to receive cluster
topology");
+ }
+ }
+
+ addFactory(factory);
+
+ return factory;
+ }
+ }
+
+ public void close()
+ {
+ if (isClosed())
+ {
+ return;
+ }
+
+ closing = true;
+
+ staticConnector.disconnect();
+
+ super.close();
+ }
+
+ public boolean isStaticDirectConnection(TransportConfiguration con)
+ {
+ for(TransportConfiguration connector : getInitialConnectors())
+ {
+ if(connector.equals(con))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ class StaticConnector implements Serializable
+ {
+ private List<Connector> connectors;
+
+ public ClientSessionFactory connect() throws HornetQException
+ {
+ if (isClosed())
+ {
+ throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
+ }
+
+ try
+ {
+ initialise();
+ }
+ catch (Exception e)
+ {
+ throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
+ }
+
+ ClientSessionFactory csf = null;
+
+ createConnectors();
+
+ try
+ {
+ List<Future<ClientSessionFactory>> futuresList = new
ArrayList<Future<ClientSessionFactory>>();
+
+ for (Connector conn : connectors)
+ {
+ futuresList.add(getThreadPool().submit(conn));
+ }
+
+ for (int i = 0, futuresSize = futuresList.size(); i < futuresSize; i++)
+ {
+ Future<ClientSessionFactory> future = futuresList.get(i);
+ try
+ {
+ csf = future.get();
+ if (csf != null)
+ break;
+ }
+ catch (Exception e)
+ {
+ log.debug("unable to connect with static connector " +
connectors.get(i).initialConnector);
+ }
+ }
+ if (csf == null && !isClosed())
+ {
+ throw new HornetQException(HornetQException.NOT_CONNECTED, "Failed to
connect to any static connectors");
+ }
+ }
+ catch (Exception e)
+ {
+ throw new HornetQException(HornetQException.NOT_CONNECTED, "Failed to
connect to any static connectors", e);
+ }
+
+ if (csf == null && !isClosed())
+ {
+ throw new HornetQException(HornetQException.NOT_CONNECTED, "Failed to
connect to any static connectors");
+ }
+ return csf;
+ }
+
+ private synchronized void createConnectors()
+ {
+ connectors = new ArrayList<Connector>();
+ for (TransportConfiguration initialConnector : getInitialConnectors())
+ {
+ ClientSessionFactoryInternal factory = new
ClientSessionFactoryImpl(StaticServerLocatorImpl.this,
+
initialConnector,
+
getCallTimeout(),
+
getClientFailureCheckPeriod(),
+
getConnectionTTL(),
+
getRetryInterval(),
+
getRetryIntervalMultiplier(),
+
getMaxRetryInterval(),
+
getReconnectAttempts(),
+
getThreadPool(),
+
getScheduledThreadPool(),
+
getInterceptors());
+ connectors.add(new Connector(initialConnector, factory));
+ }
+ }
+
+ public synchronized void disconnect()
+ {
+ if (connectors != null)
+ {
+ for (Connector connector : connectors)
+ {
+ connector.disconnect();
+ }
+ }
+ }
+
+ public void finalize() throws Throwable
+ {
+ if (!isClosed() && doFinalizeCheck())
+ {
+ log.warn("I'm closing a core ServerLocator you left open. Please
make sure you close all ServerLocators explicitly " + "before letting them go
out of scope! " +
+ System.identityHashCode(this));
+
+ log.warn("The ServerLocator you didn't close was created
here:", e);
+
+ if (StaticServerLocatorImpl.finalizeCallback != null)
+ {
+ StaticServerLocatorImpl.finalizeCallback.run();
+ }
+
+ close();
+ }
+
+ super.finalize();
+ }
+
+ class Connector implements Callable<ClientSessionFactory>
+ {
+ private TransportConfiguration initialConnector;
+
+ private volatile ClientSessionFactoryInternal factory;
+
+ private boolean isConnected = false;
+
+ private boolean interrupted = false;
+
+ private Exception e;
+
+ public Connector(TransportConfiguration initialConnector,
ClientSessionFactoryInternal factory)
+ {
+ this.initialConnector = initialConnector;
+ this.factory = factory;
+ }
+
+ public ClientSessionFactory call() throws HornetQException
+ {
+ try
+ {
+ factory.connect(getReconnectAttempts(), isFailoverOnInitialConnection());
+ }
+ catch (HornetQException e)
+ {
+ if (!interrupted)
+ {
+ this.e = e;
+ throw e;
+ }
+ /*if(factory != null)
+ {
+ factory.close();
+ factory = null;
+ }*/
+ return null;
+ }
+ isConnected = true;
+ for (Connector connector : connectors)
+ {
+ if (!connector.isConnected())
+ {
+ connector.disconnect();
+ }
+ }
+ return factory;
+ }
+
+ public boolean isConnected()
+ {
+ return isConnected;
+ }
+
+ public void disconnect()
+ {
+ interrupted = true;
+
+ if (factory != null)
+ {
+ factory.causeExit();
+ factory.close();
+ factory = null;
+ }
+ }
+ }
+ }
+}
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BridgeConfiguration.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BridgeConfiguration.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BridgeConfiguration.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -16,6 +16,8 @@
import java.io.Serializable;
import java.util.List;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
+
/**
* A BridgeConfiguration
*
@@ -37,9 +39,7 @@
private String filterString;
- private List<String> staticConnectors;
-
- private String discoveryGroupName;
+ private DiscoveryGroupConfiguration discoveryGroupConfiguration;
private boolean ha;
@@ -72,7 +72,7 @@
final boolean useDuplicateDetection,
final int confirmationWindowSize,
final long clientFailureCheckPeriod,
- final List<String> staticConnectors,
+ final DiscoveryGroupConfiguration
discoveryGroupConfiguration,
final boolean ha,
final String user,
final String password)
@@ -88,41 +88,7 @@
this.useDuplicateDetection = useDuplicateDetection;
this.confirmationWindowSize = confirmationWindowSize;
this.clientFailureCheckPeriod = clientFailureCheckPeriod;
- this.staticConnectors = staticConnectors;
- this.user = user;
- this.password = password;
- discoveryGroupName = null;
- }
-
- public BridgeConfiguration(final String name,
- final String queueName,
- final String forwardingAddress,
- final String filterString,
- final String transformerClassName,
- final long retryInterval,
- final double retryIntervalMultiplier,
- final int reconnectAttempts,
- final boolean useDuplicateDetection,
- final int confirmationWindowSize,
- final long clientFailureCheckPeriod,
- final String discoveryGroupName,
- final boolean ha,
- final String user,
- final String password)
- {
- this.name = name;
- this.queueName = queueName;
- this.forwardingAddress = forwardingAddress;
- this.filterString = filterString;
- this.transformerClassName = transformerClassName;
- this.retryInterval = retryInterval;
- this.retryIntervalMultiplier = retryIntervalMultiplier;
- this.reconnectAttempts = reconnectAttempts;
- this.useDuplicateDetection = useDuplicateDetection;
- this.confirmationWindowSize = confirmationWindowSize;
- this.clientFailureCheckPeriod = clientFailureCheckPeriod;
- this.staticConnectors = null;
- this.discoveryGroupName = discoveryGroupName;
+ this.discoveryGroupConfiguration = discoveryGroupConfiguration;
this.ha = ha;
this.user = user;
this.password = password;
@@ -153,16 +119,11 @@
return transformerClassName;
}
- public List<String> getStaticConnectors()
+ public DiscoveryGroupConfiguration getDiscoveryGroupConfiguration()
{
- return staticConnectors;
+ return discoveryGroupConfiguration;
}
- public String getDiscoveryGroupName()
- {
- return discoveryGroupName;
- }
-
public boolean isHA()
{
return ha;
@@ -231,20 +192,12 @@
}
/**
- * @param staticConnectors the staticConnectors to set
+ * @param discoveryGroupConfiguration the discoveryGroupConfiguration to set
*/
- public void setStaticConnectors(final List<String> staticConnectors)
+ public void setDiscoveryGroupConfiguration(final DiscoveryGroupConfiguration
discoveryGroupConfiguration)
{
- this.staticConnectors = staticConnectors;
+ this.discoveryGroupConfiguration = discoveryGroupConfiguration;
}
-
- /**
- * @param discoveryGroupName the discoveryGroupName to set
- */
- public void setDiscoveryGroupName(final String discoveryGroupName)
- {
- this.discoveryGroupName = discoveryGroupName;
- }
/**
*
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BroadcastGroupConfiguration.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BroadcastGroupConfiguration.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BroadcastGroupConfiguration.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -15,7 +15,9 @@
import java.io.Serializable;
import java.util.List;
+import java.util.Map;
+import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.core.logging.Logger;
/**
@@ -32,127 +34,43 @@
private static final Logger log =
Logger.getLogger(BroadcastGroupConfiguration.class);
+ private final String broadcastGroupClassName;
+
+ private final Map<String,Object> params;
+
private String name;
- private String localBindAddress;
-
- private int localBindPort;
-
- private String groupAddress;
-
- private int groupPort;
-
- private long broadcastPeriod;
-
- private List<String> connectorInfos;
-
- public BroadcastGroupConfiguration(final String name,
- final String localBindAddress,
- final int localBindPort,
- final String groupAddress,
- final int groupPort,
- final long broadcastPeriod,
- final List<String> connectorInfos)
+ private final List<TransportConfiguration> connectorList;
+
+ public BroadcastGroupConfiguration(final String clazz,
+ final Map<String,Object> params,
+ final String name,
+ final List<TransportConfiguration> connectorList)
{
super();
+ this.broadcastGroupClassName = clazz;
+ this.params = params;
this.name = name;
- this.localBindAddress = localBindAddress;
- this.localBindPort = localBindPort;
- this.groupAddress = groupAddress;
- this.groupPort = groupPort;
- this.broadcastPeriod = broadcastPeriod;
- this.connectorInfos = connectorInfos;
+ this.connectorList = connectorList;
}
- public String getName()
+ public String getBroadcastGroupClassName()
{
- return name;
+ return this.broadcastGroupClassName;
}
- public String getLocalBindAddress()
+ public Map<String, Object> getParams()
{
- return localBindAddress;
+ return this.params;
}
- public int getLocalBindPort()
+ public String getName()
{
- return localBindPort;
+ return name;
}
- public String getGroupAddress()
+ public List<TransportConfiguration> getConnectorList()
{
- return groupAddress;
+ return connectorList;
}
-
- public int getGroupPort()
- {
- return groupPort;
- }
-
- public long getBroadcastPeriod()
- {
- return broadcastPeriod;
- }
-
- public List<String> getConnectorInfos()
- {
- return connectorInfos;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(final String name)
- {
- this.name = name;
- }
-
- /**
- * @param localBindAddress the localBindAddress to set
- */
- public void setLocalBindAddress(final String localBindAddress)
- {
- this.localBindAddress = localBindAddress;
- }
-
- /**
- * @param localBindPort the localBindPort to set
- */
- public void setLocalBindPort(final int localBindPort)
- {
- this.localBindPort = localBindPort;
- }
-
- /**
- * @param groupAddress the groupAddress to set
- */
- public void setGroupAddress(final String groupAddress)
- {
- this.groupAddress = groupAddress;
- }
-
- /**
- * @param groupPort the groupPort to set
- */
- public void setGroupPort(final int groupPort)
- {
- this.groupPort = groupPort;
- }
-
- /**
- * @param broadcastPeriod the broadcastPeriod to set
- */
- public void setBroadcastPeriod(final long broadcastPeriod)
- {
- this.broadcastPeriod = broadcastPeriod;
- }
-
- /**
- * @param connectorInfos the connectorInfos to set
- */
- public void setConnectorInfos(final List<String> connectorInfos)
- {
- this.connectorInfos = connectorInfos;
- }
-
}
Added:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BroadcastGroupConstants.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BroadcastGroupConstants.java
(rev 0)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/BroadcastGroupConstants.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.core.config;
+
+/**
+ * A BroadcastGroupConstants
+ *
+ * @author "<a href=\"tm.igarashi(a)gmail.com\">Tomohisa
Igarashi</a>"
+ *
+ *
+ */
+public class BroadcastGroupConstants
+{
+ // for simple UDP broadcast
+ public static final String LOCAL_BIND_ADDRESS_NAME = "local-bind-address";
+ public static final String LOCAL_BIND_PORT_NAME = "local-bind-port";
+ public static final String GROUP_ADDRESS_NAME = "group-address";
+ public static final String GROUP_PORT_NAME = "group-port";
+ public static final String BROADCAST_PERIOD_NAME = "broadcast-period";
+}
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/ClusterConnectionConfiguration.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/ClusterConnectionConfiguration.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/config/ClusterConnectionConfiguration.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -16,6 +16,8 @@
import java.io.Serializable;
import java.util.List;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
+
/**
* A ClusterConnectionConfiguration
*
@@ -41,15 +43,13 @@
private final boolean forwardWhenNoConsumers;
- private final List<String> staticConnectors;
+ private final DiscoveryGroupConfiguration discoveryGroupConfiguration;
- private final String discoveryGroupName;
-
private final int maxHops;
private final int confirmationWindowSize;
- private final boolean allowDirectConnectionsOnly;
+ private final boolean allowableConnectionsOnly;
public ClusterConnectionConfiguration(final String name,
final String address,
@@ -59,45 +59,21 @@
final boolean forwardWhenNoConsumers,
final int maxHops,
final int confirmationWindowSize,
- final List<String> staticConnectors,
- final boolean allowDirectConnectionsOnly)
+ final DiscoveryGroupConfiguration
discoveryGroupConfiguration,
+ final boolean allowableConnectionsOnly)
{
this.name = name;
this.address = address;
this.connectorName = connectorName;
this.retryInterval = retryInterval;
- this.staticConnectors = staticConnectors;
this.duplicateDetection = duplicateDetection;
this.forwardWhenNoConsumers = forwardWhenNoConsumers;
- discoveryGroupName = null;
+ this.discoveryGroupConfiguration = discoveryGroupConfiguration;
this.maxHops = maxHops;
this.confirmationWindowSize = confirmationWindowSize;
- this.allowDirectConnectionsOnly = allowDirectConnectionsOnly;
+ this.allowableConnectionsOnly = allowableConnectionsOnly;
}
- public ClusterConnectionConfiguration(final String name,
- final String address,
- final String connectorName,
- final long retryInterval,
- final boolean duplicateDetection,
- final boolean forwardWhenNoConsumers,
- final int maxHops,
- final int confirmationWindowSize,
- final String discoveryGroupName)
- {
- this.name = name;
- this.address = address;
- this.connectorName = connectorName;
- this.retryInterval = retryInterval;
- this.duplicateDetection = duplicateDetection;
- this.forwardWhenNoConsumers = forwardWhenNoConsumers;
- this.discoveryGroupName = discoveryGroupName;
- this.staticConnectors = null;
- this.maxHops = maxHops;
- this.confirmationWindowSize = confirmationWindowSize;
- allowDirectConnectionsOnly = false;
- }
-
public String getName()
{
return name;
@@ -133,23 +109,18 @@
return confirmationWindowSize;
}
- public List<String> getStaticConnectors()
+ public DiscoveryGroupConfiguration getDiscoveryGroupConfiguration()
{
- return staticConnectors;
+ return discoveryGroupConfiguration;
}
- public String getDiscoveryGroupName()
- {
- return discoveryGroupName;
- }
-
public long getRetryInterval()
{
return retryInterval;
}
- public boolean isAllowDirectConnectionsOnly()
+ public boolean isAllowableConnectionsOnly()
{
- return allowDirectConnectionsOnly;
+ return allowableConnectionsOnly;
}
}
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/deployers/impl/FileConfigurationParser.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/deployers/impl/FileConfigurationParser.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/deployers/impl/FileConfigurationParser.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -22,8 +22,10 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.StringTokenizer;
import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
@@ -907,22 +909,11 @@
{
String name = e.getAttribute("name");
- String localAddress = XMLConfigurationUtil.getString(e,
"local-bind-address", null, Validators.NO_CHECK);
+ String clazz = XMLConfigurationUtil.getString(e, "broadcast-group-class",
null, Validators.NOT_NULL_OR_EMPTY);
- int localBindPort = XMLConfigurationUtil.getInteger(e, "local-bind-port",
-1, Validators.MINUS_ONE_OR_GT_ZERO);
-
- String groupAddress = XMLConfigurationUtil.getString(e, "group-address",
null, Validators.NOT_NULL_OR_EMPTY);
-
- int groupPort = XMLConfigurationUtil.getInteger(e, "group-port", -1,
Validators.GT_ZERO);
-
- long broadcastPeriod = XMLConfigurationUtil.getLong(e,
- "broadcast-period",
-
ConfigurationImpl.DEFAULT_BROADCAST_PERIOD,
- Validators.GT_ZERO);
-
NodeList children = e.getChildNodes();
- List<String> connectorNames = new ArrayList<String>();
+ List<TransportConfiguration> connectorList = new
ArrayList<TransportConfiguration>();
for (int j = 0; j < children.getLength(); j++)
{
@@ -935,18 +926,30 @@
null,
Validators.NOT_NULL_OR_EMPTY);
- connectorNames.add(connectorName);
+
connectorList.add(mainConfig.getConnectorConfigurations().get(connectorName));
}
}
- BroadcastGroupConfiguration config = new BroadcastGroupConfiguration(name,
- localAddress,
-
localBindPort,
- groupAddress,
- groupPort,
-
broadcastPeriod,
-
connectorNames);
+ Map<String, Object> params = new HashMap<String, Object>();
+ NodeList paramsNodes = e.getElementsByTagName("param");
+ for (int i = 0; i < paramsNodes.getLength(); i++)
+ {
+ Node paramNode = paramsNodes.item(i);
+
+ NamedNodeMap attributes = paramNode.getAttributes();
+
+ Node nkey = attributes.getNamedItem("key");
+
+ String key = nkey.getTextContent();
+
+ Node nValue = attributes.getNamedItem("value");
+
+ params.put(key, nValue.getTextContent());
+ }
+
+ BroadcastGroupConfiguration config = new BroadcastGroupConfiguration(clazz, params,
name, connectorList);
+
mainConfig.getBroadcastGroupConfigurations().add(config);
}
@@ -954,28 +957,42 @@
{
String name = e.getAttribute("name");
- String localBindAddress = XMLConfigurationUtil.getString(e,
"local-bind-address", null, Validators.NO_CHECK);
+ String clazz = XMLConfigurationUtil.getString(e, "server-locator-class",
null, Validators.NOT_NULL_OR_EMPTY);
- String groupAddress = XMLConfigurationUtil.getString(e, "group-address",
null, Validators.NOT_NULL_OR_EMPTY);
+ Map<String, Object> params = new HashMap<String, Object>();
- int groupPort = XMLConfigurationUtil.getInteger(e, "group-port", -1,
Validators.MINUS_ONE_OR_GT_ZERO);
+ NodeList paramsNodes = e.getElementsByTagName("param");
- long discoveryInitialWaitTimeout = XMLConfigurationUtil.getLong(e,
-
"initial-wait-timeout",
-
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
-
Validators.GT_ZERO);
+ for (int i = 0; i < paramsNodes.getLength(); i++)
+ {
+ Node paramNode = paramsNodes.item(i);
- long refreshTimeout = XMLConfigurationUtil.getLong(e,
- "refresh-timeout",
-
ConfigurationImpl.DEFAULT_BROADCAST_REFRESH_TIMEOUT,
- Validators.GT_ZERO);
+ NamedNodeMap attributes = paramNode.getAttributes();
- DiscoveryGroupConfiguration config = new DiscoveryGroupConfiguration(name,
-
localBindAddress,
- groupAddress,
- groupPort,
-
refreshTimeout,
-
discoveryInitialWaitTimeout);
+ Node nkey = attributes.getNamedItem("key");
+
+ String key = nkey.getTextContent();
+
+ Node nValue = attributes.getNamedItem("value");
+
+ params.put(key, nValue.getTextContent());
+ }
+
+ String connectorList =
(String)params.get(DiscoveryGroupConstants.STATIC_CONNECTORS_CONNECTOR_NAMES_NAME);
+ if(connectorList != null)
+ {
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ StringTokenizer token = new StringTokenizer(connectorList, ",", false);
+ while(token.hasMoreElements())
+ {
+
connectors.add(mainConfig.getConnectorConfigurations().get(token.nextElement()));
+ }
+ params.put(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME, connectors);
+ }
+
+ DiscoveryGroupConfiguration config = new DiscoveryGroupConfiguration(clazz, params,
name);
+
+
if (mainConfig.getDiscoveryGroupConfigurations().containsKey(name))
{
@@ -1023,8 +1040,6 @@
String discoveryGroupName = null;
- List<String> staticConnectorNames = new ArrayList<String>();
-
boolean allowDirectConnectionsOnly = false;
NodeList children = e.getChildNodes();
@@ -1036,45 +1051,29 @@
if (child.getNodeName().equals("discovery-group-ref"))
{
discoveryGroupName =
child.getAttributes().getNamedItem("discovery-group-name").getNodeValue();
- }
- else if (child.getNodeName().equals("static-connectors"))
- {
+
Node attr =
child.getAttributes().getNamedItem("allow-direct-connections-only");
if (attr != null)
{
allowDirectConnectionsOnly =
"true".equalsIgnoreCase(attr.getNodeValue()) || allowDirectConnectionsOnly;
}
- getStaticConnectors(staticConnectorNames, child);
}
}
+ DiscoveryGroupConfiguration discoveryGroupConfiguration =
mainConfig.getDiscoveryGroupConfigurations().get(discoveryGroupName);
+
ClusterConnectionConfiguration config;
- if (discoveryGroupName == null)
- {
- config = new ClusterConnectionConfiguration(name,
- address,
- connectorName,
- retryInterval,
- duplicateDetection,
- forwardWhenNoConsumers,
- maxHops,
- confirmationWindowSize,
- staticConnectorNames,
- allowDirectConnectionsOnly);
- }
- else
- {
- config = new ClusterConnectionConfiguration(name,
- address,
- connectorName,
- retryInterval,
- duplicateDetection,
- forwardWhenNoConsumers,
- maxHops,
- confirmationWindowSize,
- discoveryGroupName);
- }
+ config = new ClusterConnectionConfiguration(name,
+ address,
+ connectorName,
+ retryInterval,
+ duplicateDetection,
+ forwardWhenNoConsumers,
+ maxHops,
+ confirmationWindowSize,
+ discoveryGroupConfiguration,
+ allowDirectConnectionsOnly);
mainConfig.getClusterConfigurations().add(config);
}
@@ -1147,10 +1146,8 @@
String filterString = null;
- List<String> staticConnectorNames = new ArrayList<String>();
+ DiscoveryGroupConfiguration discoveryGroupConfiguration = null;
- String discoveryGroupName = null;
-
NodeList children = brNode.getChildNodes();
for (int j = 0; j < children.getLength(); j++)
@@ -1163,70 +1160,32 @@
}
else if (child.getNodeName().equals("discovery-group-ref"))
{
- discoveryGroupName =
child.getAttributes().getNamedItem("discovery-group-name").getNodeValue();
+ String discoveryGroupName =
child.getAttributes().getNamedItem("discovery-group-name").getNodeValue();
+ discoveryGroupConfiguration =
mainConfig.getDiscoveryGroupConfigurations().get(discoveryGroupName);
}
- else if (child.getNodeName().equals("static-connectors"))
- {
- getStaticConnectors(staticConnectorNames, child);
- }
}
BridgeConfiguration config;
- if (!staticConnectorNames.isEmpty())
- {
- config = new BridgeConfiguration(name,
- queueName,
- forwardingAddress,
- filterString,
- transformerClassName,
- retryInterval,
- retryIntervalMultiplier,
- reconnectAttempts,
- useDuplicateDetection,
- confirmationWindowSize,
-
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
- staticConnectorNames,
- ha,
- user,
- password);
- }
- else
- {
- config = new BridgeConfiguration(name,
- queueName,
- forwardingAddress,
- filterString,
- transformerClassName,
- retryInterval,
- retryIntervalMultiplier,
- reconnectAttempts,
- useDuplicateDetection,
- confirmationWindowSize,
-
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
- discoveryGroupName,
- ha,
- user,
- password);
- }
+ config = new BridgeConfiguration(name,
+ queueName,
+ forwardingAddress,
+ filterString,
+ transformerClassName,
+ retryInterval,
+ retryIntervalMultiplier,
+ reconnectAttempts,
+ useDuplicateDetection,
+ confirmationWindowSize,
+
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
+ discoveryGroupConfiguration,
+ ha,
+ user,
+ password);
mainConfig.getBridgeConfigurations().add(config);
}
- private void getStaticConnectors(final List<String> staticConnectorNames, final
Node child)
- {
- NodeList children2 =
((Element)child).getElementsByTagName("connector-ref");
-
- for (int k = 0; k < children2.getLength(); k++)
- {
- Element child2 = (Element)children2.item(k);
-
- String connectorName = child2.getChildNodes().item(0).getNodeValue();
-
- staticConnectorNames.add(connectorName);
- }
- }
-
private void parseDivertConfiguration(final Element e, final Configuration
mainConfig)
{
String name = e.getAttribute("name");
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/BridgeControlImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/BridgeControlImpl.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/BridgeControlImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -13,9 +13,14 @@
package org.hornetq.core.management.impl;
+import java.util.List;
+import java.util.Map;
+
import javax.management.MBeanOperationInfo;
import org.hornetq.api.core.management.BridgeControl;
+import org.hornetq.api.core.DiscoveryGroupConstants;
+import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.core.config.BridgeConfiguration;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.server.cluster.Bridge;
@@ -58,7 +63,19 @@
clearIO();
try
{
- return configuration.getStaticConnectors().toArray(new String[0]);
+ Map<String,Object> params =
configuration.getDiscoveryGroupConfiguration().getParams();
+ List<TransportConfiguration> staticConnectors =
(List<TransportConfiguration>)params.get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME);
+ if(staticConnectors == null)
+ {
+ return null;
+ }
+
+ String[] staticConnectorNames = new String[staticConnectors.size()];
+ for(int i=0; i<staticConnectors.size(); i++)
+ {
+ staticConnectorNames[i] = staticConnectors.get(i).getName();
+ }
+ return staticConnectorNames;
}
finally
{
@@ -97,7 +114,7 @@
clearIO();
try
{
- return configuration.getDiscoveryGroupName();
+ return configuration.getDiscoveryGroupConfiguration().getName();
}
finally
{
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/BroadcastGroupControlImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/BroadcastGroupControlImpl.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/BroadcastGroupControlImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -13,10 +13,15 @@
package org.hornetq.core.management.impl;
+import java.util.List;
+import java.util.Map;
+
import javax.management.MBeanOperationInfo;
+import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.management.BroadcastGroupControl;
import org.hornetq.core.config.BroadcastGroupConfiguration;
+import org.hornetq.core.config.BroadcastGroupConstants;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.server.cluster.BroadcastGroup;
import org.hornetq.utils.json.JSONArray;
@@ -72,7 +77,16 @@
clearIO();
try
{
- return configuration.getBroadcastPeriod();
+ Map<String,Object> params = configuration.getParams();
+ String period =
(String)params.get(BroadcastGroupConstants.BROADCAST_PERIOD_NAME);
+ if(period == null)
+ {
+ return -1;
+ }
+ else
+ {
+ return Long.parseLong(period);
+ }
}
finally
{
@@ -85,12 +99,14 @@
clearIO();
try
{
- Object[] ret = new Object[configuration.getConnectorInfos().size()];
+ List<TransportConfiguration> connectors = configuration.getConnectorList();
+ Object[] ret = new Object[connectors.size()];
+
int i = 0;
- for (String connector : configuration.getConnectorInfos())
+ for (TransportConfiguration conn : connectors)
{
- ret[i++] = connector;
+ ret[i++] = conn.getName();
}
return ret;
@@ -108,9 +124,11 @@
{
JSONArray array = new JSONArray();
- for (String connector : configuration.getConnectorInfos())
+ List<TransportConfiguration> connectors =
configuration.getConnectorList();
+
+ for (TransportConfiguration conn : connectors)
{
- array.put(connector);
+ array.put(conn.getName());
}
return array.toString();
}
@@ -125,7 +143,8 @@
clearIO();
try
{
- return configuration.getGroupAddress();
+ Map<String,Object> params = configuration.getParams();
+ return (String)params.get(BroadcastGroupConstants.GROUP_ADDRESS_NAME);
}
finally
{
@@ -138,7 +157,16 @@
clearIO();
try
{
- return configuration.getGroupPort();
+ Map<String,Object> params = configuration.getParams();
+ String port = (String)params.get(BroadcastGroupConstants.GROUP_PORT_NAME);
+ if(port == null)
+ {
+ return -1;
+ }
+ else
+ {
+ return Integer.parseInt(port);
+ }
}
finally
{
@@ -151,7 +179,16 @@
clearIO();
try
{
- return configuration.getLocalBindPort();
+ Map<String,Object> params = configuration.getParams();
+ String port = (String)params.get(BroadcastGroupConstants.LOCAL_BIND_PORT_NAME);
+ if(port == null)
+ {
+ return -1;
+ }
+ else
+ {
+ return Integer.parseInt(port);
+ }
}
finally
{
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/ClusterConnectionControlImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/ClusterConnectionControlImpl.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/ClusterConnectionControlImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -18,6 +18,8 @@
import javax.management.MBeanOperationInfo;
+import org.hornetq.api.core.DiscoveryGroupConstants;
+import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.management.ClusterConnectionControl;
import org.hornetq.core.config.ClusterConnectionConfiguration;
import org.hornetq.core.persistence.StorageManager;
@@ -74,7 +76,7 @@
clearIO();
try
{
- return configuration.getDiscoveryGroupName();
+ return configuration.getDiscoveryGroupConfiguration().getName();
}
finally
{
@@ -143,14 +145,19 @@
clearIO();
try
{
- if (configuration.getStaticConnectors() == null)
+ Map<String,Object> params =
configuration.getDiscoveryGroupConfiguration().getParams();
+ List<TransportConfiguration> staticConnectors =
(List<TransportConfiguration>)params.get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME);
+ if(staticConnectors == null)
{
return null;
}
- else
+
+ String[] staticConnectorNames = new String[staticConnectors.size()];
+ for(int i=0; i<staticConnectors.size(); i++)
{
- return configuration.getStaticConnectors().toArray(new String[0]);
+ staticConnectorNames[i] = staticConnectors.get(i).getName();
}
+ return staticConnectorNames;
}
finally
{
@@ -163,7 +170,7 @@
clearIO();
try
{
- List<String> connectors = configuration.getStaticConnectors();
+ String[] connectors = getStaticConnectors();
if (connectors == null)
{
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/HornetQServerControlImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/HornetQServerControlImpl.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/management/impl/HornetQServerControlImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -35,6 +35,8 @@
import javax.management.NotificationListener;
import javax.transaction.xa.Xid;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
@@ -44,6 +46,8 @@
import org.hornetq.api.core.management.HornetQServerControl;
import org.hornetq.api.core.management.NotificationType;
import org.hornetq.api.core.management.QueueControl;
+import org.hornetq.core.client.impl.SimpleUDPServerLocatorImpl;
+import org.hornetq.core.client.impl.StaticServerLocatorImpl;
import org.hornetq.core.config.BridgeConfiguration;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.DivertConfiguration;
@@ -1681,8 +1685,7 @@
final boolean useDuplicateDetection,
final int confirmationWindowSize,
final long clientFailureCheckPeriod,
- final String connectorNames,
- boolean useDiscoveryGroup,
+ final String discoveryGroupName,
final boolean ha,
final String user,
final String password) throws Exception
@@ -1695,43 +1698,22 @@
try
{
BridgeConfiguration config = null;
- if (useDiscoveryGroup)
- {
- config = new BridgeConfiguration(name,
- queueName,
- forwardingAddress,
- filterString,
- transformerClassName,
- retryInterval,
- retryIntervalMultiplier,
- reconnectAttempts,
- useDuplicateDetection,
- confirmationWindowSize,
- clientFailureCheckPeriod,
- connectorNames,
- ha,
- user,
- password);
- }
- else
- {
- List<String> connectors = toList(connectorNames);
- config = new BridgeConfiguration(name,
- queueName,
- forwardingAddress,
- filterString,
- transformerClassName,
- retryInterval,
- retryIntervalMultiplier,
- reconnectAttempts,
- useDuplicateDetection,
- confirmationWindowSize,
- clientFailureCheckPeriod,
- connectors,
- ha,
- user,
- password);
- }
+ config = new BridgeConfiguration(name,
+ queueName,
+ forwardingAddress,
+ filterString,
+ transformerClassName,
+ retryInterval,
+ retryIntervalMultiplier,
+ reconnectAttempts,
+ useDuplicateDetection,
+ confirmationWindowSize,
+ clientFailureCheckPeriod,
+
configuration.getDiscoveryGroupConfigurations().get(discoveryGroupName),
+ ha,
+ user,
+ password);
+
server.deployBridge(config);
}
finally
@@ -1964,4 +1946,35 @@
return list;
}
+ public void createStaticDiscoveryGroup(String name, String connectors) throws
Exception
+ {
+ List<TransportConfiguration> connectorConfigs = new
ArrayList<TransportConfiguration>();
+ for(String connector : toList(connectors))
+ {
+
connectorConfigs.add(configuration.getConnectorConfigurations().get(connector));
+ }
+
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(DiscoveryGroupConstants.STATIC_CONNECTORS_CONNECTOR_NAMES_NAME,
connectors);
+ params.put(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME, connectorConfigs);
+ DiscoveryGroupConfiguration groupConf = new
DiscoveryGroupConfiguration(StaticServerLocatorImpl.class.getName(), params, name);
+ configuration.getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+ }
+
+ public void createSimpleUDPDiscoveryGroup(String name,
+ String localBindAddress,
+ String groupAddress,
+ int groupPort,
+ long refreshTimeout,
+ long initialWaitTimeout) throws Exception
+ {
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(DiscoveryGroupConstants.LOCAL_BIND_ADDRESS_NAME, localBindAddress);
+ params.put(DiscoveryGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(DiscoveryGroupConstants.GROUP_PORT_NAME, groupPort);
+ params.put(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME, refreshTimeout);
+ params.put(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME, initialWaitTimeout);
+ DiscoveryGroupConfiguration groupConf = new
DiscoveryGroupConfiguration(SimpleUDPServerLocatorImpl.class.getName(), params, name);
+ configuration.getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+ }
}
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/BroadcastGroup.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/BroadcastGroup.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/BroadcastGroup.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -13,6 +13,8 @@
package org.hornetq.core.server.cluster;
+import java.util.concurrent.ScheduledExecutorService;
+
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.core.server.HornetQComponent;
import org.hornetq.core.server.management.NotificationService;
@@ -42,4 +44,6 @@
void broadcastConnectors() throws Exception;
void activate();
+
+ void schedule(ScheduledExecutorService scheduler);
}
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/BroadcastGroupImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/BroadcastGroupImpl.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/BroadcastGroupImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -18,17 +18,23 @@
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.api.core.HornetQBuffers;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.management.NotificationType;
+import org.hornetq.core.config.BroadcastGroupConfiguration;
+import org.hornetq.core.config.BroadcastGroupConstants;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.server.cluster.BroadcastGroup;
import org.hornetq.core.server.management.Notification;
import org.hornetq.core.server.management.NotificationService;
+import org.hornetq.utils.ConfigurationHelper;
import org.hornetq.utils.TypedProperties;
import org.hornetq.utils.UUIDGenerator;
@@ -48,17 +54,11 @@
private final String name;
- private final InetAddress localAddress;
-
- private final int localPort;
-
- private final InetAddress groupAddress;
-
- private final int groupPort;
-
+ private final BroadcastGroupConfiguration broadcastGroupConfiguration;
+
private DatagramSocket socket;
- private final List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ private final List<TransportConfiguration> connectors;
private boolean started;
@@ -77,27 +77,20 @@
*/
public BroadcastGroupImpl(final String nodeID,
final String name,
- final InetAddress localAddress,
- final int localPort,
- final InetAddress groupAddress,
- final int groupPort,
- final boolean active) throws Exception
+ final boolean active,
+ final BroadcastGroupConfiguration config) throws Exception
{
this.nodeID = nodeID;
this.name = name;
- this.localAddress = localAddress;
-
- this.localPort = localPort;
-
- this.groupAddress = groupAddress;
-
- this.groupPort = groupPort;
-
this.active = active;
+ this.broadcastGroupConfiguration = config;
+
uniqueID = UUIDGenerator.getInstance().generateStringUUID();
+
+ this.connectors = config.getConnectorList();
}
public void setNotificationService(final NotificationService notificationService)
@@ -112,6 +105,16 @@
return;
}
+ Map<String,Object> params = this.broadcastGroupConfiguration.getParams();
+ int localPort =
ConfigurationHelper.getIntProperty(BroadcastGroupConstants.LOCAL_BIND_PORT_NAME, -1,
params);
+ String localAddr =
ConfigurationHelper.getStringProperty(BroadcastGroupConstants.LOCAL_BIND_ADDRESS_NAME,
null, params);
+
+ InetAddress localAddress = null;
+ if(localAddr!=null)
+ {
+ localAddress = InetAddress.getByName(localAddr);
+ }
+
if (localPort != -1)
{
socket = new DatagramSocket(localPort, localAddress);
@@ -222,7 +225,11 @@
byte[] data = buff.toByteBuffer().array();
- DatagramPacket packet = new DatagramPacket(data, data.length, groupAddress,
groupPort);
+ Map<String,Object> params = broadcastGroupConfiguration.getParams();
+ Integer groupPort = (Integer)params.get(BroadcastGroupConstants.GROUP_PORT_NAME);
+ InetAddress groupAddr =
(InetAddress)params.get(BroadcastGroupConstants.GROUP_ADDRESS_NAME);
+
+ DatagramPacket packet = new DatagramPacket(data, data.length, groupAddr,
groupPort);
socket.send(packet);
}
@@ -244,9 +251,14 @@
}
}
- public synchronized void setScheduledFuture(final ScheduledFuture<?> future)
+ public void schedule(ScheduledExecutorService scheduler)
{
- this.future = future;
- }
+ Map<String,Object> params = broadcastGroupConfiguration.getParams();
+
+ this.future = scheduler.scheduleWithFixedDelay(this,
+ 0L,
+
Long.parseLong((String)params.get(BroadcastGroupConstants.BROADCAST_PERIOD_NAME)),
+ TimeUnit.MILLISECONDS);
+ }
}
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/ClusterConnectionImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/ClusterConnectionImpl.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/ClusterConnectionImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -21,6 +21,7 @@
import java.util.concurrent.ScheduledExecutorService;
import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
@@ -97,90 +98,16 @@
private final String clusterPassword;
- private final ClusterConnector clusterConnector;
+ private final DiscoveryGroupConfiguration discoveryGroupConfiguration;
private ServerLocatorInternal serverLocator;
private final TransportConfiguration connector;
- private final boolean allowDirectConnectionsOnly;
+ private final boolean allowableConnectionsOnly;
private final Set<TransportConfiguration> allowableConnections = new
HashSet<TransportConfiguration>();
- public ClusterConnectionImpl(final TransportConfiguration[] tcConfigs,
- final TransportConfiguration connector,
- final SimpleString name,
- final SimpleString address,
- final long retryInterval,
- final boolean useDuplicateDetection,
- final boolean routeWhenNoConsumers,
- final int confirmationWindowSize,
- final ExecutorFactory executorFactory,
- final HornetQServer server,
- final PostOffice postOffice,
- final ManagementService managementService,
- final ScheduledExecutorService scheduledExecutor,
- final int maxHops,
- final UUID nodeUUID,
- final boolean backup,
- final String clusterUser,
- final String clusterPassword,
- final boolean allowDirectConnectionsOnly) throws
Exception
- {
-
- if (nodeUUID == null)
- {
- throw new IllegalArgumentException("node id is null");
- }
-
- this.nodeUUID = nodeUUID;
-
- this.connector = connector;
-
- this.name = name;
-
- this.address = address;
-
- this.retryInterval = retryInterval;
-
- this.useDuplicateDetection = useDuplicateDetection;
-
- this.routeWhenNoConsumers = routeWhenNoConsumers;
-
- this.executorFactory = executorFactory;
-
- this.server = server;
-
- this.postOffice = postOffice;
-
- this.managementService = managementService;
-
- this.scheduledExecutor = scheduledExecutor;
-
- this.maxHops = maxHops;
-
- this.backup = backup;
-
- this.clusterUser = clusterUser;
-
- this.clusterPassword = clusterPassword;
-
- this.allowDirectConnectionsOnly = allowDirectConnectionsOnly;
-
- clusterConnector = new StaticClusterConnector(tcConfigs);
-
- if (tcConfigs != null && tcConfigs.length > 0)
- {
- // a cluster connection will connect to other nodes only if they are directly
connected
- // through a static list of connectors or broadcasting using UDP.
- if(allowDirectConnectionsOnly)
- {
- allowableConnections.addAll(Arrays.asList(tcConfigs));
- }
- }
-
- }
-
public ClusterConnectionImpl(DiscoveryGroupConfiguration dg,
final TransportConfiguration connector,
final SimpleString name,
@@ -199,7 +126,7 @@
final boolean backup,
final String clusterUser,
final String clusterPassword,
- final boolean allowDirectConnectionsOnly) throws
Exception
+ final boolean allowableConnectionsOnly) throws Exception
{
if (nodeUUID == null)
@@ -239,9 +166,9 @@
this.clusterPassword = clusterPassword;
- this.allowDirectConnectionsOnly = allowDirectConnectionsOnly;
+ this.allowableConnectionsOnly = allowableConnectionsOnly;
- clusterConnector = new DiscoveryClusterConnector(dg);
+ this.discoveryGroupConfiguration = dg;
}
public synchronized void start() throws Exception
@@ -343,7 +270,7 @@
backup = false;
- serverLocator = clusterConnector.createServerLocator();
+ serverLocator =
(ServerLocatorInternal)HornetQClient.createServerLocatorWithHA(this.discoveryGroupConfiguration);
if (serverLocator != null)
@@ -377,6 +304,13 @@
props);
managementService.sendNotification(notification);
}
+
+ if(this.allowableConnectionsOnly)
+ {
+ Map<String,Object> params = discoveryGroupConfiguration.getParams();
+ List<TransportConfiguration> sc =
(List<TransportConfiguration>)params.get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME);
+ this.allowableConnections.addAll(sc);
+ }
}
public TransportConfiguration getConnector()
@@ -431,7 +365,7 @@
server.getClusterManager().notifyNodeUp(nodeID, connectorPair, last, false);
// if the node is more than 1 hop away, we do not create a bridge for direct
cluster connection
- if (allowDirectConnectionsOnly &&
!allowableConnections.contains(connectorPair.a))
+ if (allowableConnectionsOnly &&
!allowableConnections.contains(connectorPair.a))
{
return;
}
@@ -502,7 +436,7 @@
}
// if the node is more than 1 hop away, we do not create a bridge for direct
cluster connection
- if (allowDirectConnectionsOnly &&
!allowableConnections.contains(connectorPair.a))
+ if (allowableConnectionsOnly &&
!allowableConnections.contains(connectorPair.a))
{
return;
}
@@ -1051,46 +985,4 @@
return out;
}
-
- interface ClusterConnector
- {
- ServerLocatorInternal createServerLocator();
- }
-
- private class StaticClusterConnector implements ClusterConnector
- {
- private final TransportConfiguration[] tcConfigs;
-
- public StaticClusterConnector(TransportConfiguration[] tcConfigs)
- {
- this.tcConfigs = tcConfigs;
- }
-
- public ServerLocatorInternal createServerLocator()
- {
- if(tcConfigs != null && tcConfigs.length > 0)
- {
- return (ServerLocatorInternal)
HornetQClient.createServerLocatorWithHA(tcConfigs);
- }
- else
- {
- return null;
- }
- }
- }
-
- private class DiscoveryClusterConnector implements ClusterConnector
- {
- private final DiscoveryGroupConfiguration dg;
-
- public DiscoveryClusterConnector(DiscoveryGroupConfiguration dg)
- {
- this.dg = dg;
- }
-
- public ServerLocatorInternal createServerLocator()
- {
- return (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(dg);
- }
- }
}
Modified:
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/java/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -16,6 +16,7 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
@@ -522,43 +523,23 @@
return;
}
- InetAddress localAddress = null;
- if (config.getLocalBindAddress() != null)
- {
- localAddress = InetAddress.getByName(config.getLocalBindAddress());
- }
+ String className = config.getBroadcastGroupClassName();
- InetAddress groupAddress = InetAddress.getByName(config.getGroupAddress());
-
- BroadcastGroupImpl group = new BroadcastGroupImpl(nodeUUID.toString(),
- config.getName(),
- localAddress,
- config.getLocalBindPort(),
- groupAddress,
- config.getGroupPort(),
- !backup);
-
- for (String connectorInfo : config.getConnectorInfos())
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class<?> clazz = loader.loadClass(className);
+ Constructor<?> constructor = clazz.getConstructor(String.class, String.class,
boolean.class, BroadcastGroupConfiguration.class);
+ BroadcastGroup group = (BroadcastGroup)constructor.newInstance(nodeUUID.toString(),
config.getName(), !backup, config);
+
+ if (group.size() == 0)
{
- TransportConfiguration connector =
configuration.getConnectorConfigurations().get(connectorInfo);
-
- if (connector == null)
- {
- logWarnNoConnector(config.getName(), connectorInfo);
-
- return;
- }
-
- group.addConnector(connector);
+ ClusterManagerImpl.log.warn("There is no connector deployed for the
broadcast group with name '" +
+ group.getName() +
+ "'. That will not be deployed.");
+ return;
}
- ScheduledFuture<?> future = scheduledExecutor.scheduleWithFixedDelay(group,
- 0L,
-
config.getBroadcastPeriod(),
-
MILLISECONDS);
-
- group.setScheduledFuture(future);
-
+ group.schedule(scheduledExecutor);
+
broadcastGroups.put(config.getName(), group);
managementService.registerBroadcastGroup(group, config);
@@ -569,37 +550,6 @@
}
}
- private void logWarnNoConnector(final String connectorName, final String bgName)
- {
- ClusterManagerImpl.log.warn("There is no connector deployed with name
'" + connectorName +
- "'. The broadcast group with name '"
+
- bgName +
- "' will not be deployed.");
- }
-
- private TransportConfiguration[] connectorNameListToArray(final List<String>
connectorNames)
- {
- TransportConfiguration[] tcConfigs =
(TransportConfiguration[])Array.newInstance(TransportConfiguration.class,
-
connectorNames.size());
- int count = 0;
- for (String connectorName : connectorNames)
- {
- TransportConfiguration connector =
configuration.getConnectorConfigurations().get(connectorName);
-
- if (connector == null)
- {
- ClusterManagerImpl.log.warn("No connector defined with name '"
+ connectorName +
- "'. The bridge will not be
deployed.");
-
- return null;
- }
-
- tcConfigs[count++] = connector;
- }
-
- return tcConfigs;
- }
-
public synchronized void deployBridge(final BridgeConfiguration config) throws
Exception
{
if (config.getName() == null)
@@ -645,46 +595,15 @@
ServerLocatorInternal serverLocator;
- if (config.getDiscoveryGroupName() != null)
+ DiscoveryGroupConfiguration discoveryGroupConfiguration =
config.getDiscoveryGroupConfiguration();
+
+ if (config.isHA())
{
- DiscoveryGroupConfiguration discoveryGroupConfiguration =
configuration.getDiscoveryGroupConfigurations()
-
.get(config.getDiscoveryGroupName());
- if (discoveryGroupConfiguration == null)
- {
- ClusterManagerImpl.log.warn("No discovery group configured with name
'" + config.getDiscoveryGroupName() +
- "'. The bridge will not be
deployed.");
-
- return;
- }
-
- if (config.isHA())
- {
- serverLocator =
(ServerLocatorInternal)HornetQClient.createServerLocatorWithHA(discoveryGroupConfiguration);
- }
- else
- {
- serverLocator =
(ServerLocatorInternal)HornetQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration);
- }
-
+ serverLocator =
(ServerLocatorInternal)HornetQClient.createServerLocatorWithHA(discoveryGroupConfiguration);
}
else
{
- TransportConfiguration[] tcConfigs =
connectorNameListToArray(config.getStaticConnectors());
-
- if (tcConfigs == null)
- {
- return;
- }
-
- if (config.isHA())
- {
- serverLocator =
(ServerLocatorInternal)HornetQClient.createServerLocatorWithHA(tcConfigs);
- }
- else
- {
- serverLocator =
(ServerLocatorInternal)HornetQClient.createServerLocatorWithoutHA(tcConfigs);
- }
-
+ serverLocator =
(ServerLocatorInternal)HornetQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration);
}
serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize());
@@ -763,62 +682,36 @@
ClusterConnectionImpl clusterConnection;
- if (config.getDiscoveryGroupName() != null)
- {
- DiscoveryGroupConfiguration dg =
configuration.getDiscoveryGroupConfigurations()
-
.get(config.getDiscoveryGroupName());
+ DiscoveryGroupConfiguration dg = configuration.getDiscoveryGroupConfigurations()
+
.get(config.getDiscoveryGroupConfiguration().getName());
+
- if (dg == null)
- {
- ClusterManagerImpl.log.warn("No discovery group with name '" +
config.getDiscoveryGroupName() +
- "'. The cluster connection will not be
deployed.");
- }
-
- clusterConnection = new ClusterConnectionImpl(dg,
- connector,
- new
SimpleString(config.getName()),
- new
SimpleString(config.getAddress()),
- config.getRetryInterval(),
- config.isDuplicateDetection(),
-
config.isForwardWhenNoConsumers(),
-
config.getConfirmationWindowSize(),
- executorFactory,
- server,
- postOffice,
- managementService,
- scheduledExecutor,
- config.getMaxHops(),
- nodeUUID,
- backup,
-
server.getConfiguration().getClusterUser(),
-
server.getConfiguration().getClusterPassword(),
-
config.isAllowDirectConnectionsOnly());
- }
- else
+ if (dg == null)
{
- TransportConfiguration[] tcConfigs = config.getStaticConnectors() != null?
connectorNameListToArray(config.getStaticConnectors()):null;
-
- clusterConnection = new ClusterConnectionImpl(tcConfigs,
- connector,
- new
SimpleString(config.getName()),
- new
SimpleString(config.getAddress()),
- config.getRetryInterval(),
- config.isDuplicateDetection(),
-
config.isForwardWhenNoConsumers(),
-
config.getConfirmationWindowSize(),
- executorFactory,
- server,
- postOffice,
- managementService,
- scheduledExecutor,
- config.getMaxHops(),
- nodeUUID,
- backup,
-
server.getConfiguration().getClusterUser(),
-
server.getConfiguration().getClusterPassword(),
-
config.isAllowDirectConnectionsOnly());
+ ClusterManagerImpl.log.warn("No discovery group with name '" +
config.getDiscoveryGroupConfiguration().getName() +
+ "'. The cluster connection will not be deployed.");
}
+ clusterConnection = new ClusterConnectionImpl(dg,
+ connector,
+ new SimpleString(config.getName()),
+ new
SimpleString(config.getAddress()),
+ config.getRetryInterval(),
+ config.isDuplicateDetection(),
+ config.isForwardWhenNoConsumers(),
+ config.getConfirmationWindowSize(),
+ executorFactory,
+ server,
+ postOffice,
+ managementService,
+ scheduledExecutor,
+ config.getMaxHops(),
+ nodeUUID,
+ backup,
+
server.getConfiguration().getClusterUser(),
+
server.getConfiguration().getClusterPassword(),
+
config.isAllowableConnectionsOnly());
+
managementService.registerCluster(clusterConnection, config);
clusterConnections.put(config.getName(), clusterConnection);
@@ -833,31 +726,17 @@
private void announceBackup(final ClusterConnectionConfiguration config, final
TransportConfiguration connector) throws Exception
{
- if (config.getStaticConnectors() != null)
+ DiscoveryGroupConfiguration dg = configuration.getDiscoveryGroupConfigurations()
+
.get(config.getDiscoveryGroupConfiguration().getName());
+ if (dg == null)
{
- TransportConfiguration[] tcConfigs =
connectorNameListToArray(config.getStaticConnectors());
-
- backupServerLocator =
(ServerLocatorInternal)HornetQClient.createServerLocatorWithoutHA(tcConfigs);
- backupServerLocator.setReconnectAttempts(-1);
+ ClusterManagerImpl.log.warn("No discovery group with name '" +
config.getDiscoveryGroupConfiguration().getName() +
+ "'. The cluster connection will not be
deployed.");
}
- else if (config.getDiscoveryGroupName() != null)
- {
- DiscoveryGroupConfiguration dg =
configuration.getDiscoveryGroupConfigurations()
-
.get(config.getDiscoveryGroupName());
- if (dg == null)
- {
- ClusterManagerImpl.log.warn("No discovery group with name '" +
config.getDiscoveryGroupName() +
- "'. The cluster connection will not be
deployed.");
- }
-
- backupServerLocator =
(ServerLocatorInternal)HornetQClient.createServerLocatorWithoutHA(dg);
- backupServerLocator.setReconnectAttempts(-1);
- }
- else
- {
- return;
- }
+ backupServerLocator =
(ServerLocatorInternal)HornetQClient.createServerLocatorWithoutHA(dg);
+ backupServerLocator.setReconnectAttempts(-1);
+
log.info("announcing backup");
executor.execute(new Runnable()
{
Modified:
branches/HORNETQ-316/hornetq-core/src/main/resources/schema/hornetq-configuration.xsd
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/main/resources/schema/hornetq-configuration.xsd 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/main/resources/schema/hornetq-configuration.xsd 2011-08-25
19:23:40 UTC (rev 11225)
@@ -218,18 +218,12 @@
<xsd:element name="broadcast-group">
<xsd:complexType>
<xsd:sequence>
- <xsd:element maxOccurs="1" minOccurs="0"
ref="local-bind-address">
- </xsd:element>
- <xsd:element maxOccurs="1" minOccurs="0"
ref="local-bind-port">
+ <xsd:element maxOccurs="1" minOccurs="1"
name="broadcast-group-class" type="xsd:string">
</xsd:element>
- <xsd:element maxOccurs="1" minOccurs="1"
ref="group-address">
- </xsd:element>
- <xsd:element maxOccurs="1" minOccurs="1"
ref="group-port">
- </xsd:element>
- <xsd:element maxOccurs="1" minOccurs="0"
ref="broadcast-period">
- </xsd:element>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="connector-ref" type="xsd:string">
</xsd:element>
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="param" type="paramType">
+ </xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:ID"
use="required"/>
</xsd:complexType>
@@ -242,16 +236,10 @@
<xsd:element name="discovery-group">
<xsd:complexType>
<xsd:sequence>
- <xsd:element maxOccurs="1" minOccurs="0"
ref="local-bind-address">
- </xsd:element>
- <xsd:element maxOccurs="1" minOccurs="1"
ref="group-address">
+ <xsd:element maxOccurs="1" minOccurs="1"
name="server-locator-class" type="xsd:string">
</xsd:element>
- <xsd:element maxOccurs="1" minOccurs="1"
ref="group-port">
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="param" type="paramType">
</xsd:element>
- <xsd:element maxOccurs="1" minOccurs="0"
ref="refresh-timeout">
- </xsd:element>
- <xsd:element maxOccurs="1" minOccurs="0"
ref="initial-wait-timeout">
- </xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:ID"
use="required"/>
</xsd:complexType>
@@ -329,21 +317,12 @@
</xsd:element>
<xsd:element maxOccurs="1" minOccurs="0"
name="password" type="xsd:string">
</xsd:element>
- <xsd:choice>
- <xsd:element maxOccurs="1" minOccurs="1"
name="static-connectors">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element maxOccurs="unbounded"
minOccurs="1" name="connector-ref" type="xsd:string"/>
- </xsd:sequence>
- </xsd:complexType>
- </xsd:element>
- <xsd:element maxOccurs="1" minOccurs="1"
name="discovery-group-ref">
- <xsd:complexType>
- <xsd:attribute name="discovery-group-name" type="xsd:IDREF"
use="required">
- </xsd:attribute>
- </xsd:complexType>
- </xsd:element>
- </xsd:choice>
+ <xsd:element maxOccurs="1" minOccurs="1"
name="discovery-group-ref">
+ <xsd:complexType>
+ <xsd:attribute name="discovery-group-name"
type="xsd:IDREF" use="required">
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"
use="required"/>
</xsd:complexType>
@@ -364,22 +343,12 @@
</xsd:element>
<xsd:element maxOccurs="1" minOccurs="0"
name="confirmation-window-size" type="xsd:int">
</xsd:element>
- <xsd:choice>
- <xsd:element maxOccurs="1" minOccurs="0"
name="static-connectors">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element maxOccurs="unbounded"
minOccurs="0" name="connector-ref" type="xsd:string"/>
- </xsd:sequence>
- <xsd:attribute name="allow-direct-connections-only"
type="xsd:boolean" use="optional"/>
- </xsd:complexType>
- </xsd:element>
- <xsd:element maxOccurs="1" minOccurs="0"
name="discovery-group-ref">
- <xsd:complexType>
- <xsd:attribute name="discovery-group-name" type="xsd:IDREF"
use="required">
- </xsd:attribute>
- </xsd:complexType>
- </xsd:element>
- </xsd:choice>
+ <xsd:element maxOccurs="1" minOccurs="0"
name="discovery-group-ref">
+ <xsd:complexType>
+ <xsd:attribute name="discovery-group-name"
type="xsd:IDREF" use="required">
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"
use="required"/>
</xsd:complexType>
@@ -445,7 +414,7 @@
<xsd:attribute name="type" type="xsd:string"
use="required"/>
<xsd:attribute name="roles" type="xsd:string"
use="required"/>
</xsd:complexType>
- </xsd:element>
+p </xsd:element>
</xsd:sequence>
<xsd:attribute name="match" type="xsd:string"
use="required"/>
</xsd:complexType>
Modified:
branches/HORNETQ-316/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java
===================================================================
---
branches/HORNETQ-316/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -31,6 +31,7 @@
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -47,12 +48,19 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.core.asyncio.impl.AsynchronousFileImpl;
-import org.hornetq.core.client.impl.ServerLocatorImpl;
+import org.hornetq.core.client.impl.AbstractServerLocator;
+import org.hornetq.core.client.impl.SimpleUDPServerLocatorImpl;
+import org.hornetq.core.client.impl.StaticServerLocatorImpl;
+import org.hornetq.core.config.BroadcastGroupConfiguration;
+import org.hornetq.core.config.BroadcastGroupConstants;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.journal.impl.AIOSequentialFileFactory;
@@ -73,6 +81,7 @@
import org.hornetq.core.server.MessageReference;
import org.hornetq.core.server.Queue;
import org.hornetq.core.server.ServerMessage;
+import org.hornetq.core.server.cluster.impl.BroadcastGroupImpl;
import org.hornetq.core.server.impl.ServerMessageImpl;
import org.hornetq.core.transaction.impl.XidImpl;
import org.hornetq.utils.UUIDGenerator;
@@ -248,6 +257,58 @@
}
}
+ protected static DiscoveryGroupConfiguration
createSimpleUDPDiscoveryGroupConfiguration(String name,
+
String localBindAddr,
+
String groupAddr,
+
int groupPort,
+
long refreshTimeout,
+
long discoveryInitialTimeout)
+ {
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(DiscoveryGroupConstants.LOCAL_BIND_ADDRESS_NAME, localBindAddr);
+ params.put(DiscoveryGroupConstants.GROUP_ADDRESS_NAME, groupAddr);
+ params.put(DiscoveryGroupConstants.GROUP_PORT_NAME, groupPort);
+ params.put(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME, refreshTimeout);
+ params.put(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME,
discoveryInitialTimeout);
+ return new DiscoveryGroupConfiguration(SimpleUDPServerLocatorImpl.class.getName(),
params, name);
+ }
+
+ protected static DiscoveryGroupConfiguration
createSimpleUDPDiscoveryGroupConfiguration(String groupAddr, int groupPort)
+ {
+ return
createSimpleUDPDiscoveryGroupConfiguration(UUIDGenerator.getInstance().generateStringUUID(),
+ null,
+ groupAddr,
+ groupPort,
+
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
+
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT);
+ }
+
+ protected static DiscoveryGroupConfiguration
createStaticDiscoveryGroupConfiguration(TransportConfiguration... connectors)
+ {
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME, connectors != null
? Arrays.asList(connectors) : null);
+ return new DiscoveryGroupConfiguration(StaticServerLocatorImpl.class.getName(),
+ params,
+
UUIDGenerator.getInstance().generateStringUUID());
+ }
+
+ protected static BroadcastGroupConfiguration createBroadcastGroupConfiguration(String
name,
+ String
localBindAddress,
+ int
localBindPort,
+ String
groupAddress,
+ int
groupPort,
+ long
broadcastPeriod,
+
List<TransportConfiguration> connectorList)
+ {
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.LOCAL_BIND_ADDRESS_NAME, localBindAddress);
+ params.put(BroadcastGroupConstants.LOCAL_BIND_PORT_NAME,
Integer.toString(localBindPort));
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_PORT_NAME, Integer.toString(groupPort));
+ params.put(BroadcastGroupConstants.BROADCAST_PERIOD_NAME,
Long.toString(broadcastPeriod));
+ return new BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
name, connectorList);
+ }
+
/**
* @param name
*/
@@ -973,7 +1034,7 @@
}
// We shutdown the global pools to give a better isolation between tests
- ServerLocatorImpl.clearThreadPools();
+ AbstractServerLocator.clearThreadPools();
}
protected byte[] autoEncode(final Object... args)
Added: branches/HORNETQ-316/hornetq-jgroups-discovery/pom.xml
===================================================================
--- branches/HORNETQ-316/hornetq-jgroups-discovery/pom.xml (rev
0)
+++ branches/HORNETQ-316/hornetq-jgroups-discovery/pom.xml 2011-08-25 19:23:40 UTC (rev
11225)
@@ -0,0 +1,33 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-pom</artifactId>
+ <version>2.2.3-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>hornetq-jgroups-discovery</artifactId>
+ <packaging>jar</packaging>
+ <name>HornetQ JGroups Cluster Discovery Integration</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-commons</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jgroups</groupId>
+ <artifactId>jgroups</artifactId>
+ <version>2.12.1.Final</version>
+ </dependency>
+ </dependencies>
+
+</project>
Added:
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/BroadcastGroupConstants.java
===================================================================
---
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/BroadcastGroupConstants.java
(rev 0)
+++
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/BroadcastGroupConstants.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.integration.discovery.jgroups;
+
+/**
+ * A BroadcastGroupConstants
+ *
+ * @author "<a href=\"tm.igarashi(a)gmail.com\">Tomohisa
Igarashi</a>"
+ *
+ *
+ */
+public class BroadcastGroupConstants
+{
+ public static final String JGROUPS_CONFIGURATION_FILE_NAME =
"jgroups-configuration-file";
+ public static final String BROADCAST_PERIOD_NAME = "broadcast-period";
+ public static final String JGROUPS_CHANNEL_NAME_NAME =
"jgroups-channel-name";
+
+ public static final String DEFAULT_JGROUPS_CHANNEL_NAME =
"hornetq-jgroups-channel";
+}
Added:
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/DiscoveryGroupConstants.java
===================================================================
---
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/DiscoveryGroupConstants.java
(rev 0)
+++
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/DiscoveryGroupConstants.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.integration.discovery.jgroups;
+
+/**
+ * A DiscoveryGroupConstants
+ *
+ * @author "<a href=\"tm.igarashi(a)gmail.com\">Tomohisa
Igarashi</a>"
+ *
+ *
+ */
+public class DiscoveryGroupConstants
+{
+ public static final String JGROUPS_CONFIGURATION_FILE_NAME =
"jgroups-configuration-filename";
+ public static final String INITIAL_WAIT_TIMEOUT_NAME =
"initial-wait-timeout";
+ public static final String REFRESH_TIMEOUT_NAME = "refresh-timeout";
+ public static final String JGROUPS_CHANNEL_NAME_NAME =
"jgroups-channel-name";
+
+ public static final String DEFAULT_JGROUPS_CHANNEL_NAME =
"hornetq-jgroups-channel";
+}
Added:
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsBroadcastGroupImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsBroadcastGroupImpl.java
(rev 0)
+++
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsBroadcastGroupImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,247 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.integration.discovery.jgroups;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import org.hornetq.api.core.HornetQBuffer;
+import org.hornetq.api.core.HornetQBuffers;
+import org.hornetq.api.core.SimpleString;
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.management.NotificationType;
+import org.hornetq.core.config.BroadcastGroupConfiguration;
+import org.hornetq.core.logging.Logger;
+import org.hornetq.core.server.cluster.BroadcastGroup;
+import org.hornetq.core.server.management.Notification;
+import org.hornetq.core.server.management.NotificationService;
+import org.hornetq.utils.ConfigurationHelper;
+import org.hornetq.utils.TypedProperties;
+import org.hornetq.utils.UUIDGenerator;
+import org.jgroups.JChannel;
+import org.jgroups.Message;
+
+/**
+ * A JGroupsBroadcastGroupImpl
+ *
+ * @author "<a href=\"tm.igarashi(a)gmail.com\">Tomohisa
Igarashi</a>"
+ *
+ *
+ */
+public class JGroupsBroadcastGroupImpl implements BroadcastGroup, Runnable
+{
+ private static final Logger log = Logger.getLogger(JGroupsBroadcastGroupImpl.class);
+
+ private final String nodeID;
+
+ private final String name;
+
+ private final BroadcastGroupConfiguration broadcastGroupConfiguration;
+
+ private final List<TransportConfiguration> connectors;
+
+ private String jgroupsConfigurationFileName;
+
+ private String jgroupsChannelName = null;
+
+ private JChannel broadcastChannel;
+
+ private boolean started;
+
+ private ScheduledFuture<?> future;
+
+ private boolean active;
+
+ // Each broadcast group has a unique id - we use this to detect when more than one
group broadcasts the same node id
+ // on the network which would be an error
+ private final String uniqueID;
+
+ private NotificationService notificationService;
+
+ public JGroupsBroadcastGroupImpl(final String nodeID,
+ final String name,
+ final boolean active,
+ final BroadcastGroupConfiguration config)
+ {
+ this.nodeID = nodeID;
+
+ this.name = name;
+
+ this.active = active;
+
+ this.broadcastGroupConfiguration = config;
+
+ this.connectors = config.getConnectorList();
+
+ uniqueID = UUIDGenerator.getInstance().generateStringUUID();
+ }
+
+ public void setNotificationService(NotificationService notificationService)
+ {
+ this.notificationService = notificationService;
+ }
+
+ public void start() throws Exception
+ {
+ if (started)
+ {
+ return;
+ }
+
+ Map<String,Object> params = this.broadcastGroupConfiguration.getParams();
+ this.jgroupsConfigurationFileName =
ConfigurationHelper.getStringProperty(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME,
null, params);
+ this.jgroupsChannelName =
ConfigurationHelper.getStringProperty(BroadcastGroupConstants.JGROUPS_CHANNEL_NAME_NAME,
BroadcastGroupConstants.DEFAULT_JGROUPS_CHANNEL_NAME, params);
+ this.broadcastChannel = new
JChannel(Thread.currentThread().getContextClassLoader().getResource(this.jgroupsConfigurationFileName));
+
+ this.broadcastChannel.connect(this.jgroupsChannelName);
+
+ started = true;
+
+ if (notificationService != null)
+ {
+ TypedProperties props = new TypedProperties();
+ props.putSimpleStringProperty(new SimpleString("name"), new
SimpleString(name));
+ Notification notification = new Notification(nodeID,
NotificationType.BROADCAST_GROUP_STARTED, props);
+ notificationService.sendNotification(notification);
+ }
+ }
+
+ public void stop() throws Exception
+ {
+ if (!started)
+ {
+ return;
+ }
+
+ if (future != null)
+ {
+ future.cancel(false);
+ future = null;
+ }
+
+ if (broadcastChannel != null)
+ {
+ broadcastChannel.shutdown();
+ broadcastChannel.close();
+ broadcastChannel = null;
+ }
+
+ started = false;
+
+ if (notificationService != null)
+ {
+ TypedProperties props = new TypedProperties();
+ props.putSimpleStringProperty(new SimpleString("name"), new
SimpleString(name));
+ Notification notification = new Notification(nodeID,
NotificationType.BROADCAST_GROUP_STOPPED, props);
+ try
+ {
+ notificationService.sendNotification(notification);
+ }
+ catch (Exception e)
+ {
+ JGroupsBroadcastGroupImpl.log.warn("unable to send notification when
broadcast group is stopped", e);
+ }
+ }
+
+ }
+
+ public boolean isStarted()
+ {
+ return this.started;
+ }
+
+ public String getName()
+ {
+ return this.name;
+ }
+
+ public void addConnector(TransportConfiguration tcConfig)
+ {
+ this.connectors.add(tcConfig);
+ }
+
+ public void removeConnector(TransportConfiguration tcConfig)
+ {
+ this.connectors.remove(tcConfig);
+ }
+
+ public int size()
+ {
+ return this.connectors.size();
+ }
+
+ public void activate()
+ {
+ this.active = true;
+ }
+
+ public void broadcastConnectors() throws Exception
+ {
+ if (!active)
+ {
+ return;
+ }
+
+ HornetQBuffer buff = HornetQBuffers.dynamicBuffer(4096);
+
+ buff.writeString(nodeID);
+
+ buff.writeString(uniqueID);
+
+ buff.writeInt(connectors.size());
+
+ for (TransportConfiguration tcConfig : connectors)
+ {
+ tcConfig.encode(buff);
+ }
+
+ byte[] data = buff.toByteBuffer().array();
+
+ Message msg = new Message();
+
+ msg.setBuffer(data);
+
+ this.broadcastChannel.send(msg);
+ }
+
+ public void run()
+ {
+ if (!started)
+ {
+ return;
+ }
+
+ try
+ {
+ broadcastConnectors();
+ }
+ catch (Exception e)
+ {
+ JGroupsBroadcastGroupImpl.log.error("Failed to broadcast connector
configs", e);
+ }
+ }
+
+ public void schedule(ScheduledExecutorService scheduler)
+ {
+ Map<String,Object> params = broadcastGroupConfiguration.getParams();
+
+ this.future = scheduler.scheduleWithFixedDelay(this,
+ 0L,
+
Long.parseLong((String)params.get(BroadcastGroupConstants.BROADCAST_PERIOD_NAME)),
+ TimeUnit.MILLISECONDS);
+ }
+}
Added:
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsDiscoveryGroupImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsDiscoveryGroupImpl.java
(rev 0)
+++
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsDiscoveryGroupImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,369 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.integration.discovery.jgroups;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hornetq.api.core.HornetQBuffer;
+import org.hornetq.api.core.HornetQBuffers;
+import org.hornetq.api.core.SimpleString;
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.management.NotificationType;
+import org.hornetq.core.cluster.DiscoveryEntry;
+import org.hornetq.core.cluster.DiscoveryGroup;
+import org.hornetq.core.cluster.DiscoveryListener;
+import org.hornetq.core.logging.Logger;
+import org.hornetq.core.server.management.Notification;
+import org.hornetq.core.server.management.NotificationService;
+import org.hornetq.utils.TypedProperties;
+import org.jgroups.JChannel;
+import org.jgroups.Message;
+import org.jgroups.ReceiverAdapter;
+
+/**
+ * A JGroupsDiscoveryGroupImpl
+ *
+ * @author "<a href=\"tm.igarashi(a)gmail.com\">Tomohisa
Igarashi</a>"
+ *
+ *
+ */
+public class JGroupsDiscoveryGroupImpl extends ReceiverAdapter implements DiscoveryGroup
+{
+ private static final Logger log = Logger.getLogger(JGroupsDiscoveryGroupImpl.class);
+
+ private final List<DiscoveryListener> listeners = new
ArrayList<DiscoveryListener>();
+
+ private final String name;
+
+ private final String jgroupsChannelName;
+
+ private final URL configURL;
+
+ private final String nodeID;
+
+ private volatile boolean started;
+
+ private boolean received;
+
+ private final Object waitLock = new Object();
+
+ private final Map<String, DiscoveryEntry> connectors = new HashMap<String,
DiscoveryEntry>();
+
+ private final long timeout;
+
+ private final Map<String, String> uniqueIDMap = new HashMap<String,
String>();
+
+ private JChannel discoveryChannel;
+
+ private NotificationService notificationService;
+
+ public JGroupsDiscoveryGroupImpl(final String nodeID,
+ final String name,
+ final String channelName,
+ final URL confURL,
+ final long timeout)
+ {
+ this.nodeID = nodeID;
+ this.name = name;
+ this.jgroupsChannelName = channelName;
+ this.configURL = confURL;
+ this.timeout = timeout;
+ }
+
+ public void setNotificationService(NotificationService notificationService)
+ {
+ this.notificationService = notificationService;
+ }
+
+ public void start() throws Exception
+ {
+ if (started)
+ {
+ return;
+ }
+
+ try
+ {
+ this.discoveryChannel = new JChannel(configURL);
+
+ this.discoveryChannel.setReceiver(this);
+
+ this.discoveryChannel.connect(this.jgroupsChannelName);
+ }
+ catch(Exception e)
+ {
+ log.error("Failed to join jgroups channel", e);
+ return;
+ }
+
+ started = true;
+
+ if (notificationService != null)
+ {
+ TypedProperties props = new TypedProperties();
+
+ props.putSimpleStringProperty(new SimpleString("name"), new
SimpleString(name));
+
+ Notification notification = new Notification(nodeID,
NotificationType.DISCOVERY_GROUP_STARTED, props);
+
+ notificationService.sendNotification(notification);
+ }
+ }
+
+ public void stop() throws Exception
+ {
+ synchronized (this)
+ {
+ if (!started)
+ {
+ return;
+ }
+
+ started = false;
+ }
+
+ synchronized (waitLock)
+ {
+ waitLock.notify();
+ }
+
+ this.discoveryChannel.shutdown();
+
+ this.discoveryChannel.close();
+
+ this.discoveryChannel = null;
+
+ if (notificationService != null)
+ {
+ TypedProperties props = new TypedProperties();
+ props.putSimpleStringProperty(new SimpleString("name"), new
SimpleString(name));
+ Notification notification = new Notification(nodeID,
NotificationType.DISCOVERY_GROUP_STOPPED, props);
+ try
+ {
+ notificationService.sendNotification(notification);
+ }
+ catch (Exception e)
+ {
+ JGroupsDiscoveryGroupImpl.log.warn("unable to send notification when
discovery group is stopped", e);
+ }
+ }
+ }
+
+ public String getName()
+ {
+ return this.name;
+ }
+
+ public String getJGroupsChannelName()
+ {
+ return this.jgroupsChannelName;
+ }
+
+ public List<DiscoveryEntry> getDiscoveryEntries()
+ {
+ List<DiscoveryEntry> list = new ArrayList<DiscoveryEntry>();
+
+ list.addAll(connectors.values());
+
+ return list;
+ }
+
+ public boolean isStarted()
+ {
+ return this.started;
+ }
+
+ public boolean waitForBroadcast(long timeout)
+ {
+ synchronized (waitLock)
+ {
+ long start = System.currentTimeMillis();
+
+ long toWait = timeout;
+
+ while (started && !received && (toWait > 0 || timeout == 0))
+ {
+ try
+ {
+ waitLock.wait(toWait);
+ }
+ catch (InterruptedException e)
+ {
+ }
+
+ if (timeout != 0)
+ {
+ long now = System.currentTimeMillis();
+
+ toWait -= now - start;
+
+ start = now;
+ }
+ }
+
+ boolean ret = received;
+
+ received = false;
+
+ return ret;
+ }
+ }
+
+ @Override
+ public void receive(Message msg)
+ {
+ if(!started)
+ {
+ return;
+ }
+
+ HornetQBuffer buffer = HornetQBuffers.wrappedBuffer(msg.getBuffer());
+
+ String originatingNodeID = buffer.readString();
+
+ String uniqueID = buffer.readString();
+
+ checkUniqueID(originatingNodeID, uniqueID);
+
+ if (nodeID.equals(originatingNodeID))
+ {
+ if (checkExpiration())
+ {
+ callListeners();
+ }
+
+ // Ignore traffic from own node
+ return;
+ }
+
+ int size = buffer.readInt();
+
+ boolean changed = false;
+
+ synchronized (this)
+ {
+ for (int i = 0; i < size; i++)
+ {
+ TransportConfiguration connector = new TransportConfiguration();
+
+ connector.decode(buffer);
+
+ DiscoveryEntry entry = new DiscoveryEntry(originatingNodeID, connector,
System.currentTimeMillis());
+
+ DiscoveryEntry oldVal = connectors.put(originatingNodeID, entry);
+
+ if (oldVal == null)
+ {
+ changed = true;
+ }
+ }
+
+ changed = changed || checkExpiration();
+ }
+
+ if (changed)
+ {
+ callListeners();
+ }
+
+ synchronized (waitLock)
+ {
+ received = true;
+
+ waitLock.notify();
+ }
+ }
+
+ public void registerListener(DiscoveryListener listener)
+ {
+ listeners.add(listener);
+
+ if (!connectors.isEmpty())
+ {
+ listener.connectorsChanged();
+ }
+ }
+
+ public void unregisterListener(DiscoveryListener listener)
+ {
+ listeners.remove(listener);
+ }
+
+ private void callListeners()
+ {
+ for (DiscoveryListener listener : listeners)
+ {
+ try
+ {
+ listener.connectorsChanged();
+ }
+ catch (Throwable t)
+ {
+ // Catch it so exception doesn't prevent other listeners from running
+ JGroupsDiscoveryGroupImpl.log.error("Failed to call discovery
listener", t);
+ }
+ }
+ }
+
+ private void checkUniqueID(final String originatingNodeID, final String uniqueID)
+ {
+ String currentUniqueID = uniqueIDMap.get(originatingNodeID);
+
+ if (currentUniqueID == null)
+ {
+ uniqueIDMap.put(originatingNodeID, uniqueID);
+ }
+ else
+ {
+ if (!currentUniqueID.equals(uniqueID))
+ {
+ log.warn("There are more than one servers on the network broadcasting
the same node id. " + "You will see this message exactly once (per node) if a
node is restarted, in which case it can be safely "
+ + "ignored. But if it is logged continuously it means you
really do have more than one node on the same network "
+ + "active concurrently with the same node id. This could occur
if you have a backup node active at the same time as "
+ + "its live node. nodeID=" + originatingNodeID);
+ uniqueIDMap.put(originatingNodeID, uniqueID);
+ }
+ }
+ }
+
+ private boolean checkExpiration()
+ {
+ boolean changed = false;
+ long now = System.currentTimeMillis();
+
+ Iterator<Map.Entry<String, DiscoveryEntry>> iter =
connectors.entrySet().iterator();
+
+ // Weed out any expired connectors
+
+ while (iter.hasNext())
+ {
+ Map.Entry<String, DiscoveryEntry> entry = iter.next();
+
+ if (entry.getValue().getLastUpdate() + timeout <= now)
+ {
+ iter.remove();
+
+ changed = true;
+ }
+ }
+
+ return changed;
+ }
+
+}
Added:
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsServerLocatorImpl.java
===================================================================
---
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsServerLocatorImpl.java
(rev 0)
+++
branches/HORNETQ-316/hornetq-jgroups-discovery/src/main/java/org/hornetq/integration/discovery/jgroups/JGroupsServerLocatorImpl.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,337 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.integration.discovery.jgroups;
+
+import java.lang.reflect.Array;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executor;
+
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.HornetQException;
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.HornetQClient;
+import org.hornetq.core.client.impl.AbstractServerLocator;
+import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
+import org.hornetq.core.client.impl.ClientSessionFactoryInternal;
+import org.hornetq.core.cluster.DiscoveryEntry;
+import org.hornetq.core.cluster.DiscoveryGroup;
+import org.hornetq.core.cluster.DiscoveryListener;
+import org.hornetq.core.config.impl.ConfigurationImpl;
+import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.ConfigurationHelper;
+
+/**
+ * A JGroupsServerLocatorImpl
+ *
+ * @author "<a href=\"tm.igarashi(a)gmail.com\">Tomohisa
Igarashi</a>"
+ *
+ *
+ */
+public class JGroupsServerLocatorImpl extends AbstractServerLocator implements
DiscoveryListener
+{
+ private static final long serialVersionUID = 1720602999991968346L;
+
+ private static final Logger log = Logger.getLogger(JGroupsServerLocatorImpl.class);
+
+ private String discoveryGroupName;
+
+ private String jgroupsConfigurationFileName;
+
+ private String jgroupsChannelName;
+
+ private long initialWaitTimeout;
+
+ private long refreshTimeout;
+
+ private DiscoveryGroup discoveryGroup;
+
+ private volatile boolean closing;
+
+ private synchronized void initialise() throws Exception {
+ if (!isReadOnly())
+ {
+ setThreadPools();
+
+ instantiateLoadBalancingPolicy();
+
+ this.discoveryGroupName = getDiscoveryGroupConfiguration().getName();
+
+ Map<String,Object> params = getDiscoveryGroupConfiguration().getParams();
+
+ this.jgroupsChannelName =
ConfigurationHelper.getStringProperty(DiscoveryGroupConstants.JGROUPS_CHANNEL_NAME_NAME,
DiscoveryGroupConstants.DEFAULT_JGROUPS_CHANNEL_NAME, params);
+ this.initialWaitTimeout =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME,
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, params);
+
+ this.refreshTimeout =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME,
ConfigurationImpl.DEFAULT_BROADCAST_REFRESH_TIMEOUT, params);
+
+ this.jgroupsConfigurationFileName =
ConfigurationHelper.getStringProperty(DiscoveryGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME,
null, params);
+
+ this.discoveryGroup = new JGroupsDiscoveryGroupImpl(getNodeID(),
+ this.discoveryGroupName,
+ this.jgroupsChannelName,
+
Thread.currentThread().getContextClassLoader().getResource(this.jgroupsConfigurationFileName),
+ this.refreshTimeout);
+
+ this.discoveryGroup.registerListener(this);
+
+ this.discoveryGroup.start();
+
+ setReadOnly(true);
+ }
+ }
+
+ public JGroupsServerLocatorImpl(boolean useHA, DiscoveryGroupConfiguration
discoveryGroupConfiguration)
+ {
+ super(useHA, discoveryGroupConfiguration);
+ }
+
+ public void start(Executor executor) throws Exception
+ {
+ initialise();
+
+ executor.execute(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ connect();
+ }
+ catch (Exception e)
+ {
+ if (!closing)
+ {
+ log.warn("did not connect the cluster connection to other
nodes", e);
+ }
+ }
+ }
+ });
+ }
+
+ public ClientSessionFactory connect() throws Exception
+ {
+ ClientSessionFactoryInternal sf;
+
+ // wait for discovery group to get the list of initial connectors
+ sf = (ClientSessionFactoryInternal)createSessionFactory();
+
+ addFactory(sf);
+ return sf;
+ }
+
+ public ClientSessionFactory createSessionFactory() throws Exception
+ {
+ if (isClosed())
+ {
+ throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
+ }
+
+ try
+ {
+ initialise();
+ }
+ catch (Exception e)
+ {
+ throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
+ }
+
+ if (getInitialConnectors() == null)
+ {
+ // Wait for an initial broadcast to give us at least one node in the cluster
+ long timeout = isClusterConnection() ? 0 : this.initialWaitTimeout;
+ boolean ok = discoveryGroup.waitForBroadcast(timeout);
+
+ if (!ok)
+ {
+ throw new HornetQException(HornetQException.CONNECTION_TIMEDOUT,
+ "Timed out waiting to receive initial
broadcast from cluster");
+ }
+ }
+
+ ClientSessionFactoryInternal factory = null;
+
+ synchronized (this)
+ {
+ boolean retry;
+ int attempts = 0;
+ do
+ {
+ retry = false;
+
+ TransportConfiguration tc = selectConnector();
+
+ // try each factory in the list until we find one which works
+
+ try
+ {
+ factory = new ClientSessionFactoryImpl(this,
+ tc,
+ getCallTimeout(),
+ getClientFailureCheckPeriod(),
+ getConnectionTTL(),
+ getRetryInterval(),
+ getRetryIntervalMultiplier(),
+ getMaxRetryInterval(),
+ getReconnectAttempts(),
+ getThreadPool(),
+ getScheduledThreadPool(),
+ getInterceptors());
+ factory.connect(getInitialConnectAttempts(),
isFailoverOnInitialConnection());
+ }
+ catch (HornetQException e)
+ {
+ factory.close();
+ factory = null;
+ if (e.getCode() == HornetQException.NOT_CONNECTED)
+ {
+ attempts++;
+
+ if (attempts == getConnectorLength())
+ {
+ throw new HornetQException(HornetQException.NOT_CONNECTED,
+ "Cannot connect to server(s). Tried
with all available servers.");
+ }
+ retry = true;
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+ while (retry);
+
+ if (isHA())
+ {
+ long toWait = 30000;
+ long start = System.currentTimeMillis();
+ while (!isReceivedTopology() && toWait > 0)
+ {
+ // Now wait for the topology
+
+ try
+ {
+ wait(toWait);
+ }
+ catch (InterruptedException ignore)
+ {
+ }
+
+ long now = System.currentTimeMillis();
+
+ toWait -= now - start;
+
+ start = now;
+ }
+
+ if (toWait <= 0)
+ {
+ throw new HornetQException(HornetQException.CONNECTION_TIMEDOUT,
+ "Timed out waiting to receive cluster
topology");
+ }
+ }
+
+ addFactory(factory);
+
+ return factory;
+ }
+ }
+
+ public ClientSessionFactory createSessionFactory(TransportConfiguration
transportConfiguration) throws Exception
+ {
+ if (isClosed())
+ {
+ throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
+ }
+
+ try
+ {
+ initialise();
+ }
+ catch (Exception e)
+ {
+ throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
+ }
+
+ ClientSessionFactoryInternal factory = new ClientSessionFactoryImpl(this,
+
transportConfiguration,
+
getCallTimeout(),
+
getClientFailureCheckPeriod(),
+
getConnectionTTL(),
+
getRetryInterval(),
+
getRetryIntervalMultiplier(),
+
getMaxRetryInterval(),
+
getReconnectAttempts(),
+
getThreadPool(),
+
getScheduledThreadPool(),
+
getInterceptors());
+
+ factory.connect(getReconnectAttempts(), isFailoverOnInitialConnection());
+
+ addFactory(factory);
+
+ return factory;
+ }
+
+ public void close()
+ {
+ if (isClosed())
+ {
+ return;
+ }
+
+ closing = true;
+
+ try
+ {
+ this.discoveryGroup.stop();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to stop discovery group", e);
+ }
+
+ super.close();
+ }
+
+ public synchronized void connectorsChanged()
+ {
+ List<DiscoveryEntry> newConnectors = discoveryGroup.getDiscoveryEntries();
+
+ TransportConfiguration[] initialConnectors =
(TransportConfiguration[])Array.newInstance(TransportConfiguration.class,
+
newConnectors.size());
+ int count = 0;
+ for (DiscoveryEntry entry : newConnectors)
+ {
+ initialConnectors[count++] = entry.getConnector();
+ }
+
+ if (isHA() && isClusterConnection() && !isReceivedTopology()
&& initialConnectors.length > 0)
+ {
+ // FIXME the node is alone in the cluster. We create a connection to the new
node
+ // to trigger the node notification to form the cluster.
+ try
+ {
+ connect();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); // To change body of catch statement use File | Settings
| File Templates.
+ }
+ }
+
+ setInitialConnectors(initialConnectors);
+ }
+}
Modified:
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/ConnectionFactoryProperties.java
===================================================================
---
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/ConnectionFactoryProperties.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/ConnectionFactoryProperties.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -100,6 +100,8 @@
private Integer threadPoolMaxSize;
+ private Map<String, Object> discoveryPluginParameters;
+
/**
* @return the transportType
*/
@@ -125,6 +127,17 @@
hasBeenUpdated = true;
}
+ public Map<String, Object> getParsedDiscoveryPluginParameters()
+ {
+ return discoveryPluginParameters;
+ }
+
+ public void setParsedDiscoveryPluginParameters(final Map<String, Object>
discoveryPluginParameters)
+ {
+ this.discoveryPluginParameters = discoveryPluginParameters;
+ hasBeenUpdated = true;
+ }
+
public Boolean isHA()
{
return ha;
Modified:
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/HornetQResourceAdapter.java
===================================================================
---
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/HornetQResourceAdapter.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/HornetQResourceAdapter.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -32,6 +32,7 @@
import javax.transaction.xa.XAResource;
import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
@@ -39,6 +40,7 @@
import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.jms.HornetQJMSClient;
import org.hornetq.api.jms.JMSFactoryType;
+import org.hornetq.core.client.impl.SimpleUDPServerLocatorImpl;
import org.hornetq.core.logging.Logger;
import org.hornetq.jms.client.HornetQConnectionFactory;
import org.hornetq.ra.inflow.HornetQActivation;
@@ -91,6 +93,11 @@
private String unparsedConnectors;
/**
+ * The discovery plugin properties for resource adapter before parsing
+ */
+ private String unparsedDiscoveryPluginProperties;
+
+ /**
* Have the factory been configured
*/
private final AtomicBoolean configured;
@@ -276,6 +283,20 @@
}
}
+ public String getDiscoveryPluginParameters()
+ {
+ return unparsedDiscoveryPluginProperties;
+ }
+
+ public void setDiscoveryPluginProperties(final String config)
+ {
+ if(config != null)
+ {
+ this.unparsedDiscoveryPluginProperties = config;
+
raProperties.setParsedDiscoveryPluginParameters(Util.parseDiscoveryPluginConfig(config));
+ }
+ }
+
public Boolean getHA()
{
@@ -1447,6 +1468,8 @@
}
else if (discoveryAddress != null)
{
+ Map<String,Object> params = new HashMap<String,Object>();
+
Integer discoveryPort = overrideProperties.getDiscoveryPort() != null ?
overrideProperties.getDiscoveryPort()
:
getDiscoveryPort();
@@ -1455,8 +1478,6 @@
discoveryPort = HornetQClient.DEFAULT_DISCOVERY_PORT;
}
- DiscoveryGroupConfiguration groupConfiguration = new
DiscoveryGroupConfiguration(discoveryAddress, discoveryPort);
-
Long refreshTimeout = overrideProperties.getDiscoveryRefreshTimeout() != null ?
overrideProperties.getDiscoveryRefreshTimeout()
:
raProperties.getDiscoveryRefreshTimeout();
if (refreshTimeout == null)
@@ -1472,10 +1493,13 @@
initialTimeout = HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT;
}
- groupConfiguration.setDiscoveryInitialWaitTimeout(initialTimeout);
+ params.put(DiscoveryGroupConstants.GROUP_ADDRESS_NAME, discoveryAddress);
+ params.put(DiscoveryGroupConstants.GROUP_PORT_NAME, discoveryPort);
+ params.put(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME, refreshTimeout);
+ params.put(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME, initialTimeout);
- groupConfiguration.setRefreshTimeout(refreshTimeout);
-
+ DiscoveryGroupConfiguration groupConfiguration = new
DiscoveryGroupConfiguration(SimpleUDPServerLocatorImpl.class.getName(), params, null);
+
if (ha)
{
cf = HornetQJMSClient.createConnectionFactoryWithHA(groupConfiguration,
JMSFactoryType.XA_CF);
@@ -1485,6 +1509,25 @@
cf = HornetQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration,
JMSFactoryType.XA_CF);
}
}
+ else if (this.unparsedDiscoveryPluginProperties != null)
+ {
+ // for another discovery strategy
+ Map<String, Object> discoveryPluginParams =
+
overrideConnectionParameters(overrideProperties.getParsedDiscoveryPluginParameters(),raProperties.getParsedDiscoveryPluginParameters());
+
+ String serverLocatorClassName =
(String)discoveryPluginParams.get("server-locator-class");
+
+ DiscoveryGroupConfiguration groupConfiguration = new
DiscoveryGroupConfiguration(serverLocatorClassName, discoveryPluginParams, null);
+
+ if (ha)
+ {
+ cf = HornetQJMSClient.createConnectionFactoryWithHA(groupConfiguration,
JMSFactoryType.XA_CF);
+ }
+ else
+ {
+ cf = HornetQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration,
JMSFactoryType.XA_CF);
+ }
+ }
else
{
throw new IllegalArgumentException("must provide either TransportType or
DiscoveryGroupAddress and DiscoveryGroupPort for HornetQ ResourceAdapter Connection
Factory");
Modified:
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/Util.java
===================================================================
---
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/Util.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/Util.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -199,6 +199,27 @@
return hashtable;
}
+ public static Map<String, Object> parseDiscoveryPluginConfig(final String
config)
+ {
+ HashMap<String, Object> result = new HashMap<String, Object>();
+
+ String elements[] = config.split(";");
+
+ for (String element : elements)
+ {
+ String expression[] = element.split("=");
+
+ if (expression.length != 2)
+ {
+ throw new IllegalArgumentException("Invalid expression " + element
+ " at " + config);
+ }
+
+ result.put(expression[0].trim(), expression[1].trim());
+ }
+
+ return result;
+ }
+
public static List<Map<String, Object>> parseConfig(final String config)
{
List<Map<String, Object>> result =new ArrayList<Map<String,
Object>>();
Modified:
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/main/java/org/hornetq/rest/MessageServiceManager.java
===================================================================
---
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/main/java/org/hornetq/rest/MessageServiceManager.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/main/java/org/hornetq/rest/MessageServiceManager.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -2,9 +2,9 @@
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
-import org.hornetq.core.client.impl.ServerLocatorImpl;
import org.hornetq.core.registry.JndiBindingRegistry;
import org.hornetq.core.remoting.impl.invm.InVMConnectorFactory;
import org.hornetq.core.remoting.impl.invm.TransportConstants;
@@ -143,9 +143,8 @@
HashMap<String, Object> transportConfig = new HashMap<String,
Object>();
transportConfig.put(TransportConstants.SERVER_ID_PROP_NAME,
configuration.getInVmId());
+ ServerLocator consumerLocator = HornetQClient.createServerLocatorWithoutHA(new
TransportConfiguration[]{new TransportConfiguration(InVMConnectorFactory.class.getName(),
transportConfig)});
- ServerLocator consumerLocator = new ServerLocatorImpl(false, new
TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
-
if (configuration.getConsumerWindowSize() != -1)
{
consumerLocator.setConsumerWindowSize(configuration.getConsumerWindowSize());
@@ -153,7 +152,7 @@
ClientSessionFactory consumerSessionFactory =
consumerLocator.createSessionFactory();
- ServerLocator defaultLocator = new ServerLocatorImpl(false, new
TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
+ ServerLocator defaultLocator = HornetQClient.createServerLocatorWithoutHA(new
TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
ClientSessionFactory sessionFactory = defaultLocator.createSessionFactory();
Modified:
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/test/java/org/hornetq/rest/test/RawAckTest.java
===================================================================
---
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/test/java/org/hornetq/rest/test/RawAckTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/test/java/org/hornetq/rest/test/RawAckTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -9,8 +9,8 @@
import org.hornetq.api.core.client.ClientProducer;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.core.client.ServerLocator;
-import org.hornetq.core.client.impl.ServerLocatorImpl;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory;
@@ -50,7 +50,7 @@
HashMap<String, Object> transportConfig = new HashMap<String,
Object>();
- serverLocator = new ServerLocatorImpl(false, new
TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
+ serverLocator = HornetQClient.createServerLocatorWithoutHA(new
TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
sessionFactory = serverLocator.createSessionFactory();
consumerSessionFactory = serverLocator.createSessionFactory();
Modified:
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/test/java/org/hornetq/rest/test/RawRestartTest.java
===================================================================
---
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/test/java/org/hornetq/rest/test/RawRestartTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/hornetq-rest/hornetq-rest/src/test/java/org/hornetq/rest/test/RawRestartTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -7,10 +7,10 @@
import org.hornetq.api.core.client.ClientProducer;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.core.client.MessageHandler;
import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
-import org.hornetq.core.client.impl.ServerLocatorImpl;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory;
@@ -57,7 +57,7 @@
private static void createFactories() throws Exception
{
HashMap<String, Object> transportConfig = new HashMap<String,
Object>();
- serverLocator = new ServerLocatorImpl(false, new
TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
+ serverLocator = HornetQClient.createServerLocatorWithoutHA(new
TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
sessionFactory = serverLocator.createSessionFactory();
consumerSessionFactory = serverLocator.createSessionFactory();
}
Modified: branches/HORNETQ-316/pom.xml
===================================================================
--- branches/HORNETQ-316/pom.xml 2011-08-25 05:25:43 UTC (rev 11224)
+++ branches/HORNETQ-316/pom.xml 2011-08-25 19:23:40 UTC (rev 11225)
@@ -133,6 +133,7 @@
<module>hornetq-service-sar</module>
<module>hornetq-spring-integration</module>
<module>hornetq-twitter-integration</module>
+ <module>hornetq-jgroups-discovery</module>
</modules>
<dependencyManagement>
@@ -245,6 +246,11 @@
<!-- there is a new version of this JAR but it breaks our usage of it
-->
<version>2.1.2</version>
</dependency>
+ <dependency>
+ <groupId>org.jgroups</groupId>
+ <artifactId>jgroups</artifactId>
+ <version>2.12.1.Final</version>
+ </dependency>
<!--needed to compile the spring support-->
<dependency>
<groupId>org.springframework</groupId>
Added: branches/HORNETQ-316/tests/config/test-jgroups-file_ping.xml
===================================================================
--- branches/HORNETQ-316/tests/config/test-jgroups-file_ping.xml
(rev 0)
+++ branches/HORNETQ-316/tests/config/test-jgroups-file_ping.xml 2011-08-25 19:23:40 UTC
(rev 11225)
@@ -0,0 +1,53 @@
+<config xmlns="urn:org:jgroups"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:org:jgroups file:schema/JGroups-2.8.xsd">
+ <TCP loopback="true"
+ recv_buf_size="20000000"
+ send_buf_size="640000"
+ discard_incompatible_packets="true"
+ max_bundle_size="64000"
+ max_bundle_timeout="30"
+ enable_bundling="true"
+ use_send_queues="false"
+ sock_conn_timeout="300"
+ skip_suspected_members="true"
+
+ thread_pool.enabled="true"
+ thread_pool.min_threads="1"
+ thread_pool.max_threads="10"
+ thread_pool.keep_alive_time="5000"
+ thread_pool.queue_enabled="false"
+ thread_pool.queue_max_size="100"
+ thread_pool.rejection_policy="run"
+
+ oob_thread_pool.enabled="true"
+ oob_thread_pool.min_threads="1"
+ oob_thread_pool.max_threads="8"
+ oob_thread_pool.keep_alive_time="5000"
+ oob_thread_pool.queue_enabled="false"
+ oob_thread_pool.queue_max_size="100"
+ oob_thread_pool.rejection_policy="run"/>
+
+ <FILE_PING location="file_ping_dir"/>
+ <MERGE2 max_interval="30000"
+ min_interval="10000"/>
+ <FD_SOCK/>
+ <FD timeout="10000" max_tries="5" />
+ <VERIFY_SUSPECT timeout="1500" />
+ <BARRIER />
+ <pbcast.NAKACK
+ use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200" />
+ <pbcast.STABLE stability_delay="1000"
desired_avg_gossip="50000"
+ max_bytes="400000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="3000"
+
+ view_bundling="true"/>
+ <FC max_credits="2000000"
+ min_threshold="0.10"/>
+ <FRAG2 frag_size="60000" />
+ <pbcast.STREAMING_STATE_TRANSFER/>
+ <pbcast.FLUSH timeout="0"/>
+</config>
Added: branches/HORNETQ-316/tests/config/test-jgroups-file_ping_2.xml
===================================================================
--- branches/HORNETQ-316/tests/config/test-jgroups-file_ping_2.xml
(rev 0)
+++ branches/HORNETQ-316/tests/config/test-jgroups-file_ping_2.xml 2011-08-25 19:23:40 UTC
(rev 11225)
@@ -0,0 +1,53 @@
+<config xmlns="urn:org:jgroups"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:org:jgroups file:schema/JGroups-2.8.xsd">
+ <TCP loopback="true"
+ recv_buf_size="20000000"
+ send_buf_size="640000"
+ discard_incompatible_packets="true"
+ max_bundle_size="64000"
+ max_bundle_timeout="30"
+ enable_bundling="true"
+ use_send_queues="false"
+ sock_conn_timeout="300"
+ skip_suspected_members="true"
+
+ thread_pool.enabled="true"
+ thread_pool.min_threads="1"
+ thread_pool.max_threads="10"
+ thread_pool.keep_alive_time="5000"
+ thread_pool.queue_enabled="false"
+ thread_pool.queue_max_size="100"
+ thread_pool.rejection_policy="run"
+
+ oob_thread_pool.enabled="true"
+ oob_thread_pool.min_threads="1"
+ oob_thread_pool.max_threads="8"
+ oob_thread_pool.keep_alive_time="5000"
+ oob_thread_pool.queue_enabled="false"
+ oob_thread_pool.queue_max_size="100"
+ oob_thread_pool.rejection_policy="run"/>
+
+ <FILE_PING location="file_ping_dir_2"/>
+ <MERGE2 max_interval="30000"
+ min_interval="10000"/>
+ <FD_SOCK/>
+ <FD timeout="10000" max_tries="5" />
+ <VERIFY_SUSPECT timeout="1500" />
+ <BARRIER />
+ <pbcast.NAKACK
+ use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200" />
+ <pbcast.STABLE stability_delay="1000"
desired_avg_gossip="50000"
+ max_bytes="400000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="3000"
+
+ view_bundling="true"/>
+ <FC max_credits="2000000"
+ min_threshold="0.10"/>
+ <FRAG2 frag_size="60000" />
+ <pbcast.STREAMING_STATE_TRANSFER/>
+ <pbcast.FLUSH timeout="0"/>
+</config>
Added: branches/HORNETQ-316/tests/config/test-jgroups-file_ping_3.xml
===================================================================
--- branches/HORNETQ-316/tests/config/test-jgroups-file_ping_3.xml
(rev 0)
+++ branches/HORNETQ-316/tests/config/test-jgroups-file_ping_3.xml 2011-08-25 19:23:40 UTC
(rev 11225)
@@ -0,0 +1,53 @@
+<config xmlns="urn:org:jgroups"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:org:jgroups file:schema/JGroups-2.8.xsd">
+ <TCP loopback="true"
+ recv_buf_size="20000000"
+ send_buf_size="640000"
+ discard_incompatible_packets="true"
+ max_bundle_size="64000"
+ max_bundle_timeout="30"
+ enable_bundling="true"
+ use_send_queues="false"
+ sock_conn_timeout="300"
+ skip_suspected_members="true"
+
+ thread_pool.enabled="true"
+ thread_pool.min_threads="1"
+ thread_pool.max_threads="10"
+ thread_pool.keep_alive_time="5000"
+ thread_pool.queue_enabled="false"
+ thread_pool.queue_max_size="100"
+ thread_pool.rejection_policy="run"
+
+ oob_thread_pool.enabled="true"
+ oob_thread_pool.min_threads="1"
+ oob_thread_pool.max_threads="8"
+ oob_thread_pool.keep_alive_time="5000"
+ oob_thread_pool.queue_enabled="false"
+ oob_thread_pool.queue_max_size="100"
+ oob_thread_pool.rejection_policy="run"/>
+
+ <FILE_PING location="file_ping_dir_3"/>
+ <MERGE2 max_interval="30000"
+ min_interval="10000"/>
+ <FD_SOCK/>
+ <FD timeout="10000" max_tries="5" />
+ <VERIFY_SUSPECT timeout="1500" />
+ <BARRIER />
+ <pbcast.NAKACK
+ use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200" />
+ <pbcast.STABLE stability_delay="1000"
desired_avg_gossip="50000"
+ max_bytes="400000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="3000"
+
+ view_bundling="true"/>
+ <FC max_credits="2000000"
+ min_threshold="0.10"/>
+ <FRAG2 frag_size="60000" />
+ <pbcast.STREAMING_STATE_TRANSFER/>
+ <pbcast.FLUSH timeout="0"/>
+</config>
Modified: branches/HORNETQ-316/tests/integration-tests/pom.xml
===================================================================
--- branches/HORNETQ-316/tests/integration-tests/pom.xml 2011-08-25 05:25:43 UTC (rev
11224)
+++ branches/HORNETQ-316/tests/integration-tests/pom.xml 2011-08-25 19:23:40 UTC (rev
11225)
@@ -64,6 +64,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-jgroups-discovery</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.jboss.javaee</groupId>
<artifactId>jboss-jca-api</artifactId>
</dependency>
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionFactoryTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionFactoryTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionFactoryTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -50,7 +50,7 @@
{
private static final Logger log = Logger.getLogger(SessionFactoryTest.class);
- private DiscoveryGroupConfiguration groupConfiguration = new
DiscoveryGroupConfiguration(getUDPDiscoveryAddress(), getUDPDiscoveryPort());
+ private DiscoveryGroupConfiguration groupConfiguration =
createSimpleUDPDiscoveryGroupConfiguration(getUDPDiscoveryAddress(),
getUDPDiscoveryPort());
private HornetQServer liveService;
@@ -160,7 +160,7 @@
assertFactoryParams(locator,
tc,
- null,
+ locator.getDiscoveryGroupConfiguration(),
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
HornetQClient.DEFAULT_CONNECTION_TTL,
HornetQClient.DEFAULT_CALL_TIMEOUT,
@@ -581,13 +581,13 @@
final int localBindPort = 5432;
- BroadcastGroupConfiguration bcConfig1 = new
BroadcastGroupConfiguration(bcGroupName,
- null,
-
localBindPort,
-
getUDPDiscoveryAddress(),
-
getUDPDiscoveryPort(),
-
broadcastPeriod,
-
Arrays.asList(liveTC.getName()));
+ BroadcastGroupConfiguration bcConfig1 =
createBroadcastGroupConfiguration(bcGroupName,
+ null,
+
localBindPort,
+
getUDPDiscoveryAddress(),
+
getUDPDiscoveryPort(),
+
broadcastPeriod,
+
Arrays.asList(liveTC));
List<BroadcastGroupConfiguration> bcConfigs1 = new
ArrayList<BroadcastGroupConfiguration>();
bcConfigs1.add(bcConfig1);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeReconnectTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeReconnectTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeReconnectTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -20,6 +20,7 @@
import junit.framework.Assert;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.SimpleString;
@@ -110,8 +111,8 @@
final int reconnectAttempts = 1;
final int confirmationWindowSize = 1024;
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf = createStaticDiscoveryGroupConfiguration(new
TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
queueName0,
@@ -124,7 +125,7 @@
false,
confirmationWindowSize,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -252,8 +253,8 @@
final int reconnectAttempts = 3;
final int confirmationWindowSize = 1024;
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf = createStaticDiscoveryGroupConfiguration(new
TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
queueName0,
@@ -266,7 +267,7 @@
false,
confirmationWindowSize,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -378,9 +379,9 @@
final int reconnectAttempts = 3;
final int confirmationWindowSize = 1024;
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
-
+ DiscoveryGroupConfiguration groupConf = createStaticDiscoveryGroupConfiguration(new
TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
queueName0,
forwardAddress,
@@ -392,7 +393,7 @@
false,
confirmationWindowSize,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -519,8 +520,8 @@
final int confirmationWindowSize = 1024;
final long clientFailureCheckPeriod = 1000;
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf = createStaticDiscoveryGroupConfiguration(new
TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
queueName0,
@@ -533,7 +534,7 @@
false,
confirmationWindowSize,
clientFailureCheckPeriod,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -653,8 +654,8 @@
final int reconnectAttempts = 3;
final int confirmationWindowSize = 1024;
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf = createStaticDiscoveryGroupConfiguration(new
TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
queueName0,
@@ -667,7 +668,7 @@
false,
confirmationWindowSize,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeStartTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeStartTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeStartTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -20,6 +20,7 @@
import junit.framework.Assert;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
@@ -94,8 +95,8 @@
server0.getConfiguration().setConnectorConfigurations(connectors);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
final String bridgeName = "bridge1";
@@ -110,7 +111,7 @@
true,
1024,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -257,8 +258,8 @@
server0.getConfiguration().setConnectorConfigurations(connectors);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf = createStaticDiscoveryGroupConfiguration(new
TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
final String bridgeName = "bridge1";
@@ -273,7 +274,7 @@
true,
1024,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -468,8 +469,8 @@
server0.getConfiguration().setConnectorConfigurations(connectors);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
final String bridgeName = "bridge1";
@@ -484,7 +485,7 @@
false,
1024,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -619,8 +620,8 @@
server0.getConfiguration().setConnectorConfigurations(connectors);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
final String bridgeName = "bridge1";
@@ -635,7 +636,7 @@
true,
1024,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -20,6 +20,7 @@
import junit.framework.Assert;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientConsumer;
@@ -128,8 +129,9 @@
final int numMessages = 10;
- ArrayList<String> connectorConfig = new ArrayList<String>();
- connectorConfig.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+
BridgeConfiguration bridgeConfiguration = new
BridgeConfiguration("bridge1",
queueName0,
forwardAddress,
@@ -143,7 +145,7 @@
// are sent
numMessages *
messageSize / 2,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
connectorConfig,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -328,8 +330,9 @@
final String filterString = "animal='goat'";
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+
BridgeConfiguration bridgeConfiguration = new
BridgeConfiguration("bridge1",
queueName0,
forwardAddress,
@@ -341,7 +344,7 @@
false,
1024,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -499,8 +502,9 @@
server0.getConfiguration().setConnectorConfigurations(connectors);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+
BridgeConfiguration bridgeConfiguration = new
BridgeConfiguration("bridge1",
queueName0,
forwardAddress,
@@ -512,7 +516,7 @@
false,
1024,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -654,8 +658,9 @@
server0.getConfiguration().setConnectorConfigurations(connectors);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+
BridgeConfiguration bridgeConfiguration = new
BridgeConfiguration("bridge1",
queueName0,
forwardAddress,
@@ -667,7 +672,7 @@
true,
0,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -841,8 +846,8 @@
server0.getConfiguration().setConnectorConfigurations(connectors);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf = createStaticDiscoveryGroupConfiguration(new
TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
BridgeConfiguration bridgeConfiguration = new
BridgeConfiguration("bridge1",
queueName0,
@@ -855,7 +860,7 @@
false,
1024,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -998,8 +1003,8 @@
server0.getConfiguration().setConnectorConfigurations(connectors);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
BridgeConfiguration bridgeConfiguration = new
BridgeConfiguration("bridge1",
queueName0,
@@ -1012,7 +1017,7 @@
false,
1024,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -1139,8 +1144,8 @@
final int numMessages = 10;
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
BridgeConfiguration bridgeConfiguration = new
BridgeConfiguration("bridge1", queueName0, null, // pass a null
// forwarding
// address to
@@ -1157,7 +1162,7 @@
// are sent
numMessages *
messageSize / 2,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -91,26 +91,28 @@
final int port = getUDPDiscoveryPort();
- ArrayList<String> list = new ArrayList<String>();
- list.add(server1tc.getName());
- BroadcastGroupConfiguration bcConfig = new
BroadcastGroupConfiguration("bg1",
- null,
- -1,
-
groupAddress,
- port,
- 250,
- list);
+ ArrayList<TransportConfiguration> list = new
ArrayList<TransportConfiguration>();
+ list.add(server1tc);
+ BroadcastGroupConfiguration bcConfig =
createBroadcastGroupConfiguration("bg1",
+ null,
+
-1,
+
groupAddress,
+ port,
+
250,
+ list);
server0.getConfiguration().getBroadcastGroupConfigurations().add(bcConfig);
- DiscoveryGroupConfiguration dcConfig = new
DiscoveryGroupConfiguration("dg1", null, groupAddress, port, 5000, 5000);
+ DiscoveryGroupConfiguration dcConfig =
createSimpleUDPDiscoveryGroupConfiguration("dg1", null, groupAddress, port,
5000, 5000);
server0.getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig.getName(),
dcConfig);
final String bridgeName = "bridge1";
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[]{server1tc});
+
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
queueName0,
forwardAddress,
@@ -122,7 +124,7 @@
true,
1024,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
-
staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeWithPagingTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeWithPagingTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeWithPagingTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -20,6 +20,7 @@
import junit.framework.Assert;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.SimpleString;
@@ -106,8 +107,9 @@
final int confirmationWindowSize = 1024; // 1 kiB
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(server1tc.getName());
+ DiscoveryGroupConfiguration groupConf = createStaticDiscoveryGroupConfiguration(new
TransportConfiguration[]{server1tc});
+
server0.getConfiguration().getDiscoveryGroupConfigurations().put("server1tc-static",
groupConf);
+
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
queueName0,
forwardAddress,
@@ -119,7 +121,7 @@
false,
confirmationWindowSize,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
- staticConnectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -1485,20 +1485,20 @@
TransportConfiguration connector = createTransportConfiguration(netty, false,
params);
configuration.getConnectorConfigurations().put(connector.getName(), connector);
- List<String> connectorPairs = new ArrayList<String>();
- connectorPairs.add(connector.getName());
+ List<TransportConfiguration> connectorPairs = new
ArrayList<TransportConfiguration>();
+ connectorPairs.add(connector);
- BroadcastGroupConfiguration bcConfig = new
BroadcastGroupConfiguration("bg1",
- null,
- -1,
-
groupAddress,
- port,
- 1000,
-
connectorPairs);
+ BroadcastGroupConfiguration bcConfig =
createBroadcastGroupConfiguration("bg1",
+ null,
+
-1,
+
groupAddress,
+ port,
+
1000,
+
connectorPairs);
configuration.getBroadcastGroupConfigurations().add(bcConfig);
- DiscoveryGroupConfiguration dcConfig = new
DiscoveryGroupConfiguration("dg1", null, groupAddress, port, 5000, 5000);
+ DiscoveryGroupConfiguration dcConfig =
createSimpleUDPDiscoveryGroupConfiguration("dg1", null, groupAddress, port,
5000, 5000);
configuration.getDiscoveryGroupConfigurations().put(dcConfig.getName(),
dcConfig);
@@ -1572,20 +1572,20 @@
TransportConfiguration connector = createTransportConfiguration(netty, false,
params);
configuration.getConnectorConfigurations().put(connector.getName(), connector);
- List<String> connectorPairs = new ArrayList<String>();
- connectorPairs.add(connector.getName());
+ List<TransportConfiguration> connectorPairs = new
ArrayList<TransportConfiguration>();
+ connectorPairs.add(connector);
- BroadcastGroupConfiguration bcConfig = new
BroadcastGroupConfiguration("bg1",
- null,
- -1,
-
groupAddress,
- port,
- 1000,
-
connectorPairs);
+ BroadcastGroupConfiguration bcConfig =
createBroadcastGroupConfiguration("bg1",
+ null,
+
-1,
+
groupAddress,
+ port,
+
1000,
+
connectorPairs);
configuration.getBroadcastGroupConfigurations().add(bcConfig);
- DiscoveryGroupConfiguration dcConfig = new
DiscoveryGroupConfiguration("dg1", null, groupAddress, port, 5000, 5000);
+ DiscoveryGroupConfiguration dcConfig =
createSimpleUDPDiscoveryGroupConfiguration("dg1", null, groupAddress, port,
5000, 5000);
configuration.getDiscoveryGroupConfigurations().put(dcConfig.getName(),
dcConfig);
@@ -1656,17 +1656,20 @@
TransportConfiguration connectorFrom = createTransportConfiguration(netty, false,
generateParams(nodeFrom, netty));
serverFrom.getConfiguration().getConnectorConfigurations().put(name,
connectorFrom);
- List<String> pairs = null;
+ List<TransportConfiguration> pairs = null;
if (nodeTo != -1)
{
TransportConfiguration serverTotc = createTransportConfiguration(netty, false,
generateParams(nodeTo, netty));
serverFrom.getConfiguration().getConnectorConfigurations().put(serverTotc.getName(),
serverTotc);
- pairs = new ArrayList<String>();
- pairs.add(serverTotc.getName());
+ pairs = new ArrayList<TransportConfiguration>();
+ pairs.add(serverTotc);
}
- ClusterConnectionConfiguration clusterConf = new
ClusterConnectionConfiguration(name,
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(pairs!=null ? pairs.toArray(new
TransportConfiguration[0]) : null);
+
serverFrom.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+
+ ClusterConnectionConfiguration clusterConf = new
ClusterConnectionConfiguration(name,
address,
name,
100,
@@ -1674,7 +1677,7 @@
forwardWhenNoConsumers,
maxHops,
1024,
-
pairs, allowDirectConnectionsOnly);
+
groupConf, allowDirectConnectionsOnly);
serverFrom.getConfiguration().getClusterConfigurations().add(clusterConf);
}
@@ -1697,15 +1700,18 @@
TransportConfiguration connectorFrom = createTransportConfiguration(netty, false,
generateParams(nodeFrom, netty));
serverFrom.getConfiguration().getConnectorConfigurations().put(connectorFrom.getName(),
connectorFrom);
- List<String> pairs = new ArrayList<String>();
+ List<TransportConfiguration> pairs = new
ArrayList<TransportConfiguration>();
for (int element : nodesTo)
{
TransportConfiguration serverTotc = createTransportConfiguration(netty, false,
generateParams(element, netty));
serverFrom.getConfiguration().getConnectorConfigurations().put(serverTotc.getName(),
serverTotc);
- pairs.add(serverTotc.getName());
+ pairs.add(serverTotc);
}
- ClusterConnectionConfiguration clusterConf = new
ClusterConnectionConfiguration(name,
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(pairs.toArray(new TransportConfiguration[0]));
+
serverFrom.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+
+ ClusterConnectionConfiguration clusterConf = new
ClusterConnectionConfiguration(name,
address,
connectorFrom.getName(),
250,
@@ -1713,7 +1719,7 @@
forwardWhenNoConsumers,
maxHops,
1024,
-
pairs, false);
+
groupConf, false);
serverFrom.getConfiguration().getClusterConfigurations().add(clusterConf);
}
@@ -1736,15 +1742,18 @@
TransportConfiguration connectorFrom = createTransportConfiguration(netty, false,
generateParams(nodeFrom, netty));
serverFrom.getConfiguration().getConnectorConfigurations().put(name,
connectorFrom);
- List<String> pairs = new ArrayList<String>();
+ List<TransportConfiguration> pairs = new
ArrayList<TransportConfiguration>();
for (int element : nodesTo)
{
TransportConfiguration serverTotc = createTransportConfiguration(netty, false,
generateParams(element, netty));
serverFrom.getConfiguration().getConnectorConfigurations().put(serverTotc.getName(),
serverTotc);
- pairs.add(serverTotc.getName());
+ pairs.add(serverTotc);
}
- ClusterConnectionConfiguration clusterConf = new
ClusterConnectionConfiguration(name,
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(pairs.toArray(new TransportConfiguration[0]));
+
serverFrom.getConfiguration().getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+
+ ClusterConnectionConfiguration clusterConf = new
ClusterConnectionConfiguration(name,
address,
name,
250,
@@ -1752,7 +1761,7 @@
forwardWhenNoConsumers,
maxHops,
1024,
-
pairs, false);
+
groupConf, false);
serverFrom.getConfiguration().getClusterConfigurations().add(clusterConf);
}
@@ -1783,7 +1792,9 @@
forwardWhenNoConsumers,
maxHops,
1024,
-
discoveryGroupName);
+
server.getConfiguration().getDiscoveryGroupConfigurations().get(discoveryGroupName),
+
false);
+
List<ClusterConnectionConfiguration> clusterConfs =
server.getConfiguration().getClusterConfigurations();
clusterConfs.add(clusterConf);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackAutoTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackAutoTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackAutoTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -16,6 +16,7 @@
import junit.framework.Assert;
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.SimpleString;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.*;
import org.hornetq.core.client.impl.ClientSessionFactoryInternal;
@@ -208,10 +209,10 @@
TransportConfiguration backupConnector =
getConnectorTransportConfiguration(false);
backupConfig.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
backupConfig.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(liveConnector.getName());
+ DiscoveryGroupConfiguration liveGroup =
createStaticDiscoveryGroupConfiguration(liveConnector);
+ backupConfig.getDiscoveryGroupConfigurations().put(liveGroup.getName(),
liveGroup);
ClusterConnectionConfiguration cccLive = new
ClusterConnectionConfiguration("cluster1", "jms",
backupConnector.getName(), -1, false, false, 1, 1,
- staticConnectors, false);
+ liveGroup, false);
backupConfig.getClusterConfigurations().add(cccLive);
backupServer = createBackupServer();
@@ -221,10 +222,10 @@
liveConfig.setSecurityEnabled(false);
liveConfig.setSharedStore(true);
liveConfig.setClustered(true);
- List<String> pairs = new ArrayList<String>();
- pairs.add(backupConnector.getName());
+ DiscoveryGroupConfiguration buGroup =
createStaticDiscoveryGroupConfiguration(backupConnector);
+ liveConfig.getDiscoveryGroupConfigurations().put(buGroup.getName(), buGroup);
ClusterConnectionConfiguration ccc0 = new
ClusterConnectionConfiguration("cluster1", "jms",
liveConnector.getName(), -1, false, false, 1, 1,
- pairs, false);
+ buGroup, false);
liveConfig.getClusterConfigurations().add(ccc0);
liveConfig.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
liveConfig.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackManualTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackManualTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailBackManualTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -14,6 +14,8 @@
package org.hornetq.tests.integration.cluster.failover;
import junit.framework.Assert;
+
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
@@ -148,10 +150,10 @@
TransportConfiguration backupConnector =
getConnectorTransportConfiguration(false);
backupConfig.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
backupConfig.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(liveConnector.getName());
+ DiscoveryGroupConfiguration liveGroup =
createStaticDiscoveryGroupConfiguration(liveConnector);
+ backupConfig.getDiscoveryGroupConfigurations().put(liveGroup.getName(),
liveGroup);
ClusterConnectionConfiguration cccLive = new
ClusterConnectionConfiguration("cluster1", "jms",
backupConnector.getName(), -1, false, false, 1, 1,
- staticConnectors, false);
+ liveGroup, false);
backupConfig.getClusterConfigurations().add(cccLive);
backupConfig.setAllowAutoFailBack(false);
backupServer = createBackupServer();
@@ -162,10 +164,11 @@
liveConfig.setSecurityEnabled(false);
liveConfig.setSharedStore(true);
liveConfig.setClustered(true);
- List<String> pairs = new ArrayList<String>();
- pairs.add(backupConnector.getName());
+ DiscoveryGroupConfiguration buGroup =
createStaticDiscoveryGroupConfiguration(backupConnector);
+ liveConfig.getDiscoveryGroupConfigurations().put(buGroup.getName(), buGroup);
+
ClusterConnectionConfiguration ccc0 = new
ClusterConnectionConfiguration("cluster1", "jms",
liveConnector.getName(), -1, false, false, 1, 1,
- pairs, false);
+ buGroup, false);
liveConfig.getClusterConfigurations().add(ccc0);
liveConfig.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
liveConfig.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailoverTestBase.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailoverTestBase.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/FailoverTestBase.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -28,6 +28,7 @@
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ClusterTopologyListener;
import org.hornetq.api.core.client.HornetQClient;
@@ -134,10 +135,11 @@
TransportConfiguration backupConnector =
getConnectorTransportConfiguration(false);
backupConfig.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
backupConfig.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(liveConnector.getName());
+ DiscoveryGroupConfiguration liveGroup =
createStaticDiscoveryGroupConfiguration(liveConnector);
+ backupConfig.getDiscoveryGroupConfigurations().put(liveGroup.getName(),
liveGroup);
+
ClusterConnectionConfiguration cccLive = new
ClusterConnectionConfiguration("cluster1", "jms",
backupConnector.getName(), -1, false, false, 1, 1,
- staticConnectors, false);
+ liveGroup, false);
backupConfig.getClusterConfigurations().add(cccLive);
backupServer = createBackupServer();
@@ -147,9 +149,8 @@
liveConfig.setSecurityEnabled(false);
liveConfig.setSharedStore(true);
liveConfig.setClustered(true);
- List<String> pairs = null;
ClusterConnectionConfiguration ccc0 = new
ClusterConnectionConfiguration("cluster1", "jms",
liveConnector.getName(), -1, false, false, 1, 1,
- pairs, false);
+ null, false);
liveConfig.getClusterConfigurations().add(ccc0);
liveConfig.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
liveServer = createLiveServer();
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -32,8 +32,9 @@
import org.hornetq.api.core.client.ClusterTopologyListener;
import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.core.client.impl.ClientSessionFactoryInternal;
-import org.hornetq.core.client.impl.ServerLocatorImpl;
+import org.hornetq.core.client.impl.AbstractServerLocator;
import org.hornetq.core.client.impl.ServerLocatorInternal;
+import org.hornetq.core.client.impl.StaticServerLocatorImpl;
import org.hornetq.jms.client.HornetQTextMessage;
import org.hornetq.tests.integration.cluster.util.TestableServer;
import org.hornetq.tests.util.ServiceTestBase;
@@ -189,7 +190,7 @@
{
configs[i] = createTransportConfiguration(isNetty(), false,
generateParams(nodes[i], isNetty()));
}
- return new ServerLocatorImpl(true, configs);
+ return new StaticServerLocatorImpl(true,
createStaticDiscoveryGroupConfiguration(configs));
}
// Private -------------------------------------------------------
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/MultipleLivesMultipleBackupsFailoverTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/MultipleLivesMultipleBackupsFailoverTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/MultipleLivesMultipleBackupsFailoverTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -18,6 +18,7 @@
import java.util.List;
import java.util.Map;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ServerLocator;
@@ -142,14 +143,16 @@
TransportConfiguration backupConnector = createTransportConfiguration(isNetty(),
false, generateParams(nodeid, isNetty()));
config1.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
- List<String> clusterNodes = new ArrayList<String>();
+ List<TransportConfiguration> clusterNodes = new
ArrayList<TransportConfiguration>();
for (int node : otherClusterNodes)
{
TransportConfiguration connector = createTransportConfiguration(isNetty(),
false, generateParams(node, isNetty()));
config1.getConnectorConfigurations().put(connector.getName(), connector);
- clusterNodes.add(connector.getName());
+ clusterNodes.add(connector);
}
- ClusterConnectionConfiguration ccc1 = new
ClusterConnectionConfiguration("cluster1", "jms",
backupConnector.getName(), -1, false, false, 1, 1, clusterNodes, false);
+ DiscoveryGroupConfiguration nodeConf =
createStaticDiscoveryGroupConfiguration(clusterNodes.toArray(new
TransportConfiguration[0]));
+ config1.getDiscoveryGroupConfigurations().put(nodeConf.getName(), nodeConf);
+ ClusterConnectionConfiguration ccc1 = new
ClusterConnectionConfiguration("cluster1", "jms",
backupConnector.getName(), -1, false, false, 1, 1, nodeConf, false);
config1.getClusterConfigurations().add(ccc1);
config1.setBindingsDirectory(config1.getBindingsDirectory() + "_" +
liveNode);
@@ -169,16 +172,18 @@
config0.setSecurityEnabled(false);
config0.setSharedStore(true);
config0.setClustered(true);
- List<String> pairs = new ArrayList<String>();
+ List<TransportConfiguration> pairs = new
ArrayList<TransportConfiguration>();
for (int node : otherLiveNodes)
{
TransportConfiguration otherLiveConnector =
createTransportConfiguration(isNetty(), false, generateParams(node, isNetty()));
config0.getConnectorConfigurations().put(otherLiveConnector.getName(),
otherLiveConnector);
- pairs.add(otherLiveConnector.getName());
+ pairs.add(otherLiveConnector);
}
+ DiscoveryGroupConfiguration nodeConf =
createStaticDiscoveryGroupConfiguration(pairs.toArray(new TransportConfiguration[0]));
+ config0.getDiscoveryGroupConfigurations().put(nodeConf.getName(), nodeConf);
ClusterConnectionConfiguration ccc0 = new
ClusterConnectionConfiguration("cluster1", "jms",
liveConnector.getName(), -1, false, false, 1, 1,
- pairs, false);
+ nodeConf, false);
config0.getClusterConfigurations().add(ccc0);
config0.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteFailoverTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteFailoverTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteFailoverTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.Map;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.core.config.ClusterConnectionConfiguration;
import org.hornetq.core.config.Configuration;
@@ -55,6 +56,8 @@
config.setClustered(true);
config.getConnectorConfigurations().put("self",
createTransportConfiguration(true,
false, generateParams(0, true)));
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[0]);
+ config.getDiscoveryGroupConfigurations().put(groupConf.getName(), groupConf);
config.getClusterConfigurations().add(new
ClusterConnectionConfiguration("cluster",
"foo",
"self",
@@ -63,7 +66,7 @@
false,
1,
1,
- new
ArrayList<String>(), false));
+
groupConf, false));
return config;
}
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteMultipleLivesMultipleBackupsFailoverTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteMultipleLivesMultipleBackupsFailoverTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteMultipleLivesMultipleBackupsFailoverTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -18,6 +18,7 @@
import java.util.List;
import java.util.Map;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.core.config.ClusterConnectionConfiguration;
import org.hornetq.core.config.Configuration;
@@ -167,14 +168,16 @@
TransportConfiguration backupConnector = createTransportConfiguration(true, false,
generateParams(nodeid, true));
config1.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
- List<String> clusterNodes = new ArrayList<String>();
+ List<TransportConfiguration> clusterNodes = new
ArrayList<TransportConfiguration>();
for (int node : otherClusterNodes)
{
TransportConfiguration connector = createTransportConfiguration(true, false,
generateParams(node, true));
config1.getConnectorConfigurations().put(connector.getName(), connector);
- clusterNodes.add(connector.getName());
+ clusterNodes.add(connector);
}
- ClusterConnectionConfiguration ccc1 = new
ClusterConnectionConfiguration("cluster1", "jms",
backupConnector.getName(), -1, false, false, 1, 1, clusterNodes, false);
+ DiscoveryGroupConfiguration nodeConf =
createStaticDiscoveryGroupConfiguration(clusterNodes.toArray(new
TransportConfiguration[0]));
+ config1.getDiscoveryGroupConfigurations().put(nodeConf.getName(), nodeConf);
+ ClusterConnectionConfiguration ccc1 = new
ClusterConnectionConfiguration("cluster1", "jms",
backupConnector.getName(), -1, false, false, 1, 1, nodeConf, false);
config1.getClusterConfigurations().add(ccc1);
@@ -197,16 +200,18 @@
config0.setSharedStore(true);
config0.setJournalType(JournalType.NIO);
config0.setClustered(true);
- List<String> pairs = new ArrayList<String>();
+ List<TransportConfiguration> pairs = new
ArrayList<TransportConfiguration>();
for (int node : otherLiveNodes)
{
TransportConfiguration otherLiveConnector = createTransportConfiguration(true,
false, generateParams(node, true));
config0.getConnectorConfigurations().put(otherLiveConnector.getName(),
otherLiveConnector);
- pairs.add(otherLiveConnector.getName());
+ pairs.add(otherLiveConnector);
}
+ DiscoveryGroupConfiguration nodeConf =
createStaticDiscoveryGroupConfiguration(pairs.toArray(new TransportConfiguration[0]));
+ config0.getDiscoveryGroupConfigurations().put(nodeConf.getName(), nodeConf);
ClusterConnectionConfiguration ccc0 = new
ClusterConnectionConfiguration("cluster1", "jms",
liveConnector.getName(), -1, false, false, 1, 1,
- pairs, false);
+ nodeConf, false);
config0.getClusterConfigurations().add(ccc0);
config0.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteSingleLiveMultipleBackupsFailoverTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteSingleLiveMultipleBackupsFailoverTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/RemoteSingleLiveMultipleBackupsFailoverTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -18,6 +18,7 @@
import java.util.List;
import java.util.Map;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ServerLocator;
@@ -177,16 +178,18 @@
config0.setSharedStore(true);
config0.setJournalType(JournalType.NIO);
config0.setClustered(true);
- List<String> pairs = new ArrayList<String>();
+ List<TransportConfiguration> pairs = new
ArrayList<TransportConfiguration>();
for (int node : otherLiveNodes)
{
TransportConfiguration otherLiveConnector =
createTransportConfiguration(true,
false,
generateParams(node, true));
config0.getConnectorConfigurations().put(otherLiveConnector.getName(),
otherLiveConnector);
- pairs.add(otherLiveConnector.getName());
+ pairs.add(otherLiveConnector);
}
+ DiscoveryGroupConfiguration nodeConf =
createStaticDiscoveryGroupConfiguration(pairs.toArray(new TransportConfiguration[0]));
+ config0.getDiscoveryGroupConfigurations().put(nodeConf.getName(), nodeConf);
ClusterConnectionConfiguration ccc0 = new
ClusterConnectionConfiguration("cluster1",
"jms",
liveConnector.getName(),
@@ -195,7 +198,7 @@
false,
1,
1,
- pairs,
+
nodeConf,
false);
config0.getClusterConfigurations().add(ccc0);
config0.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
@@ -275,16 +278,18 @@
config1.setBackup(true);
config1.setJournalType(JournalType.NIO);
config1.setClustered(true);
- List<String> staticConnectors = new ArrayList<String>();
+ List<TransportConfiguration> staticConnectors = new
ArrayList<TransportConfiguration>();
for (int node : nodes)
{
TransportConfiguration liveConnector = createTransportConfiguration(true, false,
generateParams(node, true));
config1.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
- staticConnectors.add(liveConnector.getName());
+ staticConnectors.add(liveConnector);
}
TransportConfiguration backupConnector = createTransportConfiguration(true, false,
generateParams(nodeid, true));
List<String> pairs = null;
+ DiscoveryGroupConfiguration nodeConf =
createStaticDiscoveryGroupConfiguration(createClusterConnections ?
staticConnectors.toArray(new TransportConfiguration[0]) : null);
+ config1.getDiscoveryGroupConfigurations().put(nodeConf.getName(), nodeConf);
ClusterConnectionConfiguration ccc1 = new
ClusterConnectionConfiguration("cluster1",
"jms",
backupConnector.getName(),
@@ -293,8 +298,7 @@
false,
1,
1,
-
createClusterConnections ? staticConnectors
-
: pairs,
+ nodeConf,
false);
config1.getClusterConfigurations().add(ccc1);
config1.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/SecurityFailoverTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/SecurityFailoverTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/SecurityFailoverTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -19,6 +19,7 @@
import java.util.Set;
import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ClientSessionFactory;
import org.hornetq.core.config.ClusterConnectionConfiguration;
@@ -112,8 +113,9 @@
TransportConfiguration backupConnector =
getConnectorTransportConfiguration(false);
backupConfig.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
backupConfig.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(liveConnector.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(liveConnector);
+ backupConfig.getDiscoveryGroupConfigurations().put(groupConf.getName(),
groupConf);
+
ClusterConnectionConfiguration cccLive = new
ClusterConnectionConfiguration("cluster1",
"jms",
backupConnector.getName(),
@@ -122,7 +124,7 @@
false,
1,
1,
-
staticConnectors,
+
groupConf,
false);
backupConfig.getClusterConfigurations().add(cccLive);
backupServer = createBackupServer();
@@ -137,7 +139,6 @@
liveConfig.setSecurityEnabled(true);
liveConfig.setSharedStore(true);
liveConfig.setClustered(true);
- List<String> pairs = null;
ClusterConnectionConfiguration ccc0 = new
ClusterConnectionConfiguration("cluster1",
"jms",
liveConnector.getName(),
@@ -146,7 +147,7 @@
false,
1,
1,
- pairs,
+ null,
false);
liveConfig.getClusterConfigurations().add(ccc0);
liveConfig.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -18,6 +18,7 @@
import java.util.List;
import java.util.Map;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ServerLocator;
@@ -107,16 +108,18 @@
config1.setSharedStore(true);
config1.setBackup(true);
config1.setClustered(true);
- List<String> staticConnectors = new ArrayList<String>();
+ List<TransportConfiguration> staticConnectors = new
ArrayList<TransportConfiguration>();
for (int node : nodes)
{
TransportConfiguration liveConnector = createTransportConfiguration(isNetty(),
false, generateParams(node, isNetty()));
config1.getConnectorConfigurations().put(liveConnector.getName(),
liveConnector);
- staticConnectors.add(liveConnector.getName());
+ staticConnectors.add(liveConnector);
}
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(staticConnectors.toArray(new
TransportConfiguration[0]));
+ config1.getDiscoveryGroupConfigurations().put(groupConf.getName(), groupConf);
TransportConfiguration backupConnector = createTransportConfiguration(isNetty(),
false, generateParams(nodeid, isNetty()));
- ClusterConnectionConfiguration ccc1 = new
ClusterConnectionConfiguration("cluster1", "jms",
backupConnector.getName(), -1, false, false, 1, 1, staticConnectors, false);
+ ClusterConnectionConfiguration ccc1 = new
ClusterConnectionConfiguration("cluster1", "jms",
backupConnector.getName(), -1, false, false, 1, 1, groupConf, false);
config1.getClusterConfigurations().add(ccc1);
config1.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
@@ -137,16 +140,18 @@
config0.setSecurityEnabled(false);
config0.setSharedStore(true);
config0.setClustered(true);
- List<String> pairs = null;
+ List<TransportConfiguration> pairs = new
ArrayList<TransportConfiguration>();
for (int node : otherLiveNodes)
{
TransportConfiguration otherLiveConnector =
createTransportConfiguration(isNetty(), false, generateParams(node, isNetty()));
config0.getConnectorConfigurations().put(otherLiveConnector.getName(),
otherLiveConnector);
- pairs.add(otherLiveConnector.getName());
+ pairs.add(otherLiveConnector);
}
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(pairs.toArray(new TransportConfiguration[0]));
+ config0.getDiscoveryGroupConfigurations().put(groupConf.getName(), groupConf);
ClusterConnectionConfiguration ccc0 = new
ClusterConnectionConfiguration("cluster1", "jms",
liveConnector.getName(), -1, false, false, 1, 1,
- pairs, false);
+ groupConf, false);
config0.getClusterConfigurations().add(ccc0);
config0.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/remote/FailoverWithSharedStoreTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/remote/FailoverWithSharedStoreTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/failover/remote/FailoverWithSharedStoreTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientConsumer;
@@ -68,6 +69,8 @@
config.getAcceptorConfigurations().add(createTransportConfiguration(true, true,
generateParams(0, true)));
config.getConnectorConfigurations().put("self",
createTransportConfiguration(true,
false, generateParams(0, true)));
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(new TransportConfiguration[0]);
+ config.getDiscoveryGroupConfigurations().put(groupConf.getName(), groupConf);
config.getClusterConfigurations().add(new
ClusterConnectionConfiguration("cluster",
"foo",
"self",
@@ -76,7 +79,7 @@
false,
1,
1,
- new
ArrayList<String>(), false));
+
groupConf, false));
return config;
}
@@ -96,12 +99,12 @@
config.setClustered(true);
config.getAcceptorConfigurations().add(createTransportConfiguration(true, true,
generateParams(1, true)));
config.setLiveConnectorName("live");
- config.getConnectorConfigurations().put("live",
- createTransportConfiguration(true,
false, generateParams(0, true)));
+ TransportConfiguration liveConnector = createTransportConfiguration(true, false,
generateParams(0, true));
+ config.getConnectorConfigurations().put("live", liveConnector);
config.getConnectorConfigurations().put("self",
createTransportConfiguration(true,
false, generateParams(1, true)));
- List<String> connectors = new ArrayList<String>();
- connectors.add("live");
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(liveConnector);
+
config.getClusterConfigurations().add(new
ClusterConnectionConfiguration("cluster",
"foo",
"self",
@@ -110,7 +113,7 @@
false,
1,
1,
-
connectors, false));
+
groupConf, false));
return config;
}
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/topology/HAClientTopologyWithDiscoveryTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/topology/HAClientTopologyWithDiscoveryTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/cluster/topology/HAClientTopologyWithDiscoveryTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -60,7 +60,7 @@
@Override
protected ServerLocator createHAServerLocator()
{
- ServerLocator locator = HornetQClient.createServerLocatorWithHA(new
DiscoveryGroupConfiguration(groupAddress, groupPort));
+ ServerLocator locator =
HornetQClient.createServerLocatorWithHA(createSimpleUDPDiscoveryGroupConfiguration(groupAddress,
groupPort));
locator.setBlockOnNonDurableSend(true);
locator.setBlockOnDurableSend(true);
return locator;
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/discovery/DiscoveryTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/discovery/DiscoveryTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/discovery/DiscoveryTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -33,6 +33,8 @@
import org.hornetq.core.cluster.DiscoveryGroup;
import org.hornetq.core.cluster.DiscoveryListener;
import org.hornetq.core.cluster.impl.DiscoveryGroupImpl;
+import org.hornetq.core.config.BroadcastGroupConfiguration;
+import org.hornetq.core.config.BroadcastGroupConstants;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.server.cluster.BroadcastGroup;
import org.hornetq.core.server.cluster.impl.BroadcastGroupImpl;
@@ -72,20 +74,17 @@
final String nodeID = RandomUtil.randomString();
- BroadcastGroup bg = new BroadcastGroupImpl(nodeID,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new BroadcastGroupImpl(nodeID, broadcastConf.getName(), true,
broadcastConf);
bg.start();
- TransportConfiguration live1 = generateTC();
-
- bg.addConnector(live1);
-
DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
RandomUtil.randomString(),
null,
@@ -156,22 +155,21 @@
return;
}
- log.info("Local address is " + localAddress);
+ log.info("Local address is " + localAddress.getHostAddress());
- BroadcastGroup bg = new BroadcastGroupImpl(nodeID,
- RandomUtil.randomString(),
- localAddress,
- 6552,
- groupAddress,
- groupPort,
- true);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.LOCAL_BIND_ADDRESS_NAME,
localAddress.getHostAddress());
+ params.put(BroadcastGroupConstants.LOCAL_BIND_PORT_NAME, 6552);
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new BroadcastGroupImpl(nodeID, broadcastConf.getName(), true,
broadcastConf);
bg.start();
- TransportConfiguration live1 = generateTC();
-
- bg.addConnector(live1);
-
DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
RandomUtil.randomString(),
localAddress,
@@ -204,21 +202,17 @@
final String nodeID = RandomUtil.randomString();
- BroadcastGroup bg = new BroadcastGroupImpl(nodeID,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new BroadcastGroupImpl(nodeID, broadcastConf.getName(), true,
broadcastConf);
bg.start();
- TransportConfiguration live1 = generateTC();
-
-
- bg.addConnector(live1);
-
DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
RandomUtil.randomString(),
null,
@@ -267,21 +261,17 @@
String nodeID = RandomUtil.randomString();
- BroadcastGroup bg = new BroadcastGroupImpl(nodeID,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new BroadcastGroupImpl(nodeID, broadcastConf.getName(), true,
broadcastConf);
bg.start();
- TransportConfiguration live1 = generateTC();
-
-
- bg.addConnector(live1);
-
DiscoveryGroup dg = new DiscoveryGroupImpl(nodeID, RandomUtil.randomString(), null,
groupAddress, groupPort, timeout);
dg.start();
@@ -352,20 +342,17 @@
final int groupPort = getUDPDiscoveryPort();
final int timeout = 500;
- BroadcastGroup bg = new BroadcastGroupImpl(RandomUtil.randomString(),
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new BroadcastGroupImpl(RandomUtil.randomString(),
broadcastConf.getName(), true, broadcastConf);
bg.start();
- TransportConfiguration live1 = generateTC();
-
- bg.addConnector(live1);
-
final int port2 = getUDPDiscoveryPort(1);
DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
@@ -394,20 +381,17 @@
final int groupPort = getUDPDiscoveryPort();
final int timeout = 500;
- BroadcastGroup bg = new BroadcastGroupImpl(RandomUtil.randomString(),
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new BroadcastGroupImpl(RandomUtil.randomString(),
broadcastConf.getName(), true, broadcastConf);
bg.start();
- TransportConfiguration live1 = generateTC();
-
- bg.addConnector(live1);
-
final InetAddress groupAddress2 = InetAddress.getByName(DiscoveryTest.address2);
final int port2 = getUDPDiscoveryPort(1);
@@ -453,43 +437,37 @@
String node3 = "node-3::" + RandomUtil.randomString();
- BroadcastGroup bg1 = new BroadcastGroupImpl(node1,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress1,
- groupPort1,
- true);
+ Map<String,Object> params1 = new HashMap<String,Object>();
+ params1.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress1);
+ params1.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort1);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors1 = new
ArrayList<TransportConfiguration>();
+ connectors1.add(live1);
+ BroadcastGroupConfiguration broadcastConf1 = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params1,
RandomUtil.randomString(), connectors1);
+ BroadcastGroup bg1 = new BroadcastGroupImpl(node1, broadcastConf1.getName(), true,
broadcastConf1);
- BroadcastGroup bg2 = new BroadcastGroupImpl(node2,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress2,
- groupPort2,
- true);
+ Map<String,Object> params2 = new HashMap<String,Object>();
+ params2.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress2);
+ params2.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort2);
+ TransportConfiguration live2 = generateTC();
+ List<TransportConfiguration> connectors2 = new
ArrayList<TransportConfiguration>();
+ connectors2.add(live2);
+ BroadcastGroupConfiguration broadcastConf2 = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params2,
RandomUtil.randomString(), connectors2);
+ BroadcastGroup bg2 = new BroadcastGroupImpl(node2, broadcastConf2.getName(), true,
broadcastConf2);
- BroadcastGroup bg3 = new BroadcastGroupImpl(node3,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress3,
- groupPort3,
- true);
+ Map<String,Object> params3 = new HashMap<String,Object>();
+ params3.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress3);
+ params3.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort3);
+ TransportConfiguration live3 = generateTC();
+ List<TransportConfiguration> connectors3 = new
ArrayList<TransportConfiguration>();
+ connectors3.add(live3);
+ BroadcastGroupConfiguration broadcastConf3 = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params3,
RandomUtil.randomString(), connectors3);
+ BroadcastGroup bg3 = new BroadcastGroupImpl(node3, broadcastConf3.getName(), true,
broadcastConf3);
+
bg2.start();
bg1.start();
bg3.start();
- TransportConfiguration live1 = generateTC("live1");
-
- TransportConfiguration live2 = generateTC("live2");
-
- TransportConfiguration live3 = generateTC("live3");
-
- bg1.addConnector(live1);
- bg2.addConnector(live2);
- bg3.addConnector(live3);
-
DiscoveryGroup dg1 = new DiscoveryGroupImpl("group-1::" +
RandomUtil.randomString(),
"group-1::" +
RandomUtil.randomString(),
null,
@@ -596,20 +574,17 @@
String nodeID = RandomUtil.randomString();
- BroadcastGroup bg = new BroadcastGroupImpl(nodeID,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new BroadcastGroupImpl(nodeID, broadcastConf.getName(), true,
broadcastConf);
bg.start();
- TransportConfiguration live1 = generateTC();
-
- bg.addConnector(live1);
-
DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
RandomUtil.randomString(),
null,
@@ -663,41 +638,30 @@
String node2 = RandomUtil.randomString();
String node3 = RandomUtil.randomString();
- BroadcastGroup bg1 = new BroadcastGroupImpl(node1,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
- bg1.start();
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort);
- BroadcastGroup bg2 = new BroadcastGroupImpl(node2,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
- bg2.start();
-
- BroadcastGroup bg3 = new BroadcastGroupImpl(node3,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
- bg3.start();
-
TransportConfiguration live1 = generateTC();
- bg1.addConnector(live1);
+ List<TransportConfiguration> connectors1 = new
ArrayList<TransportConfiguration>();
+ connectors1.add(live1);
+ BroadcastGroupConfiguration broadcastConf1 = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors1);
+ BroadcastGroup bg1 = new BroadcastGroupImpl(node1, broadcastConf1.getName(), true,
broadcastConf1);
+ bg1.start();
TransportConfiguration live2 = generateTC();
- bg2.addConnector(live2);
-
+ List<TransportConfiguration> connectors2 = new
ArrayList<TransportConfiguration>();
+ connectors2.add(live2);
+ BroadcastGroupConfiguration broadcastConf2 = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors2);
+ BroadcastGroup bg2 = new BroadcastGroupImpl(node2, broadcastConf2.getName(), true,
broadcastConf2);
+ bg2.start();
+
TransportConfiguration live3 = generateTC();
- bg3.addConnector(live3);
+ List<TransportConfiguration> connectors3 = new
ArrayList<TransportConfiguration>();
+ connectors3.add(live3);
+ BroadcastGroupConfiguration broadcastConf3 = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors3);
+ BroadcastGroup bg3 = new BroadcastGroupImpl(node3, broadcastConf3.getName(), true,
broadcastConf3);
+ bg3.start();
DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
RandomUtil.randomString(),
@@ -851,20 +815,17 @@
String nodeID = RandomUtil.randomString();
- BroadcastGroup bg = new BroadcastGroupImpl(nodeID,
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_PORT_NAME, groupPort);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new BroadcastGroupImpl(nodeID, broadcastConf.getName(), true,
broadcastConf);
bg.start();
- TransportConfiguration live1 = generateTC();
-
- bg.addConnector(live1);
-
DiscoveryGroup dg1 = new DiscoveryGroupImpl(RandomUtil.randomString(),
RandomUtil.randomString(),
null,
@@ -962,13 +923,11 @@
final InetAddress groupAddress = InetAddress.getByName(DiscoveryTest.address1);
final int groupPort = getUDPDiscoveryPort();
- BroadcastGroup bg = new BroadcastGroupImpl(RandomUtil.randomString(),
- RandomUtil.randomString(),
- null,
- -1,
- groupAddress,
- groupPort,
- true);
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ params.put(BroadcastGroupConstants.GROUP_ADDRESS_NAME, groupAddress);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(BroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), new ArrayList<TransportConfiguration>());
+ BroadcastGroup bg = new BroadcastGroupImpl(RandomUtil.randomString(),
broadcastConf.getName(), true, broadcastConf);
bg.setNotificationService(notifService);
Assert.assertEquals(0, notifListener.getNotifications().size());
Added:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/discovery/JGroupsDiscoveryTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/discovery/JGroupsDiscoveryTest.java
(rev 0)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/discovery/JGroupsDiscoveryTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -0,0 +1,719 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat 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.hornetq.tests.integration.discovery;
+
+ import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.hornetq.api.core.SimpleString;
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.management.NotificationType;
+import org.hornetq.core.cluster.DiscoveryEntry;
+import org.hornetq.core.cluster.DiscoveryGroup;
+import org.hornetq.core.cluster.DiscoveryListener;
+import org.hornetq.core.config.BroadcastGroupConfiguration;
+import org.hornetq.core.logging.Logger;
+import org.hornetq.core.server.cluster.BroadcastGroup;
+import org.hornetq.core.server.management.Notification;
+import org.hornetq.integration.discovery.jgroups.BroadcastGroupConstants;
+import org.hornetq.integration.discovery.jgroups.DiscoveryGroupConstants;
+import org.hornetq.integration.discovery.jgroups.JGroupsBroadcastGroupImpl;
+import org.hornetq.integration.discovery.jgroups.JGroupsDiscoveryGroupImpl;
+import org.hornetq.tests.integration.SimpleNotificationService;
+import org.hornetq.tests.util.RandomUtil;
+import org.hornetq.tests.util.UnitTestCase;
+import org.hornetq.utils.UUIDGenerator;
+
+/**
+ * A DiscoveryTest
+ *
+ * @author <a href="mailto:tm.igarashi@gmail.com">Tomohisa
Igarashi</a>
+ *
+ */
+public class JGroupsDiscoveryTest extends UnitTestCase
+{
+ private static final Logger log = Logger.getLogger(DiscoveryTest.class);
+
+ private static final String channelName =
DiscoveryGroupConstants.DEFAULT_JGROUPS_CHANNEL_NAME;
+
+ private static final String channelName2 =
DiscoveryGroupConstants.DEFAULT_JGROUPS_CHANNEL_NAME + "2";
+
+ private static final String channelName3 =
DiscoveryGroupConstants.DEFAULT_JGROUPS_CHANNEL_NAME + "3";
+
+ private static final String config = "test-jgroups-file_ping.xml";
+
+ private static final String config2 = "test-jgroups-file_ping_2.xml";
+
+ private static final String config3 = "test-jgroups-file_ping_3.xml";
+
+ public void testSimpleBroadcast() throws Exception
+ {
+ final long timeout = 500;
+
+ final String nodeID = RandomUtil.randomString();
+
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME, config);
+ params.put(BroadcastGroupConstants.JGROUPS_CHANNEL_NAME_NAME, channelName);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new JGroupsBroadcastGroupImpl(nodeID, broadcastConf.getName(),
true, broadcastConf);
+
+ bg.start();
+
+ DiscoveryGroup dg = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName,
+
Thread.currentThread().getContextClassLoader().getResource(config),
+ timeout);
+
+ dg.start();
+
+ bg.broadcastConnectors();
+
+ boolean ok = dg.waitForBroadcast(10000);
+
+ Assert.assertTrue(ok);
+
+ List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
+
+ bg.stop();
+
+ dg.stop();
+
+ }
+
+ public void testSimpleBroadcastWithStopStartDiscoveryGroup() throws Exception
+ {
+ final int timeout = 500;
+
+ final String nodeID = RandomUtil.randomString();
+
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME, config);
+ params.put(BroadcastGroupConstants.JGROUPS_CHANNEL_NAME_NAME, channelName);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new JGroupsBroadcastGroupImpl(nodeID, broadcastConf.getName(),
true, broadcastConf);
+
+ bg.start();
+
+ DiscoveryGroup dg = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName,
+
Thread.currentThread().getContextClassLoader().getResource(config),
+ timeout);
+
+ dg.start();
+
+ bg.broadcastConnectors();
+
+ boolean ok = dg.waitForBroadcast(1000);
+
+ Assert.assertTrue(ok);
+
+ List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
+
+ bg.stop();
+
+ dg.stop();
+
+ dg.start();
+
+ bg.start();
+
+ bg.broadcastConnectors();
+
+ ok = dg.waitForBroadcast(1000);
+
+ Assert.assertTrue(ok);
+
+ entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
+
+ bg.stop();
+
+ dg.stop();
+ }
+
+ public void testIgnoreTrafficFromOwnNode() throws Exception
+ {
+ final int timeout = 500;
+
+ String nodeID = RandomUtil.randomString();
+
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME, config);
+ params.put(BroadcastGroupConstants.JGROUPS_CHANNEL_NAME_NAME, channelName);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new JGroupsBroadcastGroupImpl(nodeID, broadcastConf.getName(),
true, broadcastConf);
+
+ bg.start();
+
+ DiscoveryGroup dg = new JGroupsDiscoveryGroupImpl(nodeID,
+ RandomUtil.randomString(),
+ channelName,
+
Thread.currentThread().getContextClassLoader().getResource(config),
+ timeout);
+
+ dg.start();
+
+ bg.broadcastConnectors();
+
+ boolean ok = dg.waitForBroadcast(1000);
+
+ Assert.assertFalse(ok);
+
+ List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
+
+ Assert.assertNotNull(entries);
+
+ Assert.assertEquals(0, entries.size());
+
+ bg.stop();
+
+ dg.stop();
+
+ }
+
+
+ public void testMultipleGroups() throws Exception
+ {
+ final int timeout = 500;
+
+ String node1 = RandomUtil.randomString();
+
+ String node2 = RandomUtil.randomString();
+
+ String node3 = RandomUtil.randomString();
+
+ Map<String,Object> params1 = new HashMap<String,Object>();
+ params1.put(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME, config);
+ params1.put(BroadcastGroupConstants.JGROUPS_CHANNEL_NAME_NAME, channelName);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors1 = new
ArrayList<TransportConfiguration>();
+ connectors1.add(live1);
+ BroadcastGroupConfiguration broadcastConf1 = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params1,
RandomUtil.randomString(), connectors1);
+ BroadcastGroup bg1 = new JGroupsBroadcastGroupImpl(node1, broadcastConf1.getName(),
true, broadcastConf1);
+ bg1.start();
+
+ Map<String,Object> params2 = new HashMap<String,Object>();
+ params2.put(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME, config2);
+ params2.put(BroadcastGroupConstants.JGROUPS_CHANNEL_NAME_NAME, channelName2);
+ TransportConfiguration live2 = generateTC();
+ List<TransportConfiguration> connectors2 = new
ArrayList<TransportConfiguration>();
+ connectors2.add(live2);
+ BroadcastGroupConfiguration broadcastConf2 = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params2,
RandomUtil.randomString(), connectors2);
+ BroadcastGroup bg2 = new JGroupsBroadcastGroupImpl(node2, broadcastConf2.getName(),
true, broadcastConf2);
+ bg2.start();
+
+ Map<String,Object> params3 = new HashMap<String,Object>();
+ params3.put(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME, config3);
+ params3.put(BroadcastGroupConstants.JGROUPS_CHANNEL_NAME_NAME, channelName3);
+ TransportConfiguration live3 = generateTC();
+ List<TransportConfiguration> connectors3 = new
ArrayList<TransportConfiguration>();
+ connectors3.add(live3);
+ BroadcastGroupConfiguration broadcastConf3 = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params3,
RandomUtil.randomString(), connectors3);
+ BroadcastGroup bg3 = new JGroupsBroadcastGroupImpl(node3, broadcastConf3.getName(),
true, broadcastConf3);
+ bg3.start();
+
+ DiscoveryGroup dg1 = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName,
+
Thread.currentThread().getContextClassLoader().getResource(config),
+ timeout);
+ dg1.start();
+
+ DiscoveryGroup dg2 = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName2,
+
Thread.currentThread().getContextClassLoader().getResource(config2),
+ timeout);
+ dg2.start();
+
+ DiscoveryGroup dg3 = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName3,
+
Thread.currentThread().getContextClassLoader().getResource(config3),
+ timeout);
+ dg3.start();
+
+ bg1.broadcastConnectors();
+
+ bg2.broadcastConnectors();
+
+ bg3.broadcastConnectors();
+
+ boolean ok = dg1.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ List<DiscoveryEntry> entries = dg1.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
+
+ ok = dg2.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ entries = dg2.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live2), entries);
+
+ ok = dg3.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ entries = dg3.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live3), entries);
+
+ bg1.stop();
+ bg2.stop();
+ bg3.stop();
+
+ dg1.stop();
+ dg2.stop();
+ dg3.stop();
+ }
+
+ public void testDiscoveryListenersCalled() throws Exception
+ {
+ final int timeout = 500;
+
+ String nodeID = RandomUtil.randomString();
+
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME, config);
+ params.put(BroadcastGroupConstants.JGROUPS_CHANNEL_NAME_NAME, channelName);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new JGroupsBroadcastGroupImpl(nodeID, broadcastConf.getName(),
true, broadcastConf);
+
+ bg.start();
+
+ DiscoveryGroup dg = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName,
+
Thread.currentThread().getContextClassLoader().getResource(config),
+ timeout);
+
+ MyListener listener1 = new MyListener();
+ MyListener listener2 = new MyListener();
+ MyListener listener3 = new MyListener();
+
+ dg.registerListener(listener1);
+ dg.registerListener(listener2);
+ dg.registerListener(listener3);
+
+ dg.start();
+
+ bg.broadcastConnectors();
+ boolean ok = dg.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+
+ Assert.assertTrue(listener1.called);
+ Assert.assertTrue(listener2.called);
+ Assert.assertTrue(listener3.called);
+
+ listener1.called = false;
+ listener2.called = false;
+ listener3.called = false;
+
+ bg.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+
+ // Won't be called since connectors haven't changed
+ Assert.assertFalse(listener1.called);
+ Assert.assertFalse(listener2.called);
+ Assert.assertFalse(listener3.called);
+
+ bg.stop();
+
+ dg.stop();
+ }
+
+ public void testConnectorsUpdatedMultipleBroadcasters() throws Exception
+ {
+ final int timeout = 500;
+
+ String node1 = RandomUtil.randomString();
+ String node2 = RandomUtil.randomString();
+ String node3 = RandomUtil.randomString();
+
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME, config);
+ params.put(BroadcastGroupConstants.JGROUPS_CHANNEL_NAME_NAME, channelName);
+
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors1 = new
ArrayList<TransportConfiguration>();
+ connectors1.add(live1);
+ BroadcastGroupConfiguration broadcastConf1 = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors1);
+ BroadcastGroup bg1 = new JGroupsBroadcastGroupImpl(node1, broadcastConf1.getName(),
true, broadcastConf1);
+ bg1.start();
+
+ TransportConfiguration live2 = generateTC();
+ List<TransportConfiguration> connectors2 = new
ArrayList<TransportConfiguration>();
+ connectors2.add(live2);
+ BroadcastGroupConfiguration broadcastConf2 = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors2);
+ BroadcastGroup bg2 = new JGroupsBroadcastGroupImpl(node2, broadcastConf2.getName(),
true, broadcastConf2);
+ bg2.start();
+
+ TransportConfiguration live3 = generateTC();
+ List<TransportConfiguration> connectors3 = new
ArrayList<TransportConfiguration>();
+ connectors3.add(live3);
+ BroadcastGroupConfiguration broadcastConf3 = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors3);
+ BroadcastGroup bg3 = new JGroupsBroadcastGroupImpl(node3, broadcastConf3.getName(),
true, broadcastConf3);
+ bg3.start();
+
+ DiscoveryGroup dg = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName,
+
Thread.currentThread().getContextClassLoader().getResource(config),
+ timeout);
+
+ MyListener listener1 = new MyListener();
+ dg.registerListener(listener1);
+ MyListener listener2 = new MyListener();
+ dg.registerListener(listener2);
+
+ dg.start();
+
+ bg1.broadcastConnectors();
+ boolean ok = dg.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
+ Assert.assertTrue(listener1.called);
+ Assert.assertTrue(listener2.called);
+ listener1.called = false;
+ listener2.called = false;
+
+ bg2.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1, live2), entries);
+ Assert.assertTrue(listener1.called);
+ Assert.assertTrue(listener2.called);
+ listener1.called = false;
+ listener2.called = false;
+
+ bg3.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
+ Assert.assertTrue(listener1.called);
+ Assert.assertTrue(listener2.called);
+ listener1.called = false;
+ listener2.called = false;
+
+ bg1.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
+ Assert.assertFalse(listener1.called);
+ Assert.assertFalse(listener2.called);
+ listener1.called = false;
+ listener2.called = false;
+
+ bg2.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
+ Assert.assertFalse(listener1.called);
+ Assert.assertFalse(listener2.called);
+ listener1.called = false;
+ listener2.called = false;
+
+ bg3.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
+ Assert.assertFalse(listener1.called);
+ Assert.assertFalse(listener2.called);
+ listener1.called = false;
+ listener2.called = false;
+
+ bg2.removeConnector(live2);
+ bg2.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+
+ // Connector2 should still be there since not timed out yet
+
+ entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
+ Assert.assertFalse(listener1.called);
+ Assert.assertFalse(listener2.called);
+ listener1.called = false;
+ listener2.called = false;
+
+ Thread.sleep(timeout);
+
+ bg1.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ bg2.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ bg3.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+
+ entries = dg.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1, live3), entries);
+ Assert.assertTrue(listener1.called);
+ Assert.assertTrue(listener2.called);
+ listener1.called = false;
+ listener2.called = false;
+
+ bg1.removeConnector(live1);
+ bg3.removeConnector(live3);
+
+ Thread.sleep(timeout);
+
+ bg1.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ bg2.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ bg3.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+
+ entries = dg.getDiscoveryEntries();
+ Assert.assertNotNull(entries);
+ Assert.assertEquals(0, entries.size());
+ Assert.assertTrue(listener1.called);
+ Assert.assertTrue(listener2.called);
+ listener1.called = false;
+ listener2.called = false;
+
+ bg1.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ bg2.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+ bg3.broadcastConnectors();
+ ok = dg.waitForBroadcast(1000);
+
+ entries = dg.getDiscoveryEntries();
+ Assert.assertNotNull(entries);
+ Assert.assertEquals(0, entries.size());
+ Assert.assertFalse(listener1.called);
+ Assert.assertFalse(listener2.called);
+
+ bg1.stop();
+ bg2.stop();
+ bg3.stop();
+
+ dg.stop();
+ }
+
+ public void testMultipleDiscoveryGroups() throws Exception
+ {
+ final int timeout = 500;
+
+ String nodeID = RandomUtil.randomString();
+
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME, config);
+ params.put(BroadcastGroupConstants.JGROUPS_CHANNEL_NAME_NAME, channelName);
+ TransportConfiguration live1 = generateTC();
+ List<TransportConfiguration> connectors = new
ArrayList<TransportConfiguration>();
+ connectors.add(live1);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), connectors);
+ BroadcastGroup bg = new JGroupsBroadcastGroupImpl(nodeID, broadcastConf.getName(),
true, broadcastConf);
+ bg.start();
+
+ DiscoveryGroup dg1 = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName,
+
Thread.currentThread().getContextClassLoader().getResource(config),
+ timeout);
+
+ DiscoveryGroup dg2 = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName,
+
Thread.currentThread().getContextClassLoader().getResource(config),
+ timeout);
+
+ DiscoveryGroup dg3 = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName,
+
Thread.currentThread().getContextClassLoader().getResource(config),
+ timeout);
+
+ dg1.start();
+ dg2.start();
+ dg3.start();
+
+ bg.broadcastConnectors();
+
+ boolean ok = dg1.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ List<DiscoveryEntry> entries = dg1.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
+
+ ok = dg2.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ entries = dg2.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
+
+ ok = dg3.waitForBroadcast(1000);
+ Assert.assertTrue(ok);
+ entries = dg3.getDiscoveryEntries();
+ assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
+
+ bg.stop();
+
+ dg1.stop();
+ dg2.stop();
+ dg3.stop();
+ }
+
+ public void testDiscoveryGroupNotifications() throws Exception
+ {
+ SimpleNotificationService notifService = new SimpleNotificationService();
+ SimpleNotificationService.Listener notifListener = new
SimpleNotificationService.Listener();
+ notifService.addNotificationListener(notifListener);
+
+ final int timeout = 500;
+
+ DiscoveryGroup dg = new JGroupsDiscoveryGroupImpl(RandomUtil.randomString(),
+ RandomUtil.randomString(),
+ channelName,
+
Thread.currentThread().getContextClassLoader().getResource(config),
+ timeout);
+ dg.setNotificationService(notifService);
+
+ Assert.assertEquals(0, notifListener.getNotifications().size());
+
+ dg.start();
+
+ Assert.assertEquals(1, notifListener.getNotifications().size());
+ Notification notif = notifListener.getNotifications().get(0);
+ Assert.assertEquals(NotificationType.DISCOVERY_GROUP_STARTED, notif.getType());
+ Assert.assertEquals(dg.getName(), notif.getProperties()
+ .getSimpleStringProperty(new
SimpleString("name"))
+ .toString());
+
+ dg.stop();
+
+ Assert.assertEquals(2, notifListener.getNotifications().size());
+ notif = notifListener.getNotifications().get(1);
+ Assert.assertEquals(NotificationType.DISCOVERY_GROUP_STOPPED, notif.getType());
+ Assert.assertEquals(dg.getName(), notif.getProperties()
+ .getSimpleStringProperty(new
SimpleString("name"))
+ .toString());
+ }
+
+ public void testBroadcastGroupNotifications() throws Exception
+ {
+ SimpleNotificationService notifService = new SimpleNotificationService();
+ SimpleNotificationService.Listener notifListener = new
SimpleNotificationService.Listener();
+ notifService.addNotificationListener(notifListener);
+
+ Map<String,Object> params = new HashMap<String,Object>();
+ params.put(BroadcastGroupConstants.JGROUPS_CONFIGURATION_FILE_NAME, config);
+ BroadcastGroupConfiguration broadcastConf = new
BroadcastGroupConfiguration(JGroupsBroadcastGroupImpl.class.getName(), params,
RandomUtil.randomString(), new ArrayList<TransportConfiguration>());
+ BroadcastGroup bg = new JGroupsBroadcastGroupImpl(RandomUtil.randomString(),
broadcastConf.getName(), true, broadcastConf);
+ bg.setNotificationService(notifService);
+
+ Assert.assertEquals(0, notifListener.getNotifications().size());
+
+ bg.start();
+
+ Assert.assertEquals(1, notifListener.getNotifications().size());
+ Notification notif = notifListener.getNotifications().get(0);
+ Assert.assertEquals(NotificationType.BROADCAST_GROUP_STARTED, notif.getType());
+ Assert.assertEquals(bg.getName(), notif.getProperties()
+ .getSimpleStringProperty(new
SimpleString("name"))
+ .toString());
+
+ bg.stop();
+
+ Assert.assertEquals(2, notifListener.getNotifications().size());
+ notif = notifListener.getNotifications().get(1);
+ Assert.assertEquals(NotificationType.BROADCAST_GROUP_STOPPED, notif.getType());
+ Assert.assertEquals(bg.getName(), notif.getProperties()
+ .getSimpleStringProperty(new
SimpleString("name"))
+ .toString());
+ }
+
+ private TransportConfiguration generateTC()
+ {
+ String className = "org.foo.bar." +
UUIDGenerator.getInstance().generateStringUUID();
+ String name = UUIDGenerator.getInstance().generateStringUUID();
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put(UUIDGenerator.getInstance().generateStringUUID(), 123);
+ params.put(UUIDGenerator.getInstance().generateStringUUID(),
UUIDGenerator.getInstance().generateStringUUID());
+ params.put(UUIDGenerator.getInstance().generateStringUUID(), true);
+ TransportConfiguration tc = new TransportConfiguration(className, params, name);
+ return tc;
+ }
+
+ private static class MyListener implements DiscoveryListener
+ {
+ volatile boolean called;
+
+ public void connectorsChanged()
+ {
+ called = true;
+ }
+ }
+
+
+ private static void assertEqualsDiscoveryEntries(List<TransportConfiguration>
expected, List<DiscoveryEntry> actual)
+ {
+ assertNotNull(actual);
+
+ List<TransportConfiguration> sortedExpected = new
ArrayList<TransportConfiguration>(expected);
+ Collections.sort(sortedExpected, new Comparator<TransportConfiguration>()
+ {
+
+ public int compare(TransportConfiguration o1, TransportConfiguration o2)
+ {
+ return o2.toString().compareTo(o1.toString());
+ }
+ });
+ List<DiscoveryEntry> sortedActual = new
ArrayList<DiscoveryEntry>(actual);
+ Collections.sort(sortedActual, new Comparator<DiscoveryEntry>()
+ {
+ public int compare(DiscoveryEntry o1, DiscoveryEntry o2)
+ {
+ return o2.getConnector().toString().compareTo(o1.getConnector().toString());
+ }
+ });
+
+ assertEquals(sortedExpected.size(), sortedActual.size());
+ for (int i = 0; i < sortedExpected.size(); i++)
+ {
+ assertEquals(sortedExpected.get(i), sortedActual.get(i).getConnector());
+ }
+ }
+
+}
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/HornetQConnectionFactoryTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/HornetQConnectionFactoryTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/HornetQConnectionFactoryTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -156,7 +156,7 @@
public void testDiscoveryConstructor() throws Exception
{
- DiscoveryGroupConfiguration groupConfiguration = new
DiscoveryGroupConfiguration(groupAddress, groupPort);
+ DiscoveryGroupConfiguration groupConfiguration =
createSimpleUDPDiscoveryGroupConfiguration(groupAddress, groupPort);
HornetQConnectionFactory cf = (HornetQConnectionFactory)
HornetQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration, JMSFactoryType.CF);
assertFactoryParams(cf,
null,
@@ -715,8 +715,8 @@
liveConf.setSharedStore(true);
liveConf.setClustered(true);
- List<String> connectorNames = new ArrayList<String>();
- connectorNames.add(liveTC.getName());
+ List<TransportConfiguration> connectorNames = new
ArrayList<TransportConfiguration>();
+ connectorNames.add(liveTC);
final long broadcastPeriod = 250;
@@ -724,13 +724,13 @@
final int localBindPort = 5432;
- BroadcastGroupConfiguration bcConfig1 = new
BroadcastGroupConfiguration(bcGroupName,
- null,
-
localBindPort,
-
groupAddress,
- groupPort,
-
broadcastPeriod,
-
connectorNames);
+ BroadcastGroupConfiguration bcConfig1 =
createBroadcastGroupConfiguration(bcGroupName,
+ null,
+
localBindPort,
+
groupAddress,
+
groupPort,
+
broadcastPeriod,
+
connectorNames);
List<BroadcastGroupConfiguration> bcConfigs1 = new
ArrayList<BroadcastGroupConfiguration>();
bcConfigs1.add(bcConfig1);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -32,6 +32,7 @@
import junit.framework.Assert;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
@@ -361,8 +362,9 @@
backupConf.getAcceptorConfigurations().add(backupAcceptortc);
backupConf.getConnectorConfigurations().put(livetc.getName(), livetc);
backupConf.getConnectorConfigurations().put(backuptc.getName(), backuptc);
- ArrayList<String> staticConnectors = new ArrayList<String>();
- staticConnectors.add(livetc.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(livetc);
+ backupConf.getDiscoveryGroupConfigurations().put(groupConf.getName(), groupConf);
+
ClusterConnectionConfiguration cccBackup = new
ClusterConnectionConfiguration("cluster1",
"jms",
backuptc.getName(),
@@ -371,7 +373,7 @@
false,
1,
1,
-
staticConnectors,
+
groupConf,
false);
backupConf.getClusterConfigurations().add(cccBackup);
@@ -404,7 +406,7 @@
liveConf.setSecurityEnabled(false);
liveConf.getAcceptorConfigurations().add(liveAcceptortc);
- List<String> pairs = null;
+ DiscoveryGroupConfiguration pairs = null;
ClusterConnectionConfiguration ccc0 = new
ClusterConnectionConfiguration("cluster1",
"jms",
livetc.getName(),
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionFactoryOnGCest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionFactoryOnGCest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionFactoryOnGCest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -27,7 +27,7 @@
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.jms.HornetQJMSClient;
import org.hornetq.api.jms.JMSFactoryType;
-import org.hornetq.core.client.impl.ServerLocatorImpl;
+import org.hornetq.core.client.impl.AbstractServerLocator;
import org.hornetq.core.logging.Logger;
import org.hornetq.jms.client.HornetQConnectionFactory;
import org.hornetq.tests.util.JMSTestBase;
@@ -61,7 +61,7 @@
final AtomicInteger valueGC = new AtomicInteger(0);
- ServerLocatorImpl.finalizeCallback = new Runnable()
+ AbstractServerLocator.finalizeCallback = new Runnable()
{
public void run()
{
@@ -85,7 +85,7 @@
}
finally
{
- ServerLocatorImpl.finalizeCallback = null;
+ AbstractServerLocator.finalizeCallback = null;
}
assertEquals("The code is throwing exceptions", 0, valueGC.get());
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/server/JMSServerDeployerTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/server/JMSServerDeployerTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/server/JMSServerDeployerTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -339,9 +339,9 @@
config.getConnectorConfigurations().put("netty",
new
TransportConfiguration(NettyConnectorFactory.class.getName()));
- DiscoveryGroupConfiguration dcg = new
DiscoveryGroupConfiguration("mygroup", "172.16.8.10",
-
"243.7.7.7", 12345,
- 5432, 5432);
+ DiscoveryGroupConfiguration dcg =
createSimpleUDPDiscoveryGroupConfiguration("mygroup", "172.16.8.10",
+
"243.7.7.7", 12345,
+
5432, 5432);
config.getDiscoveryGroupConfigurations().put("mygroup", dcg);
HornetQServer server = createServer(false, config);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BridgeControlTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BridgeControlTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BridgeControlTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -23,6 +23,8 @@
import junit.framework.Assert;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
@@ -74,7 +76,7 @@
BridgeControl bridgeControl = createBridgeControl(bridgeConfig.getName(),
mbeanServer);
Assert.assertEquals(bridgeConfig.getName(), bridgeControl.getName());
- Assert.assertEquals(bridgeConfig.getDiscoveryGroupName(),
bridgeControl.getDiscoveryGroupName());
+ Assert.assertEquals(bridgeConfig.getDiscoveryGroupConfiguration().getName(),
bridgeControl.getDiscoveryGroupName());
Assert.assertEquals(bridgeConfig.getQueueName(), bridgeControl.getQueueName());
Assert.assertEquals(bridgeConfig.getForwardingAddress(),
bridgeControl.getForwardingAddress());
Assert.assertEquals(bridgeConfig.getFilterString(),
bridgeControl.getFilterString());
@@ -84,7 +86,8 @@
Assert.assertEquals(bridgeConfig.isUseDuplicateDetection(),
bridgeControl.isUseDuplicateDetection());
String[] connectorPairData = bridgeControl.getStaticConnectors();
- Assert.assertEquals(bridgeConfig.getStaticConnectors().get(0),
connectorPairData[0]);
+ List<TransportConfiguration> connectors =
(List<TransportConfiguration>)bridgeConfig.getDiscoveryGroupConfiguration().getParams().get((DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME));
+ Assert.assertEquals(connectors.get(0).getName(), connectorPairData[0]);
Assert.assertTrue(bridgeControl.isStarted());
}
@@ -159,8 +162,7 @@
RandomUtil.randomString(),
null,
false);
- List<String> connectors = new ArrayList<String>();
- connectors.add(connectorConfig.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(connectorConfig);
bridgeConfig = new BridgeConfiguration(RandomUtil.randomString(),
sourceQueueConfig.getName(),
targetQueueConfig.getAddress(),
@@ -172,7 +174,7 @@
RandomUtil.randomBoolean(),
RandomUtil.randomPositiveInt(),
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
- connectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -191,6 +193,7 @@
conf_0.getAcceptorConfigurations().add(new
TransportConfiguration(InVMAcceptorFactory.class.getName()));
conf_0.getConnectorConfigurations().put(connectorConfig.getName(),
connectorConfig);
conf_0.getQueueConfigurations().add(sourceQueueConfig);
+ conf_0.getDiscoveryGroupConfigurations().put(groupConf.getName(), groupConf);
conf_0.getBridgeConfigurations().add(bridgeConfig);
server_1 = HornetQServers.newHornetQServer(conf_1,
MBeanServerFactory.createMBeanServer(), false);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BridgeControlUsingCoreTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BridgeControlUsingCoreTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BridgeControlUsingCoreTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -22,6 +22,8 @@
import junit.framework.Assert;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
@@ -74,7 +76,7 @@
CoreMessagingProxy proxy = createProxy(bridgeConfig.getName());
Assert.assertEquals(bridgeConfig.getName(),
(String)proxy.retrieveAttributeValue("name"));
- Assert.assertEquals(bridgeConfig.getDiscoveryGroupName(),
+ Assert.assertEquals(bridgeConfig.getDiscoveryGroupConfiguration().getName(),
(String)proxy.retrieveAttributeValue("discoveryGroupName"));
Assert.assertEquals(bridgeConfig.getQueueName(),
(String)proxy.retrieveAttributeValue("queueName"));
Assert.assertEquals(bridgeConfig.getForwardingAddress(),
@@ -90,7 +92,8 @@
((Boolean)proxy.retrieveAttributeValue("useDuplicateDetection")).booleanValue());
Object[] data =
(Object[])proxy.retrieveAttributeValue("staticConnectors");
- Assert.assertEquals(bridgeConfig.getStaticConnectors().get(0), data[0]);
+ List<TransportConfiguration> connectors =
(List<TransportConfiguration>)bridgeConfig.getDiscoveryGroupConfiguration().getParams().get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME);
+ Assert.assertEquals(connectors.get(0).getName(), data[0]);
Assert.assertTrue((Boolean)proxy.retrieveAttributeValue("started"));
}
@@ -137,8 +140,7 @@
RandomUtil.randomString(),
null,
false);
- List<String> connectors = new ArrayList<String>();
- connectors.add(connectorConfig.getName());
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(connectorConfig);
bridgeConfig = new BridgeConfiguration(RandomUtil.randomString(),
sourceQueueConfig.getName(),
targetQueueConfig.getAddress(),
@@ -150,7 +152,7 @@
RandomUtil.randomBoolean(),
RandomUtil.randomPositiveInt(),
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
- connectors,
+ groupConf,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
@@ -169,6 +171,7 @@
conf_0.getAcceptorConfigurations().add(new
TransportConfiguration(InVMAcceptorFactory.class.getName()));
conf_0.getConnectorConfigurations().put(connectorConfig.getName(),
connectorConfig);
conf_0.getQueueConfigurations().add(sourceQueueConfig);
+ conf_0.getDiscoveryGroupConfigurations().put(groupConf.getName(), groupConf);
conf_0.getBridgeConfigurations().add(bridgeConfig);
server_1 = HornetQServers.newHornetQServer(conf_1,
MBeanServerFactory.createMBeanServer(), false);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BroadcastGroupControlTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BroadcastGroupControlTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/BroadcastGroupControlTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -22,6 +22,7 @@
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.management.BroadcastGroupControl;
import org.hornetq.core.config.BroadcastGroupConfiguration;
+import org.hornetq.core.config.BroadcastGroupConstants;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory;
@@ -52,15 +53,15 @@
// Static --------------------------------------------------------
- public static BroadcastGroupConfiguration randomBroadcastGroupConfiguration(final
List<String> connectorInfos)
+ public static BroadcastGroupConfiguration randomBroadcastGroupConfiguration(final
List<TransportConfiguration> connectorList)
{
- return new BroadcastGroupConfiguration(RandomUtil.randomString(),
- null,
- 1198,
- "231.7.7.7",
- 1199,
- RandomUtil.randomPositiveInt(),
- connectorInfos);
+ return createBroadcastGroupConfiguration(RandomUtil.randomString(),
+ null,
+ 1198,
+ "231.7.7.7",
+ 1199,
+ RandomUtil.randomPositiveInt(),
+ connectorList);
}
public static Pair<String, String> randomPair()
@@ -75,9 +76,9 @@
public void testAttributes() throws Exception
{
TransportConfiguration connectorConfiguration = new
TransportConfiguration(NettyConnectorFactory.class.getName());
- List<String> connectorInfos = new ArrayList<String>();
- connectorInfos.add(connectorConfiguration.getName());
- BroadcastGroupConfiguration broadcastGroupConfig =
BroadcastGroupControlTest.randomBroadcastGroupConfiguration(connectorInfos);
+ List<TransportConfiguration> connectorList = new
ArrayList<TransportConfiguration>();
+ connectorList.add(connectorConfiguration);
+ BroadcastGroupConfiguration broadcastGroupConfig =
BroadcastGroupControlTest.randomBroadcastGroupConfiguration(connectorList);
Configuration conf = createBasicConfig();
conf.setSecurityEnabled(false);
@@ -92,21 +93,22 @@
BroadcastGroupControl broadcastGroupControl =
createManagementControl(broadcastGroupConfig.getName());
Assert.assertEquals(broadcastGroupConfig.getName(),
broadcastGroupControl.getName());
- Assert.assertEquals(broadcastGroupConfig.getGroupAddress(),
broadcastGroupControl.getGroupAddress());
- Assert.assertEquals(broadcastGroupConfig.getGroupPort(),
broadcastGroupControl.getGroupPort());
- Assert.assertEquals(broadcastGroupConfig.getLocalBindPort(),
broadcastGroupControl.getLocalBindPort());
- Assert.assertEquals(broadcastGroupConfig.getBroadcastPeriod(),
broadcastGroupControl.getBroadcastPeriod());
+
Assert.assertEquals(broadcastGroupConfig.getParams().get(BroadcastGroupConstants.GROUP_ADDRESS_NAME),
broadcastGroupControl.getGroupAddress());
+
Assert.assertEquals(broadcastGroupConfig.getParams().get(BroadcastGroupConstants.GROUP_PORT_NAME),
broadcastGroupControl.getGroupPort());
+
Assert.assertEquals(broadcastGroupConfig.getParams().get(BroadcastGroupConstants.LOCAL_BIND_PORT_NAME),
broadcastGroupControl.getLocalBindPort());
+
Assert.assertEquals(broadcastGroupConfig.getParams().get(BroadcastGroupConstants.BROADCAST_PERIOD_NAME),
broadcastGroupControl.getBroadcastPeriod());
Object[] connectorPairs = broadcastGroupControl.getConnectorPairs();
Assert.assertEquals(1, connectorPairs.length);
System.out.println(connectorPairs);
String connectorPairData = (String)connectorPairs[0];
- Assert.assertEquals(broadcastGroupConfig.getConnectorInfos().get(0),
connectorPairData);
+ List<TransportConfiguration> connectors =
broadcastGroupConfig.getConnectorList();
+ Assert.assertEquals(connectors.get(0).getName(), connectorPairData);
String jsonString = broadcastGroupControl.getConnectorPairsAsJSON();
Assert.assertNotNull(jsonString);
JSONArray array = new JSONArray(jsonString);
Assert.assertEquals(1, array.length());
- Assert.assertEquals(broadcastGroupConfig.getConnectorInfos().get(0),
array.getString(0));
+ Assert.assertEquals(connectors.get(0).getName(), array.getString(0));
Assert.assertTrue(broadcastGroupControl.isStarted());
}
@@ -114,9 +116,9 @@
public void testStartStop() throws Exception
{
TransportConfiguration connectorConfiguration = new
TransportConfiguration(NettyConnectorFactory.class.getName());
- List<String> connectorInfos = new ArrayList<String>();
- connectorInfos.add(connectorConfiguration.getName());
- BroadcastGroupConfiguration broadcastGroupConfig =
BroadcastGroupControlTest.randomBroadcastGroupConfiguration(connectorInfos);
+ List<TransportConfiguration> connectorList = new
ArrayList<TransportConfiguration>();
+ connectorList.add(connectorConfiguration);
+ BroadcastGroupConfiguration broadcastGroupConfig =
BroadcastGroupControlTest.randomBroadcastGroupConfiguration(connectorList);
Configuration conf = createBasicConfig();
conf.setSecurityEnabled(false);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/ClusterConnectionControl2Test.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/ClusterConnectionControl2Test.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/ClusterConnectionControl2Test.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -129,6 +129,13 @@
null,
false);
+ DiscoveryGroupConfiguration discoveryGroupConfig =
createSimpleUDPDiscoveryGroupConfiguration(discoveryName,
+
null,
+
groupAddress,
+
groupPort,
+
0,
+
0);
+
clusterConnectionConfig_0 = new ClusterConnectionConfiguration(clusterName,
queueConfig.getAddress(),
"netty",
@@ -137,22 +144,17 @@
false,
1,
1024,
- discoveryName);
- List<String> connectorInfos = new ArrayList<String>();
- connectorInfos.add("netty");
- BroadcastGroupConfiguration broadcastGroupConfig = new
BroadcastGroupConfiguration(discoveryName,
-
null,
-
-1,
-
groupAddress,
-
groupPort,
-
250,
-
connectorInfos);
- DiscoveryGroupConfiguration discoveryGroupConfig = new
DiscoveryGroupConfiguration(discoveryName,
-
null,
-
groupAddress,
-
groupPort,
-
0,
-
0);
+
discoveryGroupConfig,
+ false);
+ List<TransportConfiguration> connectorList = new
ArrayList<TransportConfiguration>();
+ connectorList.add(connectorConfig_0);
+ BroadcastGroupConfiguration broadcastGroupConfig =
createBroadcastGroupConfiguration(discoveryName,
+
null,
+
-1,
+
groupAddress,
+
groupPort,
+
250,
+
connectorList);
Configuration conf_1 = createBasicConfig();
conf_1.setSecurityEnabled(false);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/ClusterConnectionControlTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/ClusterConnectionControlTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/ClusterConnectionControlTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -24,6 +24,7 @@
import junit.framework.Assert;
import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
@@ -81,7 +82,7 @@
Assert.assertEquals(clusterConnectionConfig1.getName(),
clusterConnectionControl.getName());
Assert.assertEquals(clusterConnectionConfig1.getAddress(),
clusterConnectionControl.getAddress());
- Assert.assertEquals(clusterConnectionConfig1.getDiscoveryGroupName(),
+
Assert.assertEquals(clusterConnectionConfig1.getDiscoveryGroupConfiguration().getName(),
clusterConnectionControl.getDiscoveryGroupName());
Assert.assertEquals(clusterConnectionConfig1.getRetryInterval(),
clusterConnectionControl.getRetryInterval());
Assert.assertEquals(clusterConnectionConfig1.isDuplicateDetection(),
@@ -93,13 +94,14 @@
Object[] connectors = clusterConnectionControl.getStaticConnectors();
Assert.assertEquals(1, connectors.length);
String connector = (String)connectors[0];
- Assert.assertEquals(clusterConnectionConfig1.getStaticConnectors().get(0),
connector);
+ List<TransportConfiguration> clusterConnectors =
(List<TransportConfiguration>)clusterConnectionConfig1.getDiscoveryGroupConfiguration().getParams().get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME);
+ Assert.assertEquals(clusterConnectors.get(0).getName(), connector);
String jsonString = clusterConnectionControl.getStaticConnectorsAsJSON();
Assert.assertNotNull(jsonString);
JSONArray array = new JSONArray(jsonString);
Assert.assertEquals(1, array.length());
- Assert.assertEquals(clusterConnectionConfig1.getStaticConnectors().get(0),
array.getString(0));
+ Assert.assertEquals(clusterConnectors.get(0).getName(), array.getString(0));
Assert.assertNull(clusterConnectionControl.getDiscoveryGroupName());
@@ -114,7 +116,7 @@
Assert.assertEquals(clusterConnectionConfig2.getName(),
clusterConnectionControl.getName());
Assert.assertEquals(clusterConnectionConfig2.getAddress(),
clusterConnectionControl.getAddress());
- Assert.assertEquals(clusterConnectionConfig2.getDiscoveryGroupName(),
+
Assert.assertEquals(clusterConnectionConfig2.getDiscoveryGroupConfiguration().getName(),
clusterConnectionControl.getDiscoveryGroupName());
Assert.assertEquals(clusterConnectionConfig2.getRetryInterval(),
clusterConnectionControl.getRetryInterval());
Assert.assertEquals(clusterConnectionConfig2.isDuplicateDetection(),
@@ -129,7 +131,7 @@
String jsonPairs = clusterConnectionControl.getStaticConnectorsAsJSON();
Assert.assertNull(jsonPairs);
- Assert.assertEquals(clusterConnectionConfig2.getDiscoveryGroupName(),
+
Assert.assertEquals(clusterConnectionConfig2.getDiscoveryGroupConfiguration().getName(),
clusterConnectionControl.getDiscoveryGroupName());
}
@@ -200,8 +202,7 @@
RandomUtil.randomString(),
null,
false);
- List<String> connectors = new ArrayList<String>();
- connectors.add(connectorConfig.getName());
+ DiscoveryGroupConfiguration staticGroupConfig =
createStaticDiscoveryGroupConfiguration(connectorConfig);
clusterConnectionConfig1 = new
ClusterConnectionConfiguration(RandomUtil.randomString(),
queueConfig.getAddress(),
@@ -211,10 +212,10 @@
RandomUtil.randomBoolean(),
RandomUtil.randomPositiveInt(),
RandomUtil.randomPositiveInt(),
- connectors, false);
+ staticGroupConfig,
false);
String discoveryGroupName = RandomUtil.randomString();
- DiscoveryGroupConfiguration discoveryGroupConfig = new
DiscoveryGroupConfiguration(discoveryGroupName, null, "230.1.2.3", 6745, 500,
0);
+ DiscoveryGroupConfiguration discoveryGroupConfig =
createSimpleUDPDiscoveryGroupConfiguration(discoveryGroupName, null,
"230.1.2.3", 6745, 500, 0);
clusterConnectionConfig2 = new
ClusterConnectionConfiguration(RandomUtil.randomString(),
queueConfig.getAddress(),
@@ -224,7 +225,7 @@
RandomUtil.randomBoolean(),
RandomUtil.randomPositiveInt(),
RandomUtil.randomPositiveInt(),
- discoveryGroupName);
+ discoveryGroupConfig,
false);
Configuration conf_1 = createBasicConfig();
conf_1.setSecurityEnabled(false);
@@ -241,6 +242,7 @@
conf_0.getConnectorConfigurations().put(connectorConfig.getName(),
connectorConfig);
conf_0.getClusterConfigurations().add(clusterConnectionConfig1);
conf_0.getClusterConfigurations().add(clusterConnectionConfig2);
+ conf_0.getDiscoveryGroupConfigurations().put(staticGroupConfig.getName(),
staticGroupConfig);
conf_0.getDiscoveryGroupConfigurations().put(discoveryGroupName,
discoveryGroupConfig);
mbeanServer_1 = MBeanServerFactory.createMBeanServer();
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/HornetQServerControlTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/HornetQServerControlTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/HornetQServerControlTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -643,6 +643,8 @@
session.createQueue(sourceAddress, sourceQueue);
session.createQueue(targetAddress, targetQueue);
+ serverControl.createStaticDiscoveryGroup("static0",
connectorConfig.getName());
+
serverControl.createBridge(name,
sourceQueue,
targetAddress,
@@ -654,9 +656,8 @@
false, // duplicateDetection
1, // confirmationWindowSize
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
- connectorConfig.getName(), // liveConnector
+ "static0", // liveConnector
false,
- false,
null,
null);
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -604,7 +604,6 @@
int confirmationWindowSize,
long clientFailureCheckPeriod,
String connectorNames,
- boolean useDiscovery,
boolean ha,
String user,
String password) throws Exception
@@ -622,7 +621,6 @@
confirmationWindowSize,
clientFailureCheckPeriod,
connectorNames,
- useDiscovery,
ha,
user,
password);
@@ -633,6 +631,27 @@
{
return (String)proxy.invokeOperation("listProducersInfoAsJSON");
}
+
+ public void createStaticDiscoveryGroup(String name, String connectors) throws
Exception
+ {
+ proxy.invokeOperation("createStaticDiscoveryGroup", name,
connectors);
+ }
+
+ public void createSimpleUDPDiscoveryGroup(String name,
+ String localBindAddress,
+ String groupAddress,
+ int groupPort,
+ long refreshTimeout,
+ long initialWaitTimeout) throws
Exception
+ {
+ proxy.invokeOperation("createSimpleUDPDiscoveryGroup",
+ name,
+ localBindAddress,
+ groupAddress,
+ groupPort,
+ refreshTimeout,
+ initialWaitTimeout);
+ }
};
}
// Package protected ---------------------------------------------
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/ra/ResourceAdapterTest.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/ra/ResourceAdapterTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/integration/ra/ResourceAdapterTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -12,10 +12,13 @@
*/
package org.hornetq.tests.integration.ra;
+import org.hornetq.api.core.DiscoveryGroupConstants;
+import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.jms.client.HornetQConnectionFactory;
import org.hornetq.ra.HornetQResourceAdapter;
import org.hornetq.ra.inflow.HornetQActivation;
import org.hornetq.ra.inflow.HornetQActivationSpec;
+import org.hornetq.utils.ConfigurationHelper;
import javax.resource.ResourceException;
import javax.resource.spi.endpoint.MessageEndpoint;
@@ -166,9 +169,15 @@
HornetQResourceAdapter adapter = new HornetQResourceAdapter();
adapter.setDiscoveryAddress("231.1.1.1");
HornetQConnectionFactory factory = adapter.getDefaultHornetQConnectionFactory();
- long initWait =
factory.getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout();
- long refresh = factory.getDiscoveryGroupConfiguration().getRefreshTimeout();
- int port = factory.getDiscoveryGroupConfiguration().getGroupPort();
+ long initWait =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
+
factory.getDiscoveryGroupConfiguration().getParams());
+ long refresh =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT,
+
factory.getDiscoveryGroupConfiguration().getParams());
+ int port =
ConfigurationHelper.getIntProperty(DiscoveryGroupConstants.GROUP_PORT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_PORT,
+
factory.getDiscoveryGroupConfiguration().getParams());
//defaults
assertEquals(10000l, refresh);
@@ -180,8 +189,12 @@
adapter.setDiscoveryPort(9876);
adapter.setDiscoveryRefreshTimeout(1234l);
factory = adapter.getDefaultHornetQConnectionFactory();
- initWait =
factory.getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout();
- refresh = factory.getDiscoveryGroupConfiguration().getRefreshTimeout();
+ initWait =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
+
factory.getDiscoveryGroupConfiguration().getParams());
+ refresh =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT,
+
factory.getDiscoveryGroupConfiguration().getParams());
//override refresh timeout
assertEquals(1234l, refresh);
@@ -192,8 +205,12 @@
adapter.setDiscoveryPort(9876);
adapter.setDiscoveryInitialWaitTimeout(9999l);
factory = adapter.getDefaultHornetQConnectionFactory();
- initWait =
factory.getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout();
- refresh = factory.getDiscoveryGroupConfiguration().getRefreshTimeout();
+ initWait =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
+
factory.getDiscoveryGroupConfiguration().getParams());
+ refresh =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT,
+
factory.getDiscoveryGroupConfiguration().getParams());
//override initial wait
assertEquals(10000l, refresh);
@@ -204,8 +221,12 @@
adapter.setDiscoveryPort(9876);
adapter.setDiscoveryInitialWaitTimeout(9999l);
factory = adapter.getDefaultHornetQConnectionFactory();
- initWait =
factory.getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout();
- refresh = factory.getDiscoveryGroupConfiguration().getRefreshTimeout();
+ initWait =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
+
factory.getDiscoveryGroupConfiguration().getParams());
+ refresh =
ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT,
+
factory.getDiscoveryGroupConfiguration().getParams());
//override initial wait
assertEquals(10000l, refresh);
@@ -274,10 +295,20 @@
spec.setDestinationType("javax.jms.Queue");
spec.setDestination(MDBQUEUE);
HornetQConnectionFactory fac =
qResourceAdapter.createHornetQConnectionFactory(spec);
-
assertEquals(fac.getServerLocator().getDiscoveryGroupConfiguration().getGroupAddress(),
"231.6.6.6");
-
assertEquals(fac.getServerLocator().getDiscoveryGroupConfiguration().getGroupPort(),
1234);
-
assertEquals(fac.getServerLocator().getDiscoveryGroupConfiguration().getRefreshTimeout(),
1l);
-
assertEquals(fac.getServerLocator().getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout(),
1l);
+
assertEquals(fac.getServerLocator().getDiscoveryGroupConfiguration().getParams().get(DiscoveryGroupConstants.GROUP_ADDRESS_NAME),
+ "231.6.6.6");
+
assertEquals(ConfigurationHelper.getIntProperty(DiscoveryGroupConstants.GROUP_PORT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_PORT,
+
fac.getServerLocator().getDiscoveryGroupConfiguration().getParams()),
+ 1234);
+
assertEquals(ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT,
+
fac.getServerLocator().getDiscoveryGroupConfiguration().getParams()),
+ 1l);
+
assertEquals(ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
+
fac.getServerLocator().getDiscoveryGroupConfiguration().getParams()),
+ 1l);
qResourceAdapter.stop();
}
@@ -298,10 +329,20 @@
spec.setDiscoveryInitialWaitTimeout(1l);
spec.setDiscoveryRefreshTimeout(1l);
HornetQConnectionFactory fac =
qResourceAdapter.createHornetQConnectionFactory(spec);
-
assertEquals(fac.getServerLocator().getDiscoveryGroupConfiguration().getGroupAddress(),
"231.6.6.6");
-
assertEquals(fac.getServerLocator().getDiscoveryGroupConfiguration().getGroupPort(),
1234);
-
assertEquals(fac.getServerLocator().getDiscoveryGroupConfiguration().getRefreshTimeout(),
1l);
-
assertEquals(fac.getServerLocator().getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout(),
1l);
+
assertEquals(fac.getServerLocator().getDiscoveryGroupConfiguration().getParams().get(DiscoveryGroupConstants.GROUP_ADDRESS_NAME),
+ "231.6.6.6");
+
assertEquals(ConfigurationHelper.getIntProperty(DiscoveryGroupConstants.GROUP_PORT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_PORT,
+
fac.getServerLocator().getDiscoveryGroupConfiguration().getParams()),
+ 1234);
+
assertEquals(ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT,
+
fac.getServerLocator().getDiscoveryGroupConfiguration().getParams()),
+ 1l);
+
assertEquals(ConfigurationHelper.getLongProperty(DiscoveryGroupConstants.INITIAL_WAIT_TIMEOUT_NAME,
+
HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
+
fac.getServerLocator().getDiscoveryGroupConfiguration().getParams()),
+ 1l);
qResourceAdapter.stop();
}
Modified:
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSClusteredTestBase.java
===================================================================
---
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSClusteredTestBase.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSClusteredTestBase.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -23,6 +23,7 @@
import javax.jms.Topic;
import javax.naming.NamingException;
+import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.jms.HornetQJMSClient;
import org.hornetq.api.jms.JMSFactoryType;
@@ -129,23 +130,21 @@
*/
private void setupServer2() throws Exception
{
- List<String> toOtherServerPair = new ArrayList<String>();
- toOtherServerPair.add("toServer1");
-
Configuration conf2 = createDefaultConfig(1, generateInVMParams(1),
InVMAcceptorFactory.class.getCanonicalName());
conf2.setSecurityEnabled(false);
conf2.setJMXManagementEnabled(true);
conf2.setPersistenceEnabled(false);
- conf2.getConnectorConfigurations().put("toServer1",
- new
TransportConfiguration(InVMConnectorFactory.class.getName(),
-
generateInVMParams(0)));
+ TransportConfiguration toServer1 = new
TransportConfiguration(InVMConnectorFactory.class.getName(), generateInVMParams(0));
+ conf2.getConnectorConfigurations().put("toServer1", toServer1);
conf2.getConnectorConfigurations().put("server2",
new
TransportConfiguration(InVMConnectorFactory.class.getName(),
generateInVMParams(1)));
conf2.setClustered(true);
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(toServer1);
+ conf2.getDiscoveryGroupConfigurations().put(groupConf.getName(), groupConf);
conf2.getClusterConfigurations().add(new
ClusterConnectionConfiguration("to-server1",
"jms",
"server2",
@@ -154,7 +153,7 @@
false,
MAX_HOPS,
1024,
-
toOtherServerPair, false));
+ groupConf,
false));
JMSConfigurationImpl jmsconfig = new JMSConfigurationImpl();
@@ -173,24 +172,22 @@
*/
private void setupServer1() throws Exception
{
- List<String> toOtherServerPair = new ArrayList<String>();
- toOtherServerPair.add("toServer2");
-
Configuration conf1 = createDefaultConfig(0, generateInVMParams(0),
InVMAcceptorFactory.class.getCanonicalName());
conf1.setSecurityEnabled(false);
conf1.setJMXManagementEnabled(true);
conf1.setPersistenceEnabled(false);
- conf1.getConnectorConfigurations().put("toServer2",
- new
TransportConfiguration(InVMConnectorFactory.class.getName(),
-
generateInVMParams(1)));
+ TransportConfiguration toServer2 = new
TransportConfiguration(InVMConnectorFactory.class.getName(), generateInVMParams(1));
+ conf1.getConnectorConfigurations().put("toServer2", toServer2);
conf1.getConnectorConfigurations().put("server1",
new
TransportConfiguration(InVMConnectorFactory.class.getName(),
generateInVMParams(0)));
conf1.setClustered(true);
+ DiscoveryGroupConfiguration groupConf =
createStaticDiscoveryGroupConfiguration(toServer2);
+ conf1.getDiscoveryGroupConfigurations().put(groupConf.getName(), groupConf);
conf1.getClusterConfigurations().add(new
ClusterConnectionConfiguration("to-server2",
"jms",
"server1",
@@ -199,7 +196,7 @@
false,
MAX_HOPS,
1024,
-
toOtherServerPair, false));
+ groupConf,
false));
JMSConfigurationImpl jmsconfig = new JMSConfigurationImpl();
Modified:
branches/HORNETQ-316/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/config/impl/FileConfigurationTest.java
===================================================================
---
branches/HORNETQ-316/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/config/impl/FileConfigurationTest.java 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/config/impl/FileConfigurationTest.java 2011-08-25
19:23:40 UTC (rev 11225)
@@ -13,13 +13,17 @@
package org.hornetq.tests.unit.core.config.impl;
+import java.util.List;
+
import junit.framework.Assert;
import org.hornetq.api.core.DiscoveryGroupConfiguration;
+import org.hornetq.api.core.DiscoveryGroupConstants;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.core.config.BridgeConfiguration;
import org.hornetq.core.config.BroadcastGroupConfiguration;
+import org.hornetq.core.config.BroadcastGroupConstants;
import org.hornetq.core.config.ClusterConnectionConfiguration;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.DivertConfiguration;
@@ -135,38 +139,49 @@
if (bc.getName().equals("bg1"))
{
Assert.assertEquals("bg1", bc.getName());
- Assert.assertEquals(10999, bc.getLocalBindPort());
- Assert.assertEquals("192.168.0.120", bc.getGroupAddress());
- Assert.assertEquals(11999, bc.getGroupPort());
- Assert.assertEquals(12345, bc.getBroadcastPeriod());
- Assert.assertEquals("connector1", bc.getConnectorInfos().get(0));
+ Assert.assertEquals(10999, new
Integer((String)bc.getParams().get(BroadcastGroupConstants.LOCAL_BIND_PORT_NAME)).intValue());
+ Assert.assertEquals("192.168.0.120",
bc.getParams().get(BroadcastGroupConstants.GROUP_ADDRESS_NAME));
+ Assert.assertEquals(11999, new
Integer((String)bc.getParams().get(BroadcastGroupConstants.GROUP_PORT_NAME)).intValue());
+ Assert.assertEquals(12345, new
Long((String)bc.getParams().get(BroadcastGroupConstants.BROADCAST_PERIOD_NAME)).longValue());
+ Assert.assertEquals("connector1",
bc.getConnectorList().get(0).getName());
}
else
{
- Assert.assertEquals("bg2", bc.getName());
- Assert.assertEquals(12999, bc.getLocalBindPort());
- Assert.assertEquals("192.168.0.121", bc.getGroupAddress());
- Assert.assertEquals(13999, bc.getGroupPort());
- Assert.assertEquals(23456, bc.getBroadcastPeriod());
- Assert.assertEquals("connector2", bc.getConnectorInfos().get(0));
+ Assert.assertEquals(12999, new
Integer((String)bc.getParams().get(BroadcastGroupConstants.LOCAL_BIND_PORT_NAME)).intValue());
+ Assert.assertEquals("192.168.0.121",
bc.getParams().get(BroadcastGroupConstants.GROUP_ADDRESS_NAME));
+ Assert.assertEquals(13999, new
Integer((String)bc.getParams().get(BroadcastGroupConstants.GROUP_PORT_NAME)).intValue());
+ Assert.assertEquals(23456, new
Long((String)bc.getParams().get(BroadcastGroupConstants.BROADCAST_PERIOD_NAME)).longValue());
+ Assert.assertEquals("connector2",
bc.getConnectorList().get(0).getName());
}
}
- Assert.assertEquals(2, conf.getDiscoveryGroupConfigurations().size());
+ Assert.assertEquals(4, conf.getDiscoveryGroupConfigurations().size());
DiscoveryGroupConfiguration dc =
conf.getDiscoveryGroupConfigurations().get("dg1");
Assert.assertEquals("dg1", dc.getName());
- Assert.assertEquals("192.168.0.120", dc.getGroupAddress());
- assertEquals("172.16.8.10", dc.getLocalBindAddress());
- Assert.assertEquals(11999, dc.getGroupPort());
- Assert.assertEquals(12345, dc.getRefreshTimeout());
+ Assert.assertEquals("192.168.0.120",
dc.getParams().get(DiscoveryGroupConstants.GROUP_ADDRESS_NAME));
+ Assert.assertEquals("172.16.8.10",
dc.getParams().get(DiscoveryGroupConstants.LOCAL_BIND_ADDRESS_NAME));
+ Assert.assertEquals(11999, new
Integer((String)dc.getParams().get(DiscoveryGroupConstants.GROUP_PORT_NAME)).intValue());
+ Assert.assertEquals(12345, new
Long((String)dc.getParams().get(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME)).longValue());
+
dc = conf.getDiscoveryGroupConfigurations().get("dg2");
Assert.assertEquals("dg2", dc.getName());
- Assert.assertEquals("192.168.0.121", dc.getGroupAddress());
- assertEquals("172.16.8.11", dc.getLocalBindAddress());
- Assert.assertEquals(12999, dc.getGroupPort());
- Assert.assertEquals(23456, dc.getRefreshTimeout());
+ Assert.assertEquals("192.168.0.121",
dc.getParams().get(DiscoveryGroupConstants.GROUP_ADDRESS_NAME));
+ Assert.assertEquals("172.16.8.11",
dc.getParams().get(DiscoveryGroupConstants.LOCAL_BIND_ADDRESS_NAME));
+ Assert.assertEquals(12999, new
Integer((String)dc.getParams().get(DiscoveryGroupConstants.GROUP_PORT_NAME)).intValue());
+ Assert.assertEquals(23456, new
Long((String)dc.getParams().get(DiscoveryGroupConstants.REFRESH_TIMEOUT_NAME)).longValue());
+ dc = conf.getDiscoveryGroupConfigurations().get("sdg1");
+ Assert.assertEquals("sdg1", dc.getName());
+ Assert.assertEquals("connector1",
dc.getParams().get(DiscoveryGroupConstants.STATIC_CONNECTORS_CONNECTOR_NAMES_NAME));
+ Assert.assertEquals("connector1",
((List<TransportConfiguration>)dc.getParams().get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME)).get(0).getName());
+
+ dc = conf.getDiscoveryGroupConfigurations().get("sdg12");
+ Assert.assertEquals("sdg12", dc.getName());
+ Assert.assertEquals("connector1,connector2",
dc.getParams().get(DiscoveryGroupConstants.STATIC_CONNECTORS_CONNECTOR_NAMES_NAME));
+ Assert.assertEquals("connector1",
((List<TransportConfiguration>)dc.getParams().get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME)).get(0).getName());
+ Assert.assertEquals("connector2",
((List<TransportConfiguration>)dc.getParams().get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME)).get(1).getName());
+
Assert.assertEquals(2, conf.getDivertConfigurations().size());
for (DivertConfiguration dic : conf.getDivertConfigurations())
{
@@ -206,8 +221,7 @@
Assert.assertEquals(0.2, bc.getRetryIntervalMultiplier());
Assert.assertEquals(2, bc.getReconnectAttempts());
Assert.assertEquals(true, bc.isUseDuplicateDetection());
- Assert.assertEquals("connector1",
bc.getStaticConnectors().get(0));
- Assert.assertEquals(null, bc.getDiscoveryGroupName());
+ Assert.assertEquals("connector1",
((List<TransportConfiguration>)bc.getDiscoveryGroupConfiguration().getParams().get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME)).get(0).getName());
}
else
{
@@ -216,8 +230,7 @@
Assert.assertEquals("bridge-forwarding-address2",
bc.getForwardingAddress());
Assert.assertEquals(null, bc.getFilterString());
Assert.assertEquals(null, bc.getTransformerClassName());
- Assert.assertEquals(null, bc.getStaticConnectors());
- Assert.assertEquals("dg1", bc.getDiscoveryGroupName());
+ Assert.assertEquals("dg1",
bc.getDiscoveryGroupConfiguration().getName());
}
}
@@ -232,9 +245,9 @@
Assert.assertEquals(true, ccc.isDuplicateDetection());
Assert.assertEquals(false, ccc.isForwardWhenNoConsumers());
Assert.assertEquals(1, ccc.getMaxHops());
- Assert.assertEquals("connector1",
ccc.getStaticConnectors().get(0));
- Assert.assertEquals("connector2",
ccc.getStaticConnectors().get(1));
- Assert.assertEquals(null, ccc.getDiscoveryGroupName());
+ Assert.assertEquals("connector1",
((List<TransportConfiguration>)ccc.getDiscoveryGroupConfiguration().getParams().get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME)).get(0).getName());
+ Assert.assertEquals("connector2",
((List<TransportConfiguration>)ccc.getDiscoveryGroupConfiguration().getParams().get(DiscoveryGroupConstants.STATIC_CONNECTORS_LIST_NAME)).get(1).getName());
+
}
else
{
@@ -244,8 +257,7 @@
Assert.assertEquals(false, ccc.isDuplicateDetection());
Assert.assertEquals(true, ccc.isForwardWhenNoConsumers());
Assert.assertEquals(2, ccc.getMaxHops());
- Assert.assertEquals(null, ccc.getStaticConnectors());
- Assert.assertEquals("dg1", ccc.getDiscoveryGroupName());
+ Assert.assertEquals("dg1",
ccc.getDiscoveryGroupConfiguration().getName());
}
}
Modified:
branches/HORNETQ-316/tests/unit-tests/src/test/resources/ConfigurationTest-full-config.xml
===================================================================
---
branches/HORNETQ-316/tests/unit-tests/src/test/resources/ConfigurationTest-full-config.xml 2011-08-25
05:25:43 UTC (rev 11224)
+++
branches/HORNETQ-316/tests/unit-tests/src/test/resources/ConfigurationTest-full-config.xml 2011-08-25
19:23:40 UTC (rev 11225)
@@ -82,34 +82,47 @@
</acceptor>
</acceptors>
<broadcast-groups>
- <broadcast-group name="bg1">
- <local-bind-port>10999</local-bind-port>
- <group-address>192.168.0.120</group-address>
- <group-port>11999</group-port>
- <broadcast-period>12345</broadcast-period>
+ <broadcast-group name="bg1">
+
<broadcast-group-class>org.hornetq.core.server.cluster.impl.BroadcastGroupImpl</broadcast-group-class>
+ <param key="local-bind-port" value="10999"/>
+ <param key="group-address" value="192.168.0.120"/>
+ <param key="group-port" value="11999"/>
+ <param key="broadcast-period" value="12345"/>
<connector-ref>connector1</connector-ref>
- </broadcast-group>
+ </broadcast-group>
<broadcast-group name="bg2">
- <local-bind-port>12999</local-bind-port>
- <group-address>192.168.0.121</group-address>
- <group-port>13999</group-port>
- <broadcast-period>23456</broadcast-period>
+
<broadcast-group-class>org.hornetq.core.server.cluster.impl.BroadcastGroupImpl</broadcast-group-class>
<connector-ref>connector2</connector-ref>
+ <param key="local-bind-port" value="12999"/>
+ <param key="group-address" value="192.168.0.121"/>
+ <param key="group-port" value="13999"/>
+ <param key="broadcast-period" value="23456"/>
+ <connector-ref>connector2</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="dg1">
- <local-bind-address>172.16.8.10</local-bind-address>
- <group-address>192.168.0.120</group-address>
- <group-port>11999</group-port>
- <refresh-timeout>12345</refresh-timeout>
+
<server-locator-class>org.hornetq.core.client.impl.SimpleUDPServerLocatorImpl</server-locator-class>
+ <param key="local-bind-address"
value="172.16.8.10"/>
+ <param key="group-address" value="192.168.0.120"/>
+ <param key="group-port" value="11999"/>
+ <param key="refresh-timeout" value="12345"/>
</discovery-group>
<discovery-group name="dg2">
- <local-bind-address>172.16.8.11</local-bind-address>
- <group-address>192.168.0.121</group-address>
- <group-port>12999</group-port>
- <refresh-timeout>23456</refresh-timeout>
+
<server-locator-class>org.hornetq.core.client.impl.SimpleUDPServerLocatorImpl</server-locator-class>
+ <param key="local-bind-address"
value="172.16.8.11"/>
+ <param key="group-address" value="192.168.0.121"/>
+ <param key="group-port" value="12999"/>
+ <param key="refresh-timeout" value="23456"/>
</discovery-group>
+ <discovery-group name="sdg1">
+
<server-locator-class>org.hornetq.core.client.impl.StaticServerLocatorImpl</server-locator-class>
+ <param key="static-connector-names"
value="connector1"/>
+ </discovery-group>
+ <discovery-group name="sdg12">
+
<server-locator-class>org.hornetq.core.client.impl.StaticServerLocatorImpl</server-locator-class>
+ <param key="static-connector-names"
value="connector1,connector2"/>
+ </discovery-group>
</discovery-groups>
<diverts>
<divert name="divert1">
@@ -152,9 +165,7 @@
<reconnect-attempts>2</reconnect-attempts>
<failover-on-server-shutdown>false</failover-on-server-shutdown>
<use-duplicate-detection>true</use-duplicate-detection>
- <static-connectors>
- <connector-ref>connector1</connector-ref>
- </static-connectors>
+ <discovery-group-ref discovery-group-name="sdg1"/>
</bridge>
<bridge name="bridge2">
<queue-name>queue2</queue-name>
@@ -170,10 +181,7 @@
<use-duplicate-detection>true</use-duplicate-detection>
<forward-when-no-consumers>false</forward-when-no-consumers>
<max-hops>1</max-hops>
- <static-connectors>
- <connector-ref>connector1</connector-ref>
- <connector-ref>connector2</connector-ref>
- </static-connectors>
+ <discovery-group-ref discovery-group-name="sdg12"/>
</cluster-connection>
<cluster-connection name="cluster-connection2">
<address>queues2</address>