[or-cvs] r15872: New static method to get a Network by name (puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor)

sebastian at seul.org sebastian at seul.org
Sun Jul 13 14:25:55 UTC 2008


Author: sebastian
Date: 2008-07-13 10:25:54 -0400 (Sun, 13 Jul 2008)
New Revision: 15872

Modified:
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/NetworkFactory.java
Log:
New static method to get a Network by name

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/NetworkFactory.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/NetworkFactory.java	2008-07-13 08:49:46 UTC (rev 15871)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/NetworkFactory.java	2008-07-13 14:25:54 UTC (rev 15872)
@@ -31,6 +31,9 @@
  */
 package de.uniba.wiai.lspi.puppetor;
 
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
 import de.uniba.wiai.lspi.puppetor.impl.NetworkImpl;
 
 /**
@@ -48,6 +51,8 @@
  */
 public abstract class NetworkFactory {
 
+    final private static ConcurrentMap<String, Network> networks = new ConcurrentHashMap<String,Network>();
+    
 	/**
 	 * Creates a new network that is required for a test run. The new network is
 	 * initially unpopulated and creates its own working directory at
@@ -59,7 +64,9 @@
 	 * @return A new network instance.
 	 */
 	public static Network createNetwork(String networkName) {
-		return new NetworkImpl(networkName);
+		Network network = new NetworkImpl(networkName);
+		networks.put(networkName, network);
+	    return network;
 	}
 
 	/**
@@ -80,7 +87,19 @@
 	 * @return A new network instance.
 	 */
 	public static Network createNetwork(String networkName, int startPort) {
-		return new NetworkImpl(networkName, startPort);
+	    Network network = new NetworkImpl(networkName, startPort);
+	    networks.put(networkName, network);
+	    return network;
 	}
-
+	
+	/**
+	 * 
+	 */
+    public static Network getNetworkByName( String networkName ) {
+        Network network = networks.get(networkName);
+        if( network == null)
+            throw new IllegalStateException("BUG: The network with name " 
+                    + networkName + " must exist and be non-null!");
+        return network;
+    }
 }



More information about the tor-commits mailing list