[or-cvs] r15681: Commit so Karsten may have a look (in puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi: . execute impl)

sebastian at seul.org sebastian at seul.org
Sat Jul 5 22:56:09 UTC 2008


Author: sebastian
Date: 2008-07-05 18:56:09 -0400 (Sat, 05 Jul 2008)
New Revision: 15681

Modified:
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorMasterFactory.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorSlaveFactory.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/LocalPuppeTorMaster.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorMaster.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorSlave.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/TestExecutor.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorMasterProgram.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorSlaveProgram.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorMasterImpl.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorMasterImplFactory.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorSlaveImpl.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorSlaveImplFactory.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/TestExecutorImpl.java
Log:
Commit so Karsten may have a look

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorMasterFactory.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorMasterFactory.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorMasterFactory.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -34,18 +34,17 @@
 import java.rmi.RemoteException;
 
 /**
- * Create a new representation of the server. Initialize this once with a
- * concrete subclass of itself to create the actual <code>RemotePuppeTor</code>
- * instance.
+ * Factory to create all objects needed by the master side of a PuppeTor
+ * network.
  *
  * @author Sebastian Hahn
  */
 public abstract class AbstractPuppeTorMasterFactory {
 
     /**
-     * Hold the concrete RemotePuppeTorFactory that will be used to create
-     * <code>RemotePuppeTor</code> instances. Uses
-     * <code>AbstractRemotePuppeTorFactory.class</code> for locking.
+     * Hold the concrete RemotePuppeTorFactory that will be used to create the
+     * implementation classes. Use
+     * <code>AbstractPuppeTorMasterFactory.class</code> for locking.
      */
     private static AbstractPuppeTorMasterFactory factory;
 
@@ -76,6 +75,13 @@
      *            Create the server represantation for this connected slave
      * @return The new <code>RemotePuppeTor</code> instance
      */
-    public abstract RemotePuppeTorMaster createRemotePuppeTor(PuppeTorSlave slave)
+    public abstract PuppeTorMaster createPuppeTorMaster(PuppeTorSlave slave)
             throws RemoteException;
+
+    /**
+     * Override this to create a subclass of <code>TestExecutor</code>.
+     *
+     * @return The new <code>TestExecutor</code> instance.
+     */
+    public abstract TestExecutor createTestExecutor();
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorSlaveFactory.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorSlaveFactory.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorSlaveFactory.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -79,6 +79,6 @@
      * @return The new <code>PuppeTorSlave</code> instance
      */
     public abstract PuppeTorSlave createPuppeTorSlave(final String slaveName,
-            final OS os, final String ip, final Set<Integer> ports)
-            throws NullPointerException;
+            final OS os, final String ip, final Set<Integer> ports,
+            final Set<Integer> availableRevisions) throws NullPointerException;
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/LocalPuppeTorMaster.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/LocalPuppeTorMaster.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/LocalPuppeTorMaster.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -29,8 +29,23 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
- package de.uniba.wiai.lspi.puppetor.rmi;
+package de.uniba.wiai.lspi.puppetor.rmi;
 
+/**
+ * Represent a connection between the locally running PuppeTor network Master
+ * and a slave. This is the master part of the <code>PuppeTorMaster</code>
+ * interface.
+ *
+ * @author Sebastian Hahn
+ */
 public interface LocalPuppeTorMaster {
+    /**
+     * @return the slave instance this connection refers to.
+     */
+    public PuppeTorSlave getSlave();
 
+    /**
+     * Register with the TestExecutor
+     */
+    public void registerWithTestExecutor();
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorMaster.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorMaster.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorMaster.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -31,7 +31,7 @@
  */
 package de.uniba.wiai.lspi.puppetor.rmi;
 
-public interface PuppeTorMaster extends LocalPuppeTorMaster,
-        RemotePuppeTorMaster {
+public interface PuppeTorMaster /*extends LocalPuppeTorMaster,
+RemotePuppeTorMaster*/ {
 
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorSlave.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorSlave.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorSlave.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -70,4 +70,9 @@
      * @return the ports this slave can open
      */
     public Set<Integer> openablePorts();
+
+    /**
+     * @return Tor revisions available on the slave
+     */
+    public Set<Integer> availableRevisions();
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/TestExecutor.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/TestExecutor.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/TestExecutor.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -34,44 +34,56 @@
 import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 
- /**
-  * A master uses a <code>TestExecutor</code> to load all registered tests and
-  * check whether the currently running PuppeTor network can satisfy the
-  * precondition necessary to run the test. If yes, it sets up the testing
-  * environment and passes <code>PuppeTorJob</code>s to the slaves as the test
-  * instructs it to do.
-  *
-  * @author Sebastian Hahn
-  */
+/**
+ * A master uses a <code>TestExecutor</code> to load all registered tests and
+ * check whether the currently running PuppeTor network can satisfy the
+ * precondition necessary to run the test. If yes, it sets up the testing
+ * environment and passes <code>PuppeTorJob</code>s to the slaves as the test
+ * instructs it to do.
+ *
+ * @author Sebastian Hahn
+ */
 public interface TestExecutor {
+
     /**
      * Register a test with the executor so it will consider it for execution.
      * Accept all submitted tests even though some may not be executable at the
      * moment of submission.
      */
-    public void registerTest( PuppeTorTest test );
-    
+    public void registerTest(PuppeTorTest test);
+
     /**
-     * Start executing tests. Callers should make sure that the PuppeTor
-     * network that is supposed to be used is ready.
+     * Start executing tests. Callers should make sure that the PuppeTor network
+     * that is supposed to be used is ready.
      */
     public void startTesting();
-    
+
     /**
      * Return a Map of the nodes that have been run successfully along with the
      * results of the tests.
      */
     public ConcurrentMap<PuppeTorTest, PuppeTorTestResult> getSuccessfulTests();
-    
+
     /**
      * Return a Map of the nodes that have been run but didn't complete
      * successfully along with the results of the tests.
      */
     public ConcurrentMap<PuppeTorTest, PuppeTorTestResult> getFailedTests();
-    
+
     /**
      * Return all tests that could not be executed because the PuppeTorNetwork
      * could not match a test's preconditions.
      */
     public Set<PuppeTorTest> getNotRunTests();
+
+    /**
+     * Register a newly connected PuppeTor slave via its
+     * <code>LocalPuppeTorMaster</code> connection object.
+     */
+    public void registerLocalMaster(LocalPuppeTorMaster master);
+
+    /**
+     * Unregister a PuppeTor slave. Called when a slave disconnects.
+     */
+    public void unregisterLocalMaster(LocalPuppeTorMaster master);
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorMasterProgram.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorMasterProgram.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorMasterProgram.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -40,7 +40,9 @@
 import javax.rmi.ssl.SslRMIServerSocketFactory;
 
 import de.uniba.wiai.lspi.puppetor.rmi.AbstractPuppeTorMasterFactory;
+import de.uniba.wiai.lspi.puppetor.rmi.LocalPuppeTorMaster;
 import de.uniba.wiai.lspi.puppetor.rmi.MasterConnector;
+import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorMaster;
 import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorSlave;
 import de.uniba.wiai.lspi.puppetor.rmi.RemotePuppeTorMaster;
 import de.uniba.wiai.lspi.puppetor.rmi.impl.PuppeTorMasterImplFactory;
@@ -154,14 +156,15 @@
          * @throws RemoteException
          *             RMI
          */
-        public InnerMasterConnector() throws RemoteException {
-        }
+        public InnerMasterConnector() throws RemoteException {}
 
         public RemotePuppeTorMaster registerClient(final PuppeTorSlave slave)
                 throws RemoteException {
             final AbstractPuppeTorMasterFactory fact =
                     AbstractPuppeTorMasterFactory.getInstance();
-            return fact.createRemotePuppeTor(slave);
+            final PuppeTorMaster master = fact.createPuppeTorMaster(slave);
+            ((LocalPuppeTorMaster)master).registerWithTestExecutor();
+            return (RemotePuppeTorMaster)master;
         }
     }
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorSlaveProgram.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorSlaveProgram.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorSlaveProgram.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -37,6 +37,7 @@
 import java.rmi.registry.Registry;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
 
 import javax.rmi.ssl.SslRMIClientSocketFactory;
 
@@ -154,9 +155,11 @@
         for (int i = 10025; i < 20000; i++) {
             ports.add(i);
         }
+        final Set<Integer> availableRevisions =
+                new CopyOnWriteArraySet<Integer>();
         slave =
                 fac.createPuppeTorSlave(slaveName, PuppeTorSlave.OS.UNDEFINED,
-                        "127.0.0.1", ports);
+                        "127.0.0.1", ports, availableRevisions);
 
     }
 

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorMasterImpl.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorMasterImpl.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorMasterImpl.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -34,13 +34,14 @@
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
 import java.rmi.server.Unreferenced;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ConcurrentHashMap;
 
+import de.uniba.wiai.lspi.puppetor.rmi.AbstractPuppeTorMasterFactory;
 import de.uniba.wiai.lspi.puppetor.rmi.CreateNetwork;
+import de.uniba.wiai.lspi.puppetor.rmi.LocalPuppeTorMaster;
 import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorMaster;
 import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorSlave;
 import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorTest;
+import de.uniba.wiai.lspi.puppetor.rmi.RemotePuppeTorMaster;
 
 /**
  * Represent the master at the slave, and give the master a way to interact with
@@ -49,7 +50,7 @@
  * @author Sebastian Hahn
  */
 public class PuppeTorMasterImpl extends UnicastRemoteObject implements
-        PuppeTorMaster, Unreferenced {
+ LocalPuppeTorMaster, RemotePuppeTorMaster, PuppeTorMaster, Unreferenced {
 
     /**
      * Required for serialization. Needs to change for new released versions.
@@ -61,24 +62,24 @@
      */
     private final PuppeTorSlave slave;
 
-    /**
-     * We store all the connected <code>PuppeTorSlave</code>s here. Make sure
-     * the key is never null.
-     */
-    private static final ConcurrentMap<String, PuppeTorSlave> slaves =
-            new ConcurrentHashMap<String, PuppeTorSlave>();
+    public PuppeTorSlave getSlave() {
+        return slave;
+    }
 
+    public void registerWithTestExecutor() {
+        AbstractPuppeTorMasterFactory.getInstance().createTestExecutor()
+                .registerLocalMaster(this);
+    }
+
     /**
      * Check the slave object for validity and save it for further reference
      *
      * @throws RemoteException
      *             RMI
-     * @throws IllegalArgumentException
      */
     public PuppeTorMasterImpl(final PuppeTorSlave slave) throws RemoteException {
-        if (null != slaves.putIfAbsent(slave.getName(), slave)) {
-            throw new IllegalArgumentException(slave.getName()
-                    + " has already registered with this Server");
+        if (slave.getName() == null) {
+            throw new NullPointerException("The slave's name must not be null!");
         }
         this.slave = slave;
     }
@@ -89,7 +90,6 @@
      */
     public PuppeTorTest getNewJob() throws RemoteException {
         return new CreateNetwork();
-
     }
 
     // public void repoprtResults(final String slaveName,
@@ -102,10 +102,10 @@
      * Remove the slave from the Map of slaves and destroy its workqueues.
      * Inform the TestRunner that all still-running tests failed because the
      * slave went away. XXX Don't just promise to do that - we actually have to
-     * do that when there are the queues that I mentioned.
+     * do that when there are the queues that I mentioned.-SH
      */
     public void unreferenced() {
-        slaves.remove(slave.getName());
+        AbstractPuppeTorMasterFactory.getInstance().createTestExecutor()
+                .unregisterLocalMaster(this);
     }
-
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorMasterImplFactory.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorMasterImplFactory.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorMasterImplFactory.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -33,8 +33,9 @@
 
 import java.rmi.RemoteException;
 import de.uniba.wiai.lspi.puppetor.rmi.AbstractPuppeTorMasterFactory;
+import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorMaster;
 import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorSlave;
-import de.uniba.wiai.lspi.puppetor.rmi.RemotePuppeTorMaster;
+import de.uniba.wiai.lspi.puppetor.rmi.TestExecutor;
 
 /**
  * Create <code>RemotePuppeTorImpl</code> instances
@@ -43,13 +44,14 @@
  */
 public class PuppeTorMasterImplFactory extends AbstractPuppeTorMasterFactory {
 
-    /**
-     * @return a new <code>RemotePuppeTorImpl</code> instance.
-     */
     @Override
-    public RemotePuppeTorMaster createRemotePuppeTor(final PuppeTorSlave slave)
+    public PuppeTorMaster createPuppeTorMaster(final PuppeTorSlave slave)
             throws RemoteException {
         return new PuppeTorMasterImpl(slave);
     }
 
+    @Override
+    public TestExecutor createTestExecutor() {
+        return TestExecutorImpl.getInstance();
+    }
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorSlaveImpl.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorSlaveImpl.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorSlaveImpl.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -77,6 +77,11 @@
     protected final Set<Integer> ports;
 
     /**
+     * The different revisions of Tor clients this slave can execute.
+     */
+    protected final Set<Integer> availableRevisions;
+
+    /**
      * Create a new <code>PuppeTorSlave</code> with the metrics we currently
      * use, meaning it's operating system, it's IP, and the ports it can open.
      * We may in the future include other things like Tor executable version
@@ -96,8 +101,8 @@
      *             if the slavename is null
      */
     public PuppeTorSlaveImpl(final String slaveName, final OS os,
-            final String ip, final Set<Integer> ports)
-            throws NullPointerException {
+            final String ip, final Set<Integer> ports,
+            final Set<Integer> availableRevisions) throws NullPointerException {
         if (slaveName == null) {
             throw new NullPointerException("slaveName must not be null");
         }
@@ -126,6 +131,8 @@
                             .unmodifiableSet(new CopyOnWriteArraySet<Integer>(
                                     ports));
         }
+        this.availableRevisions =
+                Collections.unmodifiableSet(availableRevisions);
     }
 
     public String getName() {
@@ -144,4 +151,7 @@
         return ports;
     }
 
+    public Set<Integer> availableRevisions() {
+        return availableRevisions;
+    }
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorSlaveImplFactory.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorSlaveImplFactory.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorSlaveImplFactory.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -49,10 +49,11 @@
      */
     @Override
     public PuppeTorSlave createPuppeTorSlave(final String slaveName,
-            final OS os, final String ip, final Set<Integer> ports)
-            throws NullPointerException {
+            final OS os, final String ip, final Set<Integer> ports,
+            final Set<Integer> availableRevisions) throws NullPointerException {
         System.out.println(slaveName);
-        return new PuppeTorSlaveImpl(slaveName, os, ip, ports);
+        return new PuppeTorSlaveImpl(slaveName, os, ip, ports,
+                availableRevisions);
     }
 
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/TestExecutorImpl.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/TestExecutorImpl.java	2008-07-05 22:24:48 UTC (rev 15680)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/TestExecutorImpl.java	2008-07-05 22:56:09 UTC (rev 15681)
@@ -32,8 +32,10 @@
 package de.uniba.wiai.lspi.puppetor.rmi.impl;
 
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+import de.uniba.wiai.lspi.puppetor.rmi.LocalPuppeTorMaster;
 import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorTest;
 import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorTestResult;
 import de.uniba.wiai.lspi.puppetor.rmi.TestExecutor;
@@ -41,12 +43,53 @@
 /**
  * @author Sebastian Hahn
  */
-public class TestExecutorImpl implements TestExecutor {
+public final class TestExecutorImpl implements TestExecutor {
 
+    /**
+     * The TestExecutor instance that we'll use
+     */
+    private static final TestExecutor instance = new TestExecutorImpl();
+
+    /**
+     * Store all local representations of connections to slaves. Use the slave's
+     * name as key.
+     */
+    private static final ConcurrentMap<String, LocalPuppeTorMaster> masters =
+            new ConcurrentHashMap<String, LocalPuppeTorMaster>();
+
+    /**
+     * Singleton
+     */
+    private TestExecutorImpl() {
+    }
+
+    public static TestExecutor getInstance() {
+        return instance;
+    }
+
+    public void registerLocalMaster(final LocalPuppeTorMaster master) {
+        System.out.println("register slave " + master.getSlave().getName());
+        if (null != masters.putIfAbsent(master.getSlave().getName(), master)) {
+            throw new IllegalArgumentException(master.getSlave().getName()
+                    + " has already registered with this Server");
+        }
+
+    }
+
+    public void unregisterLocalMaster(final LocalPuppeTorMaster master) {
+        // XXX Don't forget to mark all tests as failed that depended on this
+        // slave-SH
+        System.out.println("unregister slave " + master.getSlave().getName());
+        if (masters.remove(master.getSlave().getName()) == null) {
+            throw new RuntimeException(
+                    "This is a bug. unregisterLocalMaster must never be called twice for the same master.");
+        }
+    }
+
     protected void evaluateNetwork() {
         ;
     }
-    
+
     public void startTesting() {
         // TODO Auto-generated method stub
 
@@ -67,7 +110,7 @@
         return null;
     }
 
-    public void registerTest(PuppeTorTest test) {
+    public void registerTest(final PuppeTorTest test) {
         // TODO Auto-generated method stub
 
     }



More information about the tor-commits mailing list