Author: clebert.suconic(a)jboss.com
Date: 2011-07-27 03:28:44 -0400 (Wed, 27 Jul 2011)
New Revision: 11050
Modified:
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/client/impl/Topology.java
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
Log:
tweaks
Modified:
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/client/impl/Topology.java
===================================================================
---
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/client/impl/Topology.java 2011-07-27
06:22:54 UTC (rev 11049)
+++
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/client/impl/Topology.java 2011-07-27
07:28:44 UTC (rev 11050)
@@ -18,6 +18,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClusterTopologyListener;
@@ -60,46 +61,37 @@
* keys are node IDs
* values are a pair of live/backup transport configurations
*/
- private Map<String, TopologyMember> topology = new ConcurrentHashMap<String,
TopologyMember>();
+ private final ConcurrentMap<String, TopologyMember> topologyMap = new
ConcurrentHashMap<String, TopologyMember>();
private boolean debug = log.isDebugEnabled();
public synchronized boolean addMember(String nodeId, TopologyMember member)
{
boolean replaced = false;
- TopologyMember currentMember = topology.get(nodeId);
+ TopologyMember oldMember = topologyMap.put(nodeId, member);
if (debug)
{
- log.debug(this + "::adding = " + nodeId + ":" +
member.getConnector(), new Exception ("trace"));
+ log.debug(this + "::adding nodeId=" + nodeId + ", " +
member.getConnector(), new Exception ("trace"));
log.debug(describe("Before:"));
}
- if(currentMember == null)
+
+ if(oldMember == null)
{
- topology.put(nodeId, member);
replaced = true;
}
else
{
- if(hasChanged(currentMember.getConnector().a, member.getConnector().a)
&& member.getConnector().a != null)
+ if(hasChanged(oldMember.getConnector().a, member.getConnector().a) &&
member.getConnector().a != null)
{
- currentMember.getConnector().a = member.getConnector().a;
replaced = true;
}
- if(hasChanged(currentMember.getConnector().b, member.getConnector().b)
&& member.getConnector().b != null)
+ if(hasChanged(oldMember.getConnector().b, member.getConnector().b) &&
member.getConnector().b != null)
{
- currentMember.getConnector().b = member.getConnector().b;
+ oldMember.getConnector().b = member.getConnector().b;
replaced = true;
}
-
- if(member.getConnector().a == null)
- {
- member.getConnector().a = currentMember.getConnector().a;
- }
- if(member.getConnector().b == null)
- {
- member.getConnector().b = currentMember.getConnector().b;
- }
}
+
if(debug)
{
log.debug(this + "::Topology updated=" + replaced);
@@ -110,7 +102,7 @@
public synchronized boolean removeMember(String nodeId)
{
- TopologyMember member = topology.remove(nodeId);
+ TopologyMember member = topologyMap.remove(nodeId);
if (log.isDebugEnabled())
{
log.debug("XXX " + this + " removing nodeID=" + nodeId +
", result=" + member, new Exception ("trace"));
@@ -124,7 +116,7 @@
Map<String, TopologyMember> copy;
synchronized (this)
{
- copy = new HashMap<String, TopologyMember>(topology);
+ copy = new HashMap<String, TopologyMember>(topologyMap);
}
for (Map.Entry<String, TopologyMember> entry : copy.entrySet())
{
@@ -134,23 +126,23 @@
public TopologyMember getMember(String nodeID)
{
- return topology.get(nodeID);
+ return topologyMap.get(nodeID);
}
public boolean isEmpty()
{
- return topology.isEmpty();
+ return topologyMap.isEmpty();
}
public Collection<TopologyMember> getMembers()
{
- return topology.values();
+ return topologyMap.values();
}
public int nodes()
{
int count = 0;
- for (TopologyMember member : topology.values())
+ for (TopologyMember member : topologyMap.values())
{
if (member.getConnector().a != null)
{
@@ -172,7 +164,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>(topologyMap).entrySet())
{
desc += "\t" + entry.getKey() + " => " + entry.getValue()
+ "\n";
}
@@ -182,12 +174,13 @@
public void clear()
{
- topology.clear();
+ // TODO: place this back
+ //topologyMap.clear();
}
public int members()
{
- return topology.size();
+ return topologyMap.size();
}
private boolean hasChanged(TransportConfiguration currentConnector,
TransportConfiguration connector)
@@ -197,7 +190,7 @@
public TransportConfiguration getBackupForConnector(TransportConfiguration
connectorConfiguration)
{
- for (TopologyMember member : topology.values())
+ for (TopologyMember member : topologyMap.values())
{
if(member.getConnector().a != null &&
member.getConnector().a.equals(connectorConfiguration))
{
Modified:
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
===================================================================
---
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2011-07-27
06:22:54 UTC (rev 11049)
+++
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2011-07-27
07:28:44 UTC (rev 11050)
@@ -93,22 +93,22 @@
private volatile boolean started;
- private boolean backup;
+ private volatile boolean backup;
private final boolean clustered;
// the cluster connections which links this node to other cluster nodes
private final Map<String, ClusterConnection> clusterConnections = new
HashMap<String, ClusterConnection>();
- private Set<ClusterTopologyListener> topologyListeners = new
ConcurrentHashSet<ClusterTopologyListener>();
+ private final Set<ClusterTopologyListener> topologyListeners = new
ConcurrentHashSet<ClusterTopologyListener>();
- private Topology topology = new Topology(this);
+ private final Topology topology = new Topology(this);
private volatile ServerLocatorInternal backupServerLocator;
private final List<ServerLocatorInternal> clusterLocators = new
ArrayList<ServerLocatorInternal>();
- private Executor executor;
+ private final Executor executor;
public ClusterManagerImpl(final ExecutorFactory executorFactory,
final HornetQServer server,
@@ -229,10 +229,6 @@
managementService.unregisterCluster(clusterConnection.getName().toString());
}
- topologyListeners.clear();
- clusterConnections.clear();
- topology.clear();
-
}
for (Bridge bridge : bridges.values())
@@ -255,6 +251,11 @@
}
clusterLocators.clear();
started = false;
+
+ topologyListeners.clear();
+ clusterConnections.clear();
+ topology.clear();
+
}
public void notifyNodeDown(String nodeID)