You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gd...@apache.org on 2004/05/27 16:13:40 UTC
cvs commit: incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging NodeTopology.java
gdamour 2004/05/27 07:13:40
Modified: sandbox/messaging/src/java/org/apache/geronimo/messaging
NodeTopology.java
Log:
Adds a method returning all the registered Nodes of the topology.
Revision Changes Path
1.2 +29 -6 incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/NodeTopology.java
Index: NodeTopology.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/NodeTopology.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NodeTopology.java 11 May 2004 12:06:41 -0000 1.1
+++ NodeTopology.java 27 May 2004 14:13:40 -0000 1.2
@@ -24,9 +24,11 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Abstracts the topology of a set of nodes.
@@ -52,17 +54,17 @@
/**
* Used to perform atomic operations on nodeToID and idToNode.
*/
- private final Object nodeAndIdLock = new Object();
+ private Object nodeAndIdLock = new Object();
/**
* NodeInfo to Integer (node identifier) mapping.
*/
- private final Map nodeToID;
+ private Map nodeToID;
/**
* Integer (node identifier) to NodeInfo mapping.
*/
- private final Map idToNode;
+ private Map idToNode;
/**
* TwoNodeInfo to NodeInfo[] mapping. It is a cache of the shortest path
@@ -320,7 +322,10 @@
* @return NodeInfo having this identifier.
*/
public NodeInfo getNodeById(int anId) {
- NodeInfo nodeInfo = (NodeInfo) idToNode.get(new Integer(anId));
+ NodeInfo nodeInfo;
+ synchronized(nodeAndIdLock) {
+ nodeInfo = (NodeInfo) idToNode.get(new Integer(anId));
+ }
if ( null == nodeInfo ) {
throw new IllegalArgumentException("Identifier " + anId +
" is not registered by this topology.");
@@ -328,12 +333,30 @@
return nodeInfo;
}
+ /**
+ * Gets the NodeInfo registered by this topology.
+ *
+ * @return Set of NodeInfo.
+ */
+ public Set getNodes() {
+ Set nodes;
+ synchronized(nodeAndIdLock) {
+ nodes = new HashSet(nodeToID.keySet());
+ }
+ return nodes;
+ }
+
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(nodeToPaths);
+ out.writeObject(nodeToID);
+ out.writeObject(idToNode);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ nodeAndIdLock = new Object();
nodeToPaths = (Map) in.readObject();
+ nodeToID = (Map) in.readObject();
+ idToNode = (Map) in.readObject();
}
/**