JBoss hornetq SVN: r11226 - in branches/Branch_2_2_EAP: src/main/org/hornetq/core/server/cluster/impl and 2 other directories.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2011-08-25 22:41:29 -0400 (Thu, 25 Aug 2011)
New Revision: 11226
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/TopologyMember.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterConnectionImpl.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/SimpleSymmetricClusterTest.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java
Log:
fixing testsuite
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2011-08-25 19:23:40 UTC (rev 11225)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2011-08-26 02:41:29 UTC (rev 11226)
@@ -1839,7 +1839,10 @@
private void doCleanup(boolean failingOver)
{
- remotingConnection.removeFailureListener(this);
+ if (remotingConnection == null)
+ {
+ remotingConnection.removeFailureListener(this);
+ }
if (log.isDebugEnabled())
{
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java 2011-08-25 19:23:40 UTC (rev 11225)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java 2011-08-26 02:41:29 UTC (rev 11226)
@@ -30,12 +30,14 @@
/**
* @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
+ * @author Clebert Suconic
* Created Aug 16, 2010
*/
public class Topology implements Serializable
{
- private static final int BACKOF_TIMEOUT = 500;
+ // TODO: remove the backof from this class. It's probably not needed any longer
+ // private static final int BACKOF_TIMEOUT = 500;
private static final long serialVersionUID = -9037171688692471371L;
@@ -43,7 +45,7 @@
private static final Logger log = Logger.getLogger(Topology.class);
- private transient HashMap<String, Pair<Long, Integer>> mapBackof = new HashMap<String, Pair<Long, Integer>>();
+ // private transient HashMap<String, Pair<Long, Integer>> mapBackof = new HashMap<String, Pair<Long, Integer>>();
private Executor executor = null;
@@ -62,13 +64,16 @@
* keys are node IDs
* values are a pair of live/backup transport configurations
*/
- private final Map<String, TopologyMember> topology = new ConcurrentHashMap<String, TopologyMember>();
+ private final Map<String, TopologyMember> mapTopology = new ConcurrentHashMap<String, TopologyMember>();
public Topology(final Object owner)
{
this.owner = owner;
- Topology.log.debug("Topology@" + Integer.toHexString(System.identityHashCode(this)) + " CREATE",
- new Exception("trace")); // Delete this line
+ if (log.isTraceEnabled())
+ {
+ Topology.log.trace("Topology@" + Integer.toHexString(System.identityHashCode(this)) + " CREATE",
+ new Exception("trace"));
+ }
}
public void setExecutor(final Executor executor)
@@ -100,143 +105,156 @@
}
}
- public boolean addMember(final String nodeId, final TopologyMember member, final boolean last)
+ public boolean addMember(final String nodeId, final TopologyMember memberInput, final boolean last)
{
- boolean replaced = false;
-
synchronized (this)
{
- TopologyMember currentMember = topology.get(nodeId);
+ TopologyMember currentMember = mapTopology.get(nodeId);
- if (Topology.log.isDebugEnabled())
- {
- Topology.log.debug(this + "::adding = " + nodeId + ":" + member.getConnector(), new Exception("trace"));
- }
-
if (currentMember == null)
{
- if (!testBackof(nodeId))
+ /*if (!testBackof(nodeId))
{
return false;
- }
+ } */
- replaced = true;
if (Topology.log.isDebugEnabled())
{
- Topology.log.debug("Add " + this +
+ Topology.log.debug(this + "::NewMemeberAdd " + this +
" MEMBER WAS NULL, Add member nodeId=" +
nodeId +
" member = " +
- member +
- " replaced = " +
- replaced +
+ memberInput +
" size = " +
- topology.size(), new Exception("trace"));
+ mapTopology.size(), new Exception("trace"));
}
- topology.put(nodeId, member);
+ mapTopology.put(nodeId, memberInput);
+ sendMemberUp(nodeId, memberInput);
+ return true;
}
else
{
- if (hasChanged(currentMember.getConnector().a, member.getConnector().a) && member.getConnector().a != null)
+ if (log.isTraceEnabled())
{
- if (!testBackof(nodeId))
+ log.trace(this + ":: validating update for currentMember=" + currentMember + " of memberInput=" + memberInput);
+ }
+
+ boolean replaced = false;
+ TopologyMember memberToSend = currentMember;
+
+ if (hasChanged("a", memberToSend.getConnector().a, memberInput.getConnector().a))
+ {
+ /*if (!replaced && !testBackof(nodeId))
{
return false;
- }
-
- currentMember.getConnector().a = member.getConnector().a;
+ }*/
+ memberToSend = new TopologyMember(memberInput.getConnector().a, memberToSend.getConnector().b);
replaced = true;
}
- if (hasChanged(currentMember.getConnector().b, member.getConnector().b) && member.getConnector().b != null)
+
+ if (hasChanged("b", memberToSend.getConnector().b, memberInput.getConnector().b))
{
- if (!testBackof(nodeId))
+ /*if (!replaced && !testBackof(nodeId))
{
return false;
- }
-
- currentMember.getConnector().b = member.getConnector().b;
+ }*/
+ memberToSend = new TopologyMember(memberToSend.getConnector().a, memberInput.getConnector().b);
replaced = true;
}
- if (member.getConnector().a == null)
+ if (replaced)
{
- member.getConnector().a = currentMember.getConnector().a;
+ mapTopology.remove(nodeId);
+ mapTopology.put(nodeId, memberToSend);
+
+ sendMemberUp(nodeId, memberToSend);
+ return true;
}
- if (member.getConnector().b == null)
- {
- member.getConnector().b = currentMember.getConnector().b;
- }
- }
- if (Topology.log.isDebugEnabled())
- {
- Topology.log.debug(this + " Add member nodeId=" +
- nodeId +
- " member = " +
- member +
- " replaced = " +
- replaced +
- " size = " +
- topology.size(), new Exception("trace"));
}
}
- if (replaced)
+ if (Topology.log.isDebugEnabled())
{
+ Topology.log.debug(Topology.this + " Add member nodeId=" +
+ nodeId +
+ " member = " +
+ memberInput +
+ " has been ignored since there was no change", new Exception("trace"));
+ }
- final ArrayList<ClusterTopologyListener> copy = copyListeners();
+ return false;
+ }
- execute(new Runnable()
+ /**
+ * @param nodeId
+ * @param memberToSend
+ */
+ private void sendMemberUp(final String nodeId, final TopologyMember memberToSend)
+ {
+ final ArrayList<ClusterTopologyListener> copy = copyListeners();
+
+ if (log.isTraceEnabled())
+ {
+ log.trace(this + "::prepare to send " + nodeId + " to " + copy.size() + " elements");
+ }
+
+ execute(new Runnable()
+ {
+ public void run()
{
- public void run()
+ for (ClusterTopologyListener listener : copy)
{
- for (ClusterTopologyListener listener : copy)
+ if (Topology.log.isTraceEnabled())
{
- if (Topology.log.isTraceEnabled())
- {
- Topology.log.trace(this + " informing " + listener + " about node up = " + nodeId);
- }
+ Topology.log.trace(Topology.this + " informing " + listener + " about node up = " + nodeId);
+ }
- try
- {
- listener.nodeUP(nodeId, member.getConnector(), last);
- }
- catch (Throwable e)
- {
- log.warn(e.getMessage(), e);
- }
+ try
+ {
+ listener.nodeUP(nodeId, memberToSend.getConnector(), false);
}
+ catch (Throwable e)
+ {
+ log.warn(e.getMessage(), e);
+ }
}
- });
- }
-
- return replaced;
+ }
+ });
}
/**
* @param nodeId
* @param backOfData
*/
- private boolean testBackof(final String nodeId)
+ /*private boolean testBackof(final String nodeId)
{
Pair<Long, Integer> backOfData = mapBackof.get(nodeId);
if (backOfData != null)
{
backOfData.b += 1;
-
+
long timeDiff = System.currentTimeMillis() - backOfData.a;
// To prevent a loop where nodes are being considered down and up
if (backOfData.b > 5 && timeDiff < BACKOF_TIMEOUT)
{
+
// The cluster may get in loop without this..
// Case one node is stll sending nodeDown while another member is sending nodeUp
- log.warn("The topology controller identified a blast events and it's interrupting the flow of the loop",
+ log.warn(backOfData.b + ", The topology controller identified a blast events and it's interrupting the flow of the loop, nodeID=" +
+ nodeId +
+ ", topologyInstance=" +
+ this,
new Exception("this exception is just to trace location"));
return false;
}
+ else if (timeDiff < BACKOF_TIMEOUT)
+ {
+ log.warn(this + "::Simple blast of " + nodeId, new Exception("this exception is just to trace location"));
+ }
else if (timeDiff >= BACKOF_TIMEOUT)
{
mapBackof.remove(nodeId);
@@ -244,7 +262,7 @@
}
return true;
- }
+ } */
/**
* @return
@@ -265,22 +283,22 @@
synchronized (this)
{
- Pair<Long, Integer> value = mapBackof.get(nodeId);
+// Pair<Long, Integer> value = mapBackof.get(nodeId);
+//
+// if (value == null)
+// {
+// value = new Pair<Long, Integer>(0l, 0);
+// mapBackof.put(nodeId, value);
+// }
+//
+// value.a = System.currentTimeMillis();
+//
+// if (System.currentTimeMillis() - value.a > BACKOF_TIMEOUT)
+// {
+// value.b = 0;
+// }
- if (value == null)
- {
- value = new Pair<Long, Integer>(0l, 0);
- mapBackof.put(nodeId, value);
- }
-
- value.a = System.currentTimeMillis();
-
- if (System.currentTimeMillis() - value.a > BACKOF_TIMEOUT)
- {
- value.b = 0;
- }
-
- member = topology.remove(nodeId);
+ member = mapTopology.remove(nodeId);
}
if (Topology.log.isDebugEnabled())
@@ -291,7 +309,7 @@
", result=" +
member +
", size = " +
- topology.size(), new Exception("trace"));
+ mapTopology.size(), new Exception("trace"));
}
if (member != null)
@@ -376,19 +394,19 @@
log.debug(this + " is sending topology to " + listener);
}
- final Map<String, TopologyMember> copy;
-
- synchronized (this)
- {
- copy = new HashMap<String, TopologyMember>(topology);
- }
-
execute(new Runnable()
{
public void run()
{
int count = 0;
+ final Map<String, TopologyMember> copy;
+
+ synchronized (Topology.this)
+ {
+ copy = new HashMap<String, TopologyMember>(mapTopology);
+ }
+
for (Map.Entry<String, TopologyMember> entry : copy.entrySet())
{
if (log.isDebugEnabled())
@@ -408,12 +426,12 @@
public TopologyMember getMember(final String nodeID)
{
- return topology.get(nodeID);
+ return mapTopology.get(nodeID);
}
public boolean isEmpty()
{
- return topology.isEmpty();
+ return mapTopology.isEmpty();
}
public Collection<TopologyMember> getMembers()
@@ -421,7 +439,7 @@
ArrayList<TopologyMember> members;
synchronized (this)
{
- members = new ArrayList<TopologyMember>(topology.values());
+ members = new ArrayList<TopologyMember>(mapTopology.values());
}
return members;
}
@@ -429,7 +447,7 @@
public synchronized int nodes()
{
int count = 0;
- for (TopologyMember member : topology.values())
+ for (TopologyMember member : mapTopology.values())
{
if (member.getConnector().a != null)
{
@@ -452,7 +470,7 @@
{
String desc = text + "\n";
- for (Entry<String, TopologyMember> entry : new HashMap<String, TopologyMember>(topology).entrySet())
+ for (Entry<String, TopologyMember> entry : new HashMap<String, TopologyMember>(mapTopology).entrySet())
{
desc += "\t" + entry.getKey() + " => " + entry.getValue() + "\n";
}
@@ -466,12 +484,12 @@
{
Topology.log.debug(this + "::clear", new Exception("trace"));
}
- topology.clear();
+ mapTopology.clear();
}
public int members()
{
- return topology.size();
+ return mapTopology.size();
}
/** The owner exists mainly for debug purposes.
@@ -482,16 +500,26 @@
this.owner = owner;
}
- private boolean hasChanged(final TransportConfiguration currentConnector, final TransportConfiguration connector)
+ private boolean hasChanged(final String debugInfo, final TransportConfiguration a, final TransportConfiguration b)
{
- return currentConnector == null && connector != null ||
- currentConnector != null &&
- !currentConnector.equals(connector);
+ boolean changed = a == null && b != null || a != null && b != null && !a.equals(b);
+
+ if (log.isTraceEnabled())
+ {
+
+ log.trace(this + "::Validating current=" + a
+ + " != input=" + b +
+ (changed ? " and it has changed" : " and it didn't change") +
+ ", for validation of " +
+ debugInfo);
+ }
+
+ return changed;
}
public TransportConfiguration getBackupForConnector(final TransportConfiguration connectorConfiguration)
{
- for (TopologyMember member : topology.values())
+ for (TopologyMember member : mapTopology.values())
{
if (member.getConnector().a != null && member.getConnector().a.equals(connectorConfiguration))
{
@@ -509,7 +537,7 @@
{
if (owner == null)
{
- return super.toString();
+ return "Topology@" + Integer.toHexString(System.identityHashCode(this));
}
else
{
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/TopologyMember.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/TopologyMember.java 2011-08-25 19:23:40 UTC (rev 11225)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/TopologyMember.java 2011-08-26 02:41:29 UTC (rev 11226)
@@ -32,6 +32,11 @@
this.connector = connector;
}
+ public TopologyMember(TransportConfiguration a, TransportConfiguration b)
+ {
+ this(new Pair<TransportConfiguration, TransportConfiguration>(a, b));
+ }
+
public Pair<TransportConfiguration, TransportConfiguration> getConnector()
{
return connector;
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterConnectionImpl.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterConnectionImpl.java 2011-08-25 19:23:40 UTC (rev 11225)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterConnectionImpl.java 2011-08-26 02:41:29 UTC (rev 11226)
@@ -564,6 +564,10 @@
{
if (connectorPair.b != null)
{
+ if (log.isTraceEnabled())
+ {
+ log.trace(this + "::informing about backup to itself, nodeUUID=" + nodeUUID + ", connectorPair=" + connectorPair + " this = " + this);
+ }
server.getClusterManager().notifyNodeUp(nodeID, connectorPair, last, false);
}
return;
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java 2011-08-25 19:23:40 UTC (rev 11225)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java 2011-08-26 02:41:29 UTC (rev 11226)
@@ -2021,9 +2021,9 @@
for (int node : nodes)
{
log.info("#test start node " + node);
- if (System.currentTimeMillis() - timeStarts[node] < 1000)
+ if (System.currentTimeMillis() - timeStarts[node] < 100)
{
- Thread.sleep(1000);
+ Thread.sleep(100);
}
timeStarts[node] = System.currentTimeMillis();
@@ -2065,10 +2065,10 @@
{
try
{
- if (System.currentTimeMillis() - timeStarts[node] < 1000)
+ if (System.currentTimeMillis() - timeStarts[node] < 100)
{
// We can't stop and start a node too fast (faster than what the Topology could realize about this
- Thread.sleep(1000);
+ Thread.sleep(100);
}
timeStarts[node] = System.currentTimeMillis();
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/SimpleSymmetricClusterTest.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/SimpleSymmetricClusterTest.java 2011-08-25 19:23:40 UTC (rev 11225)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/SimpleSymmetricClusterTest.java 2011-08-26 02:41:29 UTC (rev 11226)
@@ -112,7 +112,6 @@
setupClusterConnection("cluster2", "queues", false, 1, isNetty(), 2, 3, 4);
- // startServers(3, 4, 5, 0, 1, 2);
startServers(0, 1, 2, 3, 4, 5);
log.info("");
@@ -122,11 +121,7 @@
log.info(debugBindings(servers[i], servers[i].getConfiguration().getManagementNotificationAddress().toString()));
}
log.info("");
-
- //stopServers(3);
-
- Thread.sleep(1000);
-
+
log.info("");
for (int i = 0; i <= 5; i++)
{
@@ -168,21 +163,13 @@
setupSessionFactory(1, isNetty());
setupSessionFactory(2, isNetty());
- // Thread.sleep(1500);
-
createQueue(0, "queues.testaddress", "queue0", null, false);
- // Thread.sleep(1500);
createQueue(1, "queues.testaddress", "queue0", null, false);
- // Thread.sleep(1500);
createQueue(2, "queues.testaddress", "queue0", null, false);
- // Thread.sleep(1500);
addConsumer(0, 0, "queue0", null);
- // Thread.sleep(1500);
addConsumer(1, 1, "queue0", null);
- // Thread.sleep(1500);
addConsumer(2, 2, "queue0", null);
- // Thread.sleep(1500);
waitForBindings(0, "queues.testaddress", 1, 1, true);
waitForBindings(1, "queues.testaddress", 1, 1, true);
@@ -291,21 +278,14 @@
// Need to wait some time so the bridges and
// connectors had time to connect properly between the nodes
- Thread.sleep(1000);
createQueue(0, "queues.testaddress", "queue0", null, true);
- // Thread.sleep(1500);
createQueue(1, "queues.testaddress", "queue0", null, true);
- // Thread.sleep(1500);
createQueue(2, "queues.testaddress", "queue0", null, true);
- // Thread.sleep(1500);
addConsumer(0, 0, "queue0", null);
- // Thread.sleep(1500);
addConsumer(1, 1, "queue0", null);
- // Thread.sleep(1500);
addConsumer(2, 2, "queue0", null);
- // Thread.sleep(1500);
waitForBindings(0, "queues.testaddress", 1, 1, true);
waitForBindings(1, "queues.testaddress", 1, 1, true);
@@ -375,21 +355,13 @@
setupSessionFactory(1, isNetty());
setupSessionFactory(2, isNetty());
- // Thread.sleep(1500);
-
createQueue(0, "queues.testaddress", "queue0", null, true);
- // Thread.sleep(1500);
createQueue(1, "queues.testaddress", "queue0", null, true);
- // Thread.sleep(1500);
createQueue(2, "queues.testaddress", "queue0", null, true);
- // Thread.sleep(1500);
addConsumer(0, 0, "queue0", null);
- // Thread.sleep(1500);
addConsumer(1, 1, "queue0", null);
- // Thread.sleep(1500);
addConsumer(2, 2, "queue0", null);
- // Thread.sleep(1500);
waitForBindings(0, "queues.testaddress", 1, 1, true);
waitForBindings(1, "queues.testaddress", 1, 1, true);
@@ -402,16 +374,8 @@
send(0, "queues.testaddress", 33, true, null);
verifyReceiveRoundRobin(33, 0, 1, 2);
-
- Thread.sleep(1000);
- // TODO: need to make sure the shutdown won't be send, what will affect the test
stopServers(2);
-//
-// Thread.sleep(5000);
-//
-// waitForBindings(0, "queues.testaddress", 2, 2, false);
-// waitForBindings(1, "queues.testaddress", 2, 2, false);
send(0, "queues.testaddress", 100, true, null);
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java 2011-08-25 19:23:40 UTC (rev 11225)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java 2011-08-26 02:41:29 UTC (rev 11226)
@@ -395,6 +395,8 @@
backupJMSService.setContext(ctx2);
+ backupJMSService.getHornetQServer().setIdentity("JMSBackup");
+ log.info("Starting backup");
backupJMSService.start();
liveConf = createBasicConfig(0);
@@ -432,6 +434,9 @@
liveJMSService.setContext(ctx1);
+ liveJMSService.getHornetQServer().setIdentity("JMSLive");
+ log.info("Starting life");
+
liveJMSService.start();
JMSUtil.waitForServer(backupService);
13 years, 6 months
JBoss hornetq SVN: r11225 - in branches/HORNETQ-316: distribution/hornetq/src/main/assembly and 42 other directories.
by do-not-reply@jboss.org
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>
13 years, 6 months
JBoss hornetq SVN: r11224 - branches.
by do-not-reply@jboss.org
Author: gaohoward
Date: 2011-08-25 01:25:43 -0400 (Thu, 25 Aug 2011)
New Revision: 11224
Added:
branches/STOMP11/
Log:
Implement stomp 1.1 support
13 years, 6 months
JBoss hornetq SVN: r11223 - branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2011-08-24 20:20:34 -0400 (Wed, 24 Aug 2011)
New Revision: 11223
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java
Log:
fixing tests
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java 2011-08-24 23:55:01 UTC (rev 11222)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java 2011-08-25 00:20:34 UTC (rev 11223)
@@ -35,7 +35,7 @@
public class Topology implements Serializable
{
- private static final int BACKOF_TIMEOUT = 50;
+ private static final int BACKOF_TIMEOUT = 500;
private static final long serialVersionUID = -9037171688692471371L;
13 years, 6 months
JBoss hornetq SVN: r11222 - branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2011-08-24 19:55:01 -0400 (Wed, 24 Aug 2011)
New Revision: 11222
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java
Log:
just cleanup (no code changes)
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java 2011-08-24 23:51:12 UTC (rev 11221)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java 2011-08-24 23:55:01 UTC (rev 11222)
@@ -83,9 +83,9 @@
private static final Logger log = Logger.getLogger(ClientSessionFactoryImpl.class);
- private static final boolean isTrace = log.isTraceEnabled();
+ private static final boolean isTrace = ClientSessionFactoryImpl.log.isTraceEnabled();
- private static final boolean isDebug = log.isDebugEnabled();
+ private static final boolean isDebug = ClientSessionFactoryImpl.log.isDebugEnabled();
// Attributes
// -----------------------------------------------------------------------------------
@@ -97,9 +97,9 @@
private TransportConfiguration backupConfig;
private ConnectorFactory connectorFactory;
-
- private transient boolean finalizeCheck = true;
+ private transient boolean finalizeCheck = true;
+
private final long callTimeout;
private final long clientFailureCheckPeriod;
@@ -209,13 +209,13 @@
this.interceptors = interceptors;
}
-
+
public void disableFinalizeCheck()
{
finalizeCheck = false;
}
- public void connect(int initialConnectAttempts, boolean failoverOnInitialConnection) throws HornetQException
+ public void connect(final int initialConnectAttempts, final boolean failoverOnInitialConnection) throws HornetQException
{
// Get the connection
getConnectionWithRetry(initialConnectAttempts);
@@ -237,25 +237,25 @@
return connectorConfig;
}
- public void setBackupConnector(TransportConfiguration live, TransportConfiguration backUp)
+ public void setBackupConnector(final TransportConfiguration live, final TransportConfiguration backUp)
{
if (live.equals(connectorConfig) && backUp != null && !backUp.equals(connectorConfig))
{
- if (isDebug)
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("Setting up backup config = " + backUp + " for live = " + live);
+ ClientSessionFactoryImpl.log.debug("Setting up backup config = " + backUp + " for live = " + live);
}
backupConfig = backUp;
}
else
{
- if (isDebug)
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("ClientSessionFactoryImpl received backup update for live/backup pair = " + live +
- " / " +
- backUp +
- " but it didn't belong to " +
- this.connectorConfig);
+ ClientSessionFactoryImpl.log.debug("ClientSessionFactoryImpl received backup update for live/backup pair = " + live +
+ " / " +
+ backUp +
+ " but it didn't belong to " +
+ connectorConfig);
}
}
}
@@ -373,9 +373,9 @@
public void connectionDestroyed(final Object connectionID)
{
// It has to use the same executor as the disconnect message is being sent through
-
+
final HornetQException ex = new HornetQException(HornetQException.NOT_CONNECTED, "Channel disconnected");
-
+
closeExecutor.execute(new Runnable()
{
public void run()
@@ -393,7 +393,7 @@
// Must be synchronized to prevent it happening concurrently with failover which can lead to
// inconsistencies
- public void removeSession(final ClientSessionInternal session, boolean failingOver)
+ public void removeSession(final ClientSessionInternal session, final boolean failingOver)
{
synchronized (sessions)
{
@@ -468,7 +468,7 @@
}
catch (HornetQException e)
{
- log.warn("Unable to close session", e);
+ ClientSessionFactoryImpl.log.warn("Unable to close session", e);
}
}
@@ -506,7 +506,7 @@
}
catch (Exception e)
{
- log.warn("Unable to close session", e);
+ ClientSessionFactoryImpl.log.warn("Unable to close session", e);
}
}
@@ -569,9 +569,9 @@
return;
}
- if (isTrace)
+ if (ClientSessionFactoryImpl.isTrace)
{
- log.trace("Client Connection failed, calling failure listeners and trying to reconnect, reconnectAttempts=" + reconnectAttempts);
+ ClientSessionFactoryImpl.log.trace("Client Connection failed, calling failure listeners and trying to reconnect, reconnectAttempts=" + reconnectAttempts);
}
// We call before reconnection occurs to give the user a chance to do cleanup, like cancel messages
@@ -705,7 +705,7 @@
}
catch (Exception e)
{
- log.error("Failed to cleanup session");
+ ClientSessionFactoryImpl.log.error("Failed to cleanup session");
}
}
}
@@ -883,10 +883,12 @@
}
// Should never get here
- throw new IllegalStateException("Oh my God it's full of stars!");
+ throw new IllegalStateException("Internal Error! ClientSessionFactoryImpl::createSessionInternal " +
+ "just reached a condition that was not supposed to happen. " +
+ "Please inform this condition to the HornetQ team");
}
- private void callFailureListeners(final HornetQException me, final boolean afterReconnect, boolean failedOver)
+ private void callFailureListeners(final HornetQException me, final boolean afterReconnect, final boolean failedOver)
{
final List<SessionFailureListener> listenersClone = new ArrayList<SessionFailureListener>(listeners);
@@ -908,7 +910,7 @@
// Failure of one listener to execute shouldn't prevent others
// from
// executing
- log.error("Failed to execute failure listener", t);
+ ClientSessionFactoryImpl.log.error("Failed to execute failure listener", t);
}
}
}
@@ -922,7 +924,7 @@
if (connection == null)
{
- log.warn("Failed to connect to server.");
+ ClientSessionFactoryImpl.log.warn("Failed to connect to server.");
return;
}
@@ -957,9 +959,13 @@
private void getConnectionWithRetry(final int reconnectAttempts)
{
- if (log.isTraceEnabled())
+ if (ClientSessionFactoryImpl.log.isTraceEnabled())
{
- log.trace("getConnectionWithRetry::" + reconnectAttempts + " with retryInterval = " + retryInterval + " multiplier = " + retryIntervalMultiplier, new Exception ("trace"));
+ ClientSessionFactoryImpl.log.trace("getConnectionWithRetry::" + reconnectAttempts +
+ " with retryInterval = " +
+ retryInterval +
+ " multiplier = " +
+ retryIntervalMultiplier, new Exception("trace"));
}
long interval = retryInterval;
@@ -970,9 +976,9 @@
{
while (!exitLoop)
{
- if (isDebug)
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("Trying reconnection attempt " + count + "/" + reconnectAttempts);
+ ClientSessionFactoryImpl.log.debug("Trying reconnection attempt " + count + "/" + reconnectAttempts);
}
getConnection();
@@ -989,24 +995,24 @@
{
if (reconnectAttempts != 1)
{
- log.warn("Tried " + reconnectAttempts + " times to connect. Now giving up on reconnecting it.");
+ ClientSessionFactoryImpl.log.warn("Tried " + reconnectAttempts +
+ " times to connect. Now giving up on reconnecting it.");
}
- else
- if (reconnectAttempts == 1)
+ else if (reconnectAttempts == 1)
{
- log.debug("Trying to connect towards " + this);
+ ClientSessionFactoryImpl.log.debug("Trying to connect towards " + this);
}
return;
}
- if (isTrace)
+ if (ClientSessionFactoryImpl.isTrace)
{
- log.trace("Waiting " + interval +
- " milliseconds before next retry. RetryInterval=" +
- retryInterval +
- " and multiplier = " +
- retryIntervalMultiplier);
+ ClientSessionFactoryImpl.log.trace("Waiting " + interval +
+ " milliseconds before next retry. RetryInterval=" +
+ retryInterval +
+ " and multiplier = " +
+ retryIntervalMultiplier);
}
try
@@ -1029,7 +1035,7 @@
}
else
{
- log.debug("Could not connect to any server. Didn't have reconnection configured on the ClientSessionFactory");
+ ClientSessionFactoryImpl.log.debug("Could not connect to any server. Didn't have reconnection configured on the ClientSessionFactory");
return;
}
}
@@ -1103,31 +1109,31 @@
threadPool,
scheduledThreadPool);
- if (log.isDebugEnabled())
+ if (ClientSessionFactoryImpl.log.isDebugEnabled())
{
- log.debug("Trying to connect with connector = " + connectorFactory +
- ", parameters = " +
- connectorConfig.getParams() + " connector = " + connector);
+ ClientSessionFactoryImpl.log.debug("Trying to connect with connector = " + connectorFactory +
+ ", parameters = " +
+ connectorConfig.getParams() +
+ " connector = " +
+ connector);
}
-
-
if (connector != null)
{
connector.start();
- if (isDebug)
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("Trying to connect at the main server using connector :" + connectorConfig);
+ ClientSessionFactoryImpl.log.debug("Trying to connect at the main server using connector :" + connectorConfig);
}
tc = connector.createConnection();
if (tc == null)
{
- if (isDebug)
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("Main server is not up. Hopefully there's a backup configured now!");
+ ClientSessionFactoryImpl.log.debug("Main server is not up. Hopefully there's a backup configured now!");
}
try
@@ -1146,9 +1152,9 @@
{
if (backupConfig != null)
{
- if (isDebug)
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("Trying backup config = " + backupConfig);
+ ClientSessionFactoryImpl.log.debug("Trying backup config = " + backupConfig);
}
ConnectorFactory backupConnectorFactory = instantiateConnectorFactory(backupConfig.getFactoryClassName());
connector = backupConnectorFactory.createConnector(backupConfig.getParams(),
@@ -1160,16 +1166,16 @@
if (connector != null)
{
connector.start();
-
+
tc = connector.createConnection();
-
+
if (tc == null)
{
- if (isDebug)
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("Backup is not active yet");
+ ClientSessionFactoryImpl.log.debug("Backup is not active yet");
}
-
+
try
{
connector.close();
@@ -1177,31 +1183,31 @@
catch (Throwable t)
{
}
-
+
connector = null;
}
else
{
/*looks like the backup is now live, lets use that*/
-
- if (isDebug)
+
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("Connected to the backup at " + backupConfig);
+ ClientSessionFactoryImpl.log.debug("Connected to the backup at " + backupConfig);
}
-
+
connectorConfig = backupConfig;
-
+
backupConfig = null;
-
+
connectorFactory = backupConnectorFactory;
}
}
}
else
{
- if (isTrace)
+ if (ClientSessionFactoryImpl.isTrace)
{
- log.trace("No Backup configured!", new Exception("trace"));
+ ClientSessionFactoryImpl.log.trace("No Backup configured!", new Exception("trace"));
}
}
}
@@ -1210,8 +1216,8 @@
{
// Sanity catch for badly behaved remoting plugins
- log.warn("connector.create or connectorFactory.createConnector should never throw an exception, implementation is badly behaved, but we'll deal with it anyway.",
- e);
+ ClientSessionFactoryImpl.log.warn("connector.create or connectorFactory.createConnector should never throw an exception, implementation is badly behaved, but we'll deal with it anyway.",
+ e);
if (tc != null)
{
@@ -1242,9 +1248,9 @@
if (tc == null)
{
- if (isTrace)
+ if (ClientSessionFactoryImpl.isTrace)
{
- log.trace("returning connection = " + connection + " as tc == null");
+ ClientSessionFactoryImpl.log.trace("returning connection = " + connection + " as tc == null");
}
return connection;
}
@@ -1280,40 +1286,43 @@
if (serverLocator.getTopology() != null)
{
- if (isTrace)
+ if (ClientSessionFactoryImpl.isTrace)
{
- log.trace(this + "::Subscribing Topology");
+ ClientSessionFactoryImpl.log.trace(this + "::Subscribing Topology");
}
channel0.send(new SubscribeClusterTopologyUpdatesMessage(serverLocator.isClusterConnection()));
if (serverLocator.isClusterConnection())
{
TransportConfiguration config = serverLocator.getClusterTransportConfiguration();
- if (isDebug)
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("Announcing node " + serverLocator.getNodeID() + ", isBackup=" + serverLocator.isBackup());
+ ClientSessionFactoryImpl.log.debug("Announcing node " + serverLocator.getNodeID() +
+ ", isBackup=" +
+ serverLocator.isBackup());
}
channel0.send(new NodeAnnounceMessage(serverLocator.getNodeID(), serverLocator.isBackup(), config));
}
}
}
-
- if (log.isTraceEnabled())
+
+ if (ClientSessionFactoryImpl.log.isTraceEnabled())
{
- log.trace("returning " + connection);
+ ClientSessionFactoryImpl.log.trace("returning " + connection);
}
return connection;
}
+ @Override
public void finalize() throws Throwable
{
if (!closed && finalizeCheck)
{
- log.warn("I'm closing a core ClientSessionFactory you left open. Please make sure you close all ClientSessionFactories explicitly " + "before letting them go out of scope! " +
- System.identityHashCode(this));
+ ClientSessionFactoryImpl.log.warn("I'm closing a core ClientSessionFactory you left open. Please make sure you close all ClientSessionFactories explicitly " + "before letting them go out of scope! " +
+ System.identityHashCode(this));
- log.warn("The ClientSessionFactory you didn't close was created here:", e);
+ ClientSessionFactoryImpl.log.warn("The ClientSessionFactory you didn't close was created here:", e);
close();
}
@@ -1348,7 +1357,7 @@
if (connection != null)
{
Channel channel1 = connection.getChannel(1, -1);
-
+
if (channel1 != null)
{
channel1.getLock().lock();
@@ -1361,7 +1370,7 @@
if (connection != null)
{
Channel channel1 = connection.getChannel(1, -1);
-
+
if (channel1 != null)
{
channel1.getLock().unlock();
@@ -1417,10 +1426,15 @@
final DisconnectMessage msg = (DisconnectMessage)packet;
SimpleString nodeID = msg.getNodeID();
-
- if (log.isTraceEnabled())
+
+ if (ClientSessionFactoryImpl.log.isTraceEnabled())
{
- log.trace("Disconnect being called on client:" + msg + " server locator = " + serverLocator + " notifying node " + nodeID + " as down", new Exception ("trace"));
+ ClientSessionFactoryImpl.log.trace("Disconnect being called on client:" + msg +
+ " server locator = " +
+ serverLocator +
+ " notifying node " +
+ nodeID +
+ " as down", new Exception("trace"));
}
if (nodeID != null)
@@ -1446,21 +1460,23 @@
if (topMessage.isExit())
{
- if (isDebug)
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("Notifying " + topMessage.getNodeID() + " going down");
+ ClientSessionFactoryImpl.log.debug("Notifying " + topMessage.getNodeID() + " going down");
}
serverLocator.notifyNodeDown(topMessage.getNodeID());
}
else
{
- if (isDebug)
+ if (ClientSessionFactoryImpl.isDebug)
{
- log.debug("Node " + topMessage.getNodeID() +
- " going up, connector = " +
- topMessage.getPair() +
- ", isLast=" +
- topMessage.isLast() + " csf created at\nserverLocator=" + serverLocator, ClientSessionFactoryImpl.this.e);
+ ClientSessionFactoryImpl.log.debug("Node " + topMessage.getNodeID() +
+ " going up, connector = " +
+ topMessage.getPair() +
+ ", isLast=" +
+ topMessage.isLast() +
+ " csf created at\nserverLocator=" +
+ serverLocator, e);
}
serverLocator.notifyNodeUp(topMessage.getNodeID(), topMessage.getPair(), topMessage.isLast());
}
@@ -1490,7 +1506,7 @@
this.connectionID = connectionID;
}
- public void connectionFailed(final HornetQException me, boolean failedOver)
+ public void connectionFailed(final HornetQException me, final boolean failedOver)
{
handleConnectionFailure(connectionID, me);
}
@@ -1590,9 +1606,9 @@
/* (non-Javadoc)
* @see org.hornetq.core.client.impl.ClientSessionFactoryInternal#setReconnectAttempts(int)
*/
- public void setReconnectAttempts(int attempts)
+ public void setReconnectAttempts(final int attempts)
{
- this.reconnectAttempts = attempts;
+ reconnectAttempts = attempts;
}
}
13 years, 6 months
JBoss hornetq SVN: r11221 - branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2011-08-24 19:51:12 -0400 (Wed, 24 Aug 2011)
New Revision: 11221
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java
Log:
just changing a message
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java 2011-08-24 23:02:39 UTC (rev 11220)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java 2011-08-24 23:51:12 UTC (rev 11221)
@@ -233,7 +233,7 @@
{
// The cluster may get in loop without this..
// Case one node is stll sending nodeDown while another member is sending nodeUp
- log.warn("The topology controller identified a blast of nodeUp and down and it is ignoring a nodeUP",
+ log.warn("The topology controller identified a blast events and it's interrupting the flow of the loop",
new Exception("this exception is just to trace location"));
return false;
}
13 years, 6 months
JBoss hornetq SVN: r11220 - in branches/Branch_2_2_EAP: src/main/org/hornetq/core/server/cluster/impl and 2 other directories.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2011-08-24 19:02:39 -0400 (Wed, 24 Aug 2011)
New Revision: 11220
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/MessageRedistributionTest.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java
Log:
fixing tests
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java 2011-08-24 02:16:47 UTC (rev 11219)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java 2011-08-24 23:02:39 UTC (rev 11220)
@@ -1415,12 +1415,19 @@
if (type == PacketImpl.DISCONNECT)
{
final DisconnectMessage msg = (DisconnectMessage)packet;
+
+ SimpleString nodeID = msg.getNodeID();
if (log.isTraceEnabled())
{
- log.trace("Disconnect being called on client:" + msg + " server locator = " + serverLocator, new Exception ("trace"));
+ log.trace("Disconnect being called on client:" + msg + " server locator = " + serverLocator + " notifying node " + nodeID + " as down", new Exception ("trace"));
}
+ if (nodeID != null)
+ {
+ serverLocator.notifyNodeDown(msg.getNodeID().toString());
+ }
+
closeExecutor.execute(new Runnable()
{
// Must be executed on new thread since cannot block the netty thread for a long time and fail can
@@ -1430,15 +1437,6 @@
conn.fail(new HornetQException(HornetQException.DISCONNECTED,
"The connection was disconnected because of server shutdown"));
- SimpleString nodeID = msg.getNodeID();
- if (log.isTraceEnabled())
- {
- log.trace("notifyDown nodeID=" + msg.getNodeID() + " on serverLocator=" + serverLocator + " csf created at ", ClientSessionFactoryImpl.this.e);
- }
- if (nodeID != null)
- {
- serverLocator.notifyNodeDown(msg.getNodeID().toString());
- }
}
});
}
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java 2011-08-24 02:16:47 UTC (rev 11219)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java 2011-08-24 23:02:39 UTC (rev 11220)
@@ -23,6 +23,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
+import org.hornetq.api.core.Pair;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClusterTopologyListener;
import org.hornetq.core.logging.Logger;
@@ -35,15 +36,15 @@
{
private static final int BACKOF_TIMEOUT = 50;
-
+
private static final long serialVersionUID = -9037171688692471371L;
private final Set<ClusterTopologyListener> topologyListeners = new HashSet<ClusterTopologyListener>();
private static final Logger log = Logger.getLogger(Topology.class);
-
- private transient HashMap<String, Long> mapBackof = new HashMap<String, Long>();
+ private transient HashMap<String, Pair<Long, Integer>> mapBackof = new HashMap<String, Pair<Long, Integer>>();
+
private Executor executor = null;
/** Used to debug operations.
@@ -55,7 +56,6 @@
* */
private volatile Object owner;
-
/**
* topology describes the other cluster nodes that this server knows about:
*
@@ -80,7 +80,7 @@
{
if (log.isDebugEnabled())
{
- log.debug(this + "::PPP Adding topology listener " + listener, new Exception("Trace"));
+ log.debug(this + "::Adding topology listener " + listener, new Exception("Trace"));
}
synchronized (topologyListeners)
{
@@ -106,16 +106,6 @@
synchronized (this)
{
- Long lastTime = mapBackof.get(nodeId);
-
- if (lastTime != null && System.currentTimeMillis() - lastTime.longValue() < BACKOF_TIMEOUT)
- {
- // The cluster may get in loop without this..
- // Case one node is stll sending nodeDown while another member is sending nodeUp
- log.warn("Node was considered down too fast, ignoring addMember on Topology", new Exception("trace"));
- return false;
- }
-
TopologyMember currentMember = topology.get(nodeId);
if (Topology.log.isDebugEnabled())
@@ -125,6 +115,11 @@
if (currentMember == null)
{
+ if (!testBackof(nodeId))
+ {
+ return false;
+ }
+
replaced = true;
if (Topology.log.isDebugEnabled())
{
@@ -144,11 +139,21 @@
{
if (hasChanged(currentMember.getConnector().a, member.getConnector().a) && member.getConnector().a != null)
{
+ if (!testBackof(nodeId))
+ {
+ return false;
+ }
+
currentMember.getConnector().a = member.getConnector().a;
replaced = true;
}
if (hasChanged(currentMember.getConnector().b, member.getConnector().b) && member.getConnector().b != null)
{
+ if (!testBackof(nodeId))
+ {
+ return false;
+ }
+
currentMember.getConnector().b = member.getConnector().b;
replaced = true;
}
@@ -180,9 +185,8 @@
if (replaced)
{
-
final ArrayList<ClusterTopologyListener> copy = copyListeners();
-
+
execute(new Runnable()
{
public void run()
@@ -211,6 +215,38 @@
}
/**
+ * @param nodeId
+ * @param backOfData
+ */
+ private boolean testBackof(final String nodeId)
+ {
+ Pair<Long, Integer> backOfData = mapBackof.get(nodeId);
+
+ if (backOfData != null)
+ {
+ backOfData.b += 1;
+
+ long timeDiff = System.currentTimeMillis() - backOfData.a;
+
+ // To prevent a loop where nodes are being considered down and up
+ if (backOfData.b > 5 && timeDiff < BACKOF_TIMEOUT)
+ {
+ // The cluster may get in loop without this..
+ // Case one node is stll sending nodeDown while another member is sending nodeUp
+ log.warn("The topology controller identified a blast of nodeUp and down and it is ignoring a nodeUP",
+ new Exception("this exception is just to trace location"));
+ return false;
+ }
+ else if (timeDiff >= BACKOF_TIMEOUT)
+ {
+ mapBackof.remove(nodeId);
+ }
+ }
+
+ return true;
+ }
+
+ /**
* @return
*/
private ArrayList<ClusterTopologyListener> copyListeners()
@@ -229,7 +265,21 @@
synchronized (this)
{
- mapBackof.put(nodeId, new Long(System.currentTimeMillis()));
+ Pair<Long, Integer> value = mapBackof.get(nodeId);
+
+ if (value == null)
+ {
+ value = new Pair<Long, Integer>(0l, 0);
+ mapBackof.put(nodeId, value);
+ }
+
+ value.a = System.currentTimeMillis();
+
+ if (System.currentTimeMillis() - value.a > BACKOF_TIMEOUT)
+ {
+ value.b = 0;
+ }
+
member = topology.remove(nodeId);
}
@@ -273,7 +323,7 @@
}
return member != null;
}
-
+
protected void execute(final Runnable runnable)
{
if (executor != null)
@@ -291,43 +341,69 @@
* @param nodeID
* @param member
*/
- public void sendMemberToListeners(String nodeID, TopologyMember member)
+ public void sendMemberToListeners(final String nodeID, final TopologyMember member)
{
// To make sure it was updated
addMember(nodeID, member, false);
- ArrayList<ClusterTopologyListener> copy = copyListeners();
+ final ArrayList<ClusterTopologyListener> copy = copyListeners();
- // Now force sending it
- for (ClusterTopologyListener listener : copy)
+ execute(new Runnable()
{
- if (log.isDebugEnabled())
+ public void run()
{
- log.debug("Informing client listener " + listener +
- " about itself node " +
- nodeID +
- " with connector=" +
- member.getConnector());
+ // Now force sending it
+ for (ClusterTopologyListener listener : copy)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Informing client listener " + listener +
+ " about itself node " +
+ nodeID +
+ " with connector=" +
+ member.getConnector());
+ }
+ listener.nodeUP(nodeID, member.getConnector(), false);
+ }
}
- listener.nodeUP(nodeID, member.getConnector(), false);
- }
+ });
}
- public void sendTopology(final ClusterTopologyListener listener)
+ public synchronized void sendTopology(final ClusterTopologyListener listener)
{
- int count = 0;
+ if (log.isDebugEnabled())
+ {
+ log.debug(this + " is sending topology to " + listener);
+ }
- Map<String, TopologyMember> copy;
+ final Map<String, TopologyMember> copy;
synchronized (this)
{
copy = new HashMap<String, TopologyMember>(topology);
}
- for (Map.Entry<String, TopologyMember> entry : copy.entrySet())
+ execute(new Runnable()
{
- listener.nodeUP(entry.getKey(), entry.getValue().getConnector(), ++count == copy.size());
- }
+ public void run()
+ {
+ int count = 0;
+
+ for (Map.Entry<String, TopologyMember> entry : copy.entrySet())
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug(Topology.this + " sending " +
+ entry.getKey() +
+ " / " +
+ entry.getValue().getConnector() +
+ " to " +
+ listener);
+ }
+ listener.nodeUP(entry.getKey(), entry.getValue().getConnector(), ++count == copy.size());
+ }
+ }
+ });
}
public TopologyMember getMember(final String nodeID)
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2011-08-24 02:16:47 UTC (rev 11219)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2011-08-24 23:02:39 UTC (rev 11220)
@@ -380,15 +380,8 @@
{
topology.addClusterTopologyListener(listener);
- // We now need to send the current topology to the client
- executor.execute(new Runnable()
- {
- public void run()
- {
- topology.sendTopology(listener);
-
- }
- });
+ // no need to use an executor here since the Topology is already using one
+ topology.sendTopology(listener);
}
public void removeClusterTopologyListener(final ClusterTopologyListener listener, final boolean clusterConnection)
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/MessageRedistributionTest.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/MessageRedistributionTest.java 2011-08-24 02:16:47 UTC (rev 11219)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/MessageRedistributionTest.java 2011-08-24 23:02:39 UTC (rev 11220)
@@ -169,7 +169,7 @@
removeConsumer(1);
// Need to wait some time as we need to handle all redistributions before we stop the servers
- Thread.sleep(5000);
+ Thread.sleep(1000);
for (int i = 0; i <= 2; i++)
{
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java 2011-08-24 02:16:47 UTC (rev 11219)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java 2011-08-24 23:02:39 UTC (rev 11220)
@@ -173,7 +173,8 @@
ClientSessionFactoryInternal sf;
CountDownLatch countDownLatch = new CountDownLatch(topologyMembers);
- locator.addClusterTopologyListener(new LatchClusterTopologyListener(countDownLatch));
+ LatchClusterTopologyListener topListener = new LatchClusterTopologyListener(countDownLatch);
+ locator.addClusterTopologyListener(topListener);
sf = (ClientSessionFactoryInternal)locator.createSessionFactory();
@@ -182,6 +183,7 @@
{
System.out.println(((ServerLocatorInternal)locator).getTopology().describe());
}
+ locator.removeClusterTopologyListener(topListener);
assertTrue(ok);
return sf;
}
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java 2011-08-24 02:16:47 UTC (rev 11219)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java 2011-08-24 23:02:39 UTC (rev 11220)
@@ -20,10 +20,12 @@
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
-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.Topology;
import org.hornetq.core.config.ClusterConnectionConfiguration;
import org.hornetq.core.config.Configuration;
+import org.hornetq.core.logging.Logger;
import org.hornetq.core.server.NodeManager;
import org.hornetq.core.server.impl.InVMNodeManager;
import org.hornetq.tests.integration.cluster.util.SameProcessHornetQServer;
@@ -36,7 +38,19 @@
protected Map<Integer, TestableServer> servers = new HashMap<Integer, TestableServer>();
private NodeManager nodeManager;
+
+ Logger log = Logger.getLogger(SingleLiveMultipleBackupsFailoverTest.class);
+ public void _testLoop() throws Exception
+ {
+ for (int i = 0 ; i < 100; i++)
+ {
+ log.info("#test " + i);
+ testMultipleFailovers();
+ tearDown();
+ setUp();
+ }
+ }
public void testMultipleFailovers() throws Exception
{
nodeManager = new InVMNodeManager();
@@ -56,7 +70,12 @@
servers.get(4).start();
servers.get(5).start();
- ServerLocator locator = getServerLocator(0);
+ ServerLocatorImpl locator = (ServerLocatorImpl)getServerLocator(0);
+
+ Topology topology = locator.getTopology();
+
+ // for logging and debugging
+ topology.setOwner("testMultipleFailovers");
locator.setBlockOnNonDurableSend(true);
locator.setBlockOnDurableSend(true);
@@ -65,36 +84,32 @@
ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
int backupNode;
ClientSession session = sendAndConsume(sf, true);
- System.out.println("failing node 0");
- Thread.sleep(500);
+
+ log.info("failing node 0");
servers.get(0).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
- System.out.println("failing node " + backupNode);
- Thread.sleep(500);
+ log.info("failing node " + backupNode);
servers.get(backupNode).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
- System.out.println("failing node " + backupNode);
- Thread.sleep(1000);
+ log.info("failing node " + backupNode);
servers.get(backupNode).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
- System.out.println("failing node " + backupNode);
- Thread.sleep(500);
+ log.info("failing node " + backupNode);
servers.get(backupNode).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
- System.out.println("failing node " + backupNode);
- Thread.sleep(500);
+ log.info("failing node " + backupNode);
servers.get(backupNode).crash(session);
session.close();
13 years, 6 months
JBoss hornetq SVN: r11219 - in branches/Branch_2_2_EAP: src/main/org/hornetq/core/protocol/core/impl and 10 other directories.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2011-08-23 22:16:47 -0400 (Tue, 23 Aug 2011)
New Revision: 11219
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/core/impl/CoreProtocolManager.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompProtocolManager.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/HornetQServer.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/ClusterManager.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
branches/Branch_2_2_EAP/src/main/org/hornetq/spi/core/protocol/ConnectionEntry.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterWithBackupTest.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/util/SameProcessHornetQServer.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/util/ServiceTestBase.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/util/UnitTestCase.java
Log:
Improvements on test suite (fixing a few intermittent issues)
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/Topology.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -34,7 +34,7 @@
public class Topology implements Serializable
{
- private static final int BACKOF_TIMEOUT = 500;
+ private static final int BACKOF_TIMEOUT = 50;
private static final long serialVersionUID = -9037171688692471371L;
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/core/impl/CoreProtocolManager.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/core/impl/CoreProtocolManager.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/core/impl/CoreProtocolManager.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -37,7 +37,6 @@
import org.hornetq.core.protocol.core.impl.wireformat.SubscribeClusterTopologyUpdatesMessage;
import org.hornetq.core.remoting.CloseListener;
import org.hornetq.core.server.HornetQServer;
-import org.hornetq.core.server.cluster.ClusterManager;
import org.hornetq.spi.core.protocol.ConnectionEntry;
import org.hornetq.spi.core.protocol.ProtocolManager;
import org.hornetq.spi.core.protocol.RemotingConnection;
@@ -53,9 +52,9 @@
public class CoreProtocolManager implements ProtocolManager
{
private static final Logger log = Logger.getLogger(CoreProtocolManager.class);
-
+
private static final boolean isTrace = log.isTraceEnabled();
-
+
private final HornetQServer server;
private final List<Interceptor> interceptors;
@@ -70,13 +69,14 @@
public ConnectionEntry createConnectionEntry(final Connection connection)
{
final Configuration config = server.getConfiguration();
+
+ Executor connectionExecutor = server.getExecutorFactory().getExecutor();
final CoreRemotingConnection rc = new RemotingConnectionImpl(connection,
interceptors,
- config.isAsyncConnectionExecutionEnabled() ? server.getExecutorFactory()
- .getExecutor()
+ config.isAsyncConnectionExecutionEnabled() ? connectionExecutor
: null,
- server.getNodeID());
+ server.getNodeID());
Channel channel1 = rc.getChannel(1, -1);
@@ -91,7 +91,7 @@
ttl = config.getConnectionTTLOverride();
}
- final ConnectionEntry entry = new ConnectionEntry(rc, System.currentTimeMillis(), ttl);
+ final ConnectionEntry entry = new ConnectionEntry(rc, connectionExecutor, System.currentTimeMillis(), ttl);
final Channel channel0 = rc.getChannel(0, -1);
@@ -115,11 +115,9 @@
else if (packet.getType() == PacketImpl.SUBSCRIBE_TOPOLOGY)
{
SubscribeClusterTopologyUpdatesMessage msg = (SubscribeClusterTopologyUpdatesMessage)packet;
-
+
final ClusterTopologyListener listener = new ClusterTopologyListener()
{
- Executor executor = server.getExecutorFactory().getExecutor();
-
public void nodeUP(final String nodeID,
final Pair<TransportConfiguration, TransportConfiguration> connectorPair,
final boolean last)
@@ -127,21 +125,21 @@
// Using an executor as most of the notifications on the Topology
// may come from a channel itself
// What could cause deadlocks
- executor.execute(new Runnable()
+ entry.connectionExecutor.execute(new Runnable()
{
public void run()
{
channel0.send(new ClusterTopologyChangeMessage(nodeID, connectorPair, last));
}
});
- }
+ }
public void nodeDown(final String nodeID)
{
// Using an executor as most of the notifications on the Topology
// may come from a channel itself
// What could cause deadlocks
- executor.execute(new Runnable()
+ entry.connectionExecutor.execute(new Runnable()
{
public void run()
{
@@ -149,17 +147,17 @@
}
});
}
-
+
public String toString()
{
return "Remote Proxy on channel " + Integer.toHexString(System.identityHashCode(this));
}
};
-
+
final boolean isCC = msg.isClusterConnection();
-
+
server.getClusterManager().addClusterTopologyListener(listener, isCC);
-
+
rc.addCloseListener(new CloseListener()
{
public void connectionClosed()
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompProtocolManager.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompProtocolManager.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompProtocolManager.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -120,13 +120,13 @@
if (ttl != -1)
{
- return new ConnectionEntry(conn, System.currentTimeMillis(), ttl);
+ return new ConnectionEntry(conn, null, System.currentTimeMillis(), ttl);
}
else
{
// Default to 1 minute - which is same as core protocol
- return new ConnectionEntry(conn, System.currentTimeMillis(), 1 * 60 * 1000);
+ return new ConnectionEntry(conn, null, System.currentTimeMillis(), 1 * 60 * 1000);
}
}
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/HornetQServer.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/HornetQServer.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/HornetQServer.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -181,6 +181,8 @@
void destroyBridge(String name) throws Exception;
ServerSession getSessionByID(String sessionID);
+
+ void threadDump(String reason);
void stop(boolean failoverOnServerShutdown) throws Exception;
}
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/ClusterManager.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/ClusterManager.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/ClusterManager.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -53,6 +53,8 @@
void notifyNodeUp(String nodeID, Pair<TransportConfiguration, TransportConfiguration> connectorPair, boolean backup, boolean nodeAnnounce);
Topology getTopology();
+
+ void flushExecutor();
void announceBackup() throws Exception;
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -56,6 +56,7 @@
import org.hornetq.core.server.management.ManagementService;
import org.hornetq.utils.ConcurrentHashSet;
import org.hornetq.utils.ExecutorFactory;
+import org.hornetq.utils.Future;
import org.hornetq.utils.UUID;
/**
@@ -123,10 +124,10 @@
this.executorFactory = executorFactory;
- executor = executorFactory.getExecutor();
-
- topology.setExecutor(executorFactory.getExecutor());
+ executor = executorFactory.getExecutor();;
+ topology.setExecutor(executor);
+
this.server = server;
this.postOffice = postOffice;
@@ -340,6 +341,16 @@
}
}
+ public void flushExecutor()
+ {
+ Future future = new Future();
+ executor.execute(future);
+ if (!future.await(10000))
+ {
+ server.threadDump("Couldn't flush ClusterManager executor (" + this + ") in 10 seconds, verify your thread pool size");
+ }
+ }
+
public boolean isStarted()
{
return started;
@@ -486,7 +497,7 @@
{
this.clusterLocators.add(serverLocator);
}
-
+
public void removeClusterLocator(final ServerLocatorInternal serverLocator)
{
this.clusterLocators.remove(serverLocator);
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -625,7 +625,7 @@
activation = new SharedNothingBackupActivation();
}
- backupActivationThread = new Thread(activation);
+ backupActivationThread = new Thread(activation, "Activation for server " + this);
backupActivationThread.start();
}
@@ -652,7 +652,41 @@
stopped = true;
stop(configuration.isFailoverOnServerShutdown());
}
+
+ public void threadDump(final String reason)
+ {
+ StringWriter str = new StringWriter();
+ PrintWriter out = new PrintWriter(str);
+ Map<Thread, StackTraceElement[]> stackTrace = Thread.getAllStackTraces();
+
+ out.println("Generating thread dump because - " + reason);
+ out.println("*******************************************************************************");
+
+ for (Map.Entry<Thread, StackTraceElement[]> el : stackTrace.entrySet())
+ {
+ out.println("===============================================================================");
+ out.println("Thread " + el.getKey() +
+ " name = " +
+ el.getKey().getName() +
+ " id = " +
+ el.getKey().getId() +
+ " group = " +
+ el.getKey().getThreadGroup());
+ out.println();
+ for (StackTraceElement traceEl : el.getValue())
+ {
+ out.println(traceEl);
+ }
+ }
+
+ out.println("===============================================================================");
+ out.println("End Thread dump");
+ out.println("*******************************************************************************");
+
+ log.warn(str.toString());
+ }
+
public void stop(boolean failoverOnServerShutdown) throws Exception
{
synchronized (this)
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/spi/core/protocol/ConnectionEntry.java
===================================================================
--- branches/Branch_2_2_EAP/src/main/org/hornetq/spi/core/protocol/ConnectionEntry.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/src/main/org/hornetq/spi/core/protocol/ConnectionEntry.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -13,7 +13,9 @@
package org.hornetq.spi.core.protocol;
+import java.util.concurrent.Executor;
+
/**
* A ConnectionEntry
*
@@ -28,13 +30,17 @@
public volatile long lastCheck;
public volatile long ttl;
+
+ public final Executor connectionExecutor;
- public ConnectionEntry(final RemotingConnection connection, final long lastCheck, final long ttl)
+ public ConnectionEntry(final RemotingConnection connection, final Executor connectionExecutor, final long lastCheck, final long ttl)
{
this.connection = connection;
this.lastCheck = lastCheck;
this.ttl = ttl;
+
+ this.connectionExecutor = connectionExecutor;
}
}
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -2041,23 +2041,6 @@
}
- protected void waitForServer(HornetQServer server) throws InterruptedException
- {
- long timetowait = System.currentTimeMillis() + 5000;
- while (!server.isStarted())
- {
- Thread.sleep(100);
- if (server.isStarted())
- {
- break;
- }
- else if (System.currentTimeMillis() > timetowait)
- {
- fail("server didnt start");
- }
- }
- }
-
protected void stopClusterConnections(final int... nodes) throws Exception
{
for (int node : nodes)
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterWithBackupTest.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterWithBackupTest.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterWithBackupTest.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -97,7 +97,7 @@
{
e.printStackTrace();
log.error(e.getMessage(), e);
- throw e;
+ throw e;
}
}
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -70,7 +70,10 @@
protected abstract boolean isNetty();
- protected int waitForNewLive(long seconds, boolean waitForNewBackup, Map<Integer, TestableServer> servers, int... nodes)
+ protected int waitForNewLive(long seconds,
+ boolean waitForNewBackup,
+ Map<Integer, TestableServer> servers,
+ int... nodes)
{
long time = System.currentTimeMillis();
long toWait = seconds * 1000;
@@ -84,12 +87,12 @@
{
newLive = node;
}
- else if(newLive != -1)
+ else if (newLive != -1)
{
- if(waitForNewBackup)
+ if (waitForNewBackup)
+ {
+ if (node != newLive && servers.get(node).isStarted())
{
- if(node != newLive && servers.get(node).isStarted())
- {
return newLive;
}
}
@@ -99,6 +102,7 @@
}
}
}
+
try
{
Thread.sleep(100);
@@ -146,7 +150,7 @@
for (int i = 0; i < numMessages; i++)
{
ClientMessage message2 = consumer.receive(10000);
-
+
assertNotNull(message2);
Assert.assertEquals("aardvarks", message2.getBodyBuffer().readString());
@@ -174,10 +178,10 @@
sf = (ClientSessionFactoryInternal)locator.createSessionFactory();
boolean ok = countDownLatch.await(5, TimeUnit.SECONDS);
- if (!ok)
+ if (!ok)
{
System.out.println(((ServerLocatorInternal)locator).getTopology().describe());
- }
+ }
assertTrue(ok);
return sf;
}
@@ -191,7 +195,7 @@
}
return new ServerLocatorImpl(true, configs);
}
-
+
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
@@ -213,9 +217,7 @@
this.latch = latch;
}
- public void nodeUP(String nodeID,
- Pair<TransportConfiguration, TransportConfiguration> connectorPair,
- boolean last)
+ public void nodeUP(String nodeID, Pair<TransportConfiguration, TransportConfiguration> connectorPair, boolean last)
{
if (connectorPair.a != null && !liveNode.contains(connectorPair.a.getName()))
{
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -46,8 +46,11 @@
createBackupConfig(0, 3, 0, 1, 2, 4, 5);
createBackupConfig(0, 4, 0, 1, 2, 3, 5);
createBackupConfig(0, 5, 0, 1, 2, 3, 4);
+
servers.get(0).start();
+ waitForServer(servers.get(0).getServer());
servers.get(1).start();
+ waitForServer(servers.get(1).getServer());
servers.get(2).start();
servers.get(3).start();
servers.get(4).start();
@@ -63,30 +66,35 @@
int backupNode;
ClientSession session = sendAndConsume(sf, true);
System.out.println("failing node 0");
+ Thread.sleep(500);
servers.get(0).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
System.out.println("failing node " + backupNode);
+ Thread.sleep(500);
servers.get(backupNode).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
System.out.println("failing node " + backupNode);
+ Thread.sleep(1000);
servers.get(backupNode).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
System.out.println("failing node " + backupNode);
+ Thread.sleep(500);
servers.get(backupNode).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
System.out.println("failing node " + backupNode);
+ Thread.sleep(500);
servers.get(backupNode).crash(session);
session.close();
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/util/SameProcessHornetQServer.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/util/SameProcessHornetQServer.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/util/SameProcessHornetQServer.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -112,6 +112,7 @@
}
ClusterManagerImpl clusterManager = (ClusterManagerImpl) server.getClusterManager();
+ clusterManager.flushExecutor();
clusterManager.clear();
server.stop(true);
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/util/ServiceTestBase.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/util/ServiceTestBase.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/util/ServiceTestBase.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -165,7 +165,37 @@
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
+
+ protected void waitForServer(HornetQServer server) throws InterruptedException
+ {
+ long timetowait = System.currentTimeMillis() + 5000;
+ while (!server.isStarted() && System.currentTimeMillis() < timetowait)
+ {
+ Thread.sleep(100);
+ }
+
+ if (!server.isStarted())
+ {
+ log.info(threadDump("Server didn't start"));
+ fail("server didnt start");
+ }
+
+ if (!server.getConfiguration().isBackup())
+ {
+ timetowait = System.currentTimeMillis() + 5000;
+ while (!server.isInitialised() && System.currentTimeMillis() < timetowait)
+ {
+ Thread.sleep(100);
+ }
+
+ if (!server.isInitialised())
+ {
+ fail("Server didn't initialize");
+ }
+ }
+ }
+
protected HornetQServer createServer(final boolean realFiles,
final Configuration configuration,
final int pageSize,
Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/util/UnitTestCase.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/util/UnitTestCase.java 2011-08-23 13:34:40 UTC (rev 11218)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/util/UnitTestCase.java 2011-08-24 02:16:47 UTC (rev 11219)
@@ -99,6 +99,8 @@
private static final Logger log = Logger.getLogger(UnitTestCase.class);
+ private static final Logger logInstance = Logger.getLogger(UnitTestCase.class);
+
public static final String INVM_ACCEPTOR_FACTORY = "org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory";
public static final String INVM_CONNECTOR_FACTORY = "org.hornetq.core.remoting.impl.invm.InVMConnectorFactory";
@@ -268,7 +270,7 @@
public static void forceGC()
{
- log.info("#test forceGC");
+ logInstance.info("#test forceGC");
WeakReference<Object> dumbReference = new WeakReference<Object>(new Object());
// A loop that will wait GC, using the minimal time as possible
while (dumbReference.get() != null)
@@ -282,7 +284,7 @@
{
}
}
- log.info("#test forceGC Done");
+ logInstance.info("#test forceGC Done");
}
public static void forceGC(Reference<?> ref, long timeout)
13 years, 6 months
JBoss hornetq SVN: r11218 - branches.
by do-not-reply@jboss.org
Author: igarashitm
Date: 2011-08-23 09:34:40 -0400 (Tue, 23 Aug 2011)
New Revision: 11218
Added:
branches/HORNETQ-316/
Log:
branch for HORNETQ-316
13 years, 6 months
JBoss hornetq SVN: r11217 - branches.
by do-not-reply@jboss.org
Author: igarashitm
Date: 2011-08-23 09:30:09 -0400 (Tue, 23 Aug 2011)
New Revision: 11217
Added:
branches/HORNETQ-316_old/
Removed:
branches/HORNETQ-316/
Log:
re-create a branch for HORNETQ-316 to catch up with current trunk
13 years, 6 months