[or-cvs] r15580: Add another factory, clean up documentation, give each conne (in puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi: . execute impl)

sebastian at seul.org sebastian at seul.org
Tue Jul 1 17:45:28 UTC 2008


Author: sebastian
Date: 2008-07-01 13:45:28 -0400 (Tue, 01 Jul 2008)
New Revision: 15580

Added:
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorSlaveFactory.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/MasterConnector.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/RemotePuppeTorImplFactory.java
Modified:
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractRemotePuppeTorFactory.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorTest.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/RemotePuppeTor.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/PuppeTorSlaveImpl.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/RemotePuppeTorImpl.java
Log:
Add another factory, clean up documentation, give each connecting slave its own master view object

Added: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorSlaveFactory.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorSlaveFactory.java	                        (rev 0)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractPuppeTorSlaveFactory.java	2008-07-01 17:45:28 UTC (rev 15580)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2008, Sebastian Hahn
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ *     * Neither the names of the copyright owners nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (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;
+
+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.
+ *
+ * @author Sebastian Hahn
+ */
+public abstract class AbstractPuppeTorSlaveFactory {
+
+    /**
+     * Hold the concrete RemotePuppeTorFactory that will be used to create
+     * <code>RemotePuppeTor</code> instances.
+     */
+    volatile private static AbstractPuppeTorSlaveFactory factory;
+
+    /**
+     * @return a new concrete
+     *     <code>AbstractRemotePuppeTorFactory<code>subclass as
+     *     specified by the initialization
+     */
+    final public static AbstractPuppeTorSlaveFactory getInstance() {
+        return factory;
+    }
+
+    /**
+     * @param factory
+     *            save this as the factory if this hasn't been called before.
+     */
+    final public static void initialize(final AbstractPuppeTorSlaveFactory factory) {
+        if (AbstractPuppeTorSlaveFactory.factory != null) {
+            AbstractPuppeTorSlaveFactory.factory = factory;
+        }
+    }
+    
+    /**
+     * Override this to create a subclass of <code>RemotePuppeTor</code>
+     * @return
+     *     <code>The new RemotePuppeTor</code> instance
+     */
+    public abstract PuppeTorSlave createPuppeTorSlave() throws RemoteException;
+}

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractRemotePuppeTorFactory.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractRemotePuppeTorFactory.java	2008-07-01 16:25:32 UTC (rev 15579)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractRemotePuppeTorFactory.java	2008-07-01 17:45:28 UTC (rev 15580)
@@ -69,8 +69,11 @@
     
     /**
      * Override this to create a subclass of <code>RemotePuppeTor</code>
+     * @param slave
+     *     Create the server represantation for this connected slave
      * @return
      *     <code>The new RemotePuppeTor</code> instance
      */
-    public abstract RemotePuppeTor createRemotePuppeTor() throws RemoteException;
+    public abstract RemotePuppeTor createRemotePuppeTor(PuppeTorSlave slave)
+        throws RemoteException;
 }

Added: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/MasterConnector.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/MasterConnector.java	                        (rev 0)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/MasterConnector.java	2008-07-01 17:45:28 UTC (rev 15580)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008, Sebastian Hahn
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ *     * Neither the names of the copyright owners nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (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;
+
+import java.rmi.RemoteException;
+
+/**
+ * Handle the initial handshake with the slaves and pass them back an object
+ * that the slave uses to refer to the master. The master will create exactly
+ * one <code>MasterConnector</code>, slaves don't ever need one.
+ * 
+ * @author Sebastian Hahn
+ */
+public interface MasterConnector {
+	
+	/**
+	 * Called once by every connecting client so that the master knows about it
+	 * and has a chance to pass back a representation of itself.
+	 * @param slave
+	 *     A slave representation as passed from the connecting slave
+	 * @return
+	 *     The representation of the master
+	 * @throws RemoteException
+	 */
+	public RemotePuppeTor registerClient
+    ( final PuppeTorSlave slave ) throws RemoteException;
+}

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorTest.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorTest.java	2008-07-01 16:25:32 UTC (rev 15579)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorTest.java	2008-07-01 17:45:28 UTC (rev 15580)
@@ -42,7 +42,7 @@
  * work. A test should be able to tell whether it was successfully run or not
  * when passed a PuppeTorTestResult.
  * 
- * @author killerchicken
+ * @author Sebastian Hahn
  */
 public interface PuppeTorTest extends Serializable {
     /**

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/RemotePuppeTor.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/RemotePuppeTor.java	2008-07-01 16:25:32 UTC (rev 15579)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/RemotePuppeTor.java	2008-07-01 17:45:28 UTC (rev 15580)
@@ -33,11 +33,13 @@
 
 import java.rmi.Remote;
 import java.rmi.RemoteException;
+import java.rmi.server.Unreferenced;
 
 /**
  * <code>RemotePuppeTor</code> is the main interface that drives the 
  * interaction between the interconnected master and its slave instances. It is
- * published by the master's instance.
+ * published by the master's instance, and represents the view of the master a
+ * slave has.
  * It provides ways for the slave to register a <code>PuppeTorSlave</code>
  * to provide information about its capabilities, as well as a way for the
  * slave to poll the master for new work and then report back results.
@@ -47,43 +49,24 @@
  * 
  * @author Sebastian Hahn
  */
-public interface RemotePuppeTor extends Remote{
+public interface RemotePuppeTor extends Remote, Unreferenced{
 
     /**
-     * Every slave has to call this once and only once after the connection is
-     * established. This method is responsible for any initialization the 
-     * master may need to be doing for a new slave.
-     * 
-     * @param slave
-     *     A <code>PuppeTorSlave</code> that describes the connecting client.
-     * @throws RemoteException
-     *     Regular RemoteException... This is RMI
-     * @throws IllegalArgumentException
-     *     Thrown if the slave object is rejected by the master
-     */
-    public void announceNewSlave(PuppeTorSlave slave) throws RemoteException, IllegalArgumentException;
-    
-    /**
      * Slaves that must poll because they are not reachable can use this
      * method to ask the master for new work.
      * 
-     * @param slaveName
-     *     The slave's name that we want work for
      * @throws RemoteException
      *     RMI...
-     * @throws IllegalArgumentException
-     *     Thrown if the slave name is not registered
      */
-    public PuppeTorTest isThereNewWork(String slaveName) throws RemoteException, IllegalArgumentException;
+    public PuppeTorTest getNewJob() throws RemoteException;
 
     /**
      * XXX We want the slaves to report back when they have an update for the
      * master-SH
-     * @param slaveName
      * @param jobResult
      * @throws RemoteException
      
-    public void repoprtResults(String slaveName, PuppeTorTestResult testResult)
+    public void reportResults(PuppeTorTestResult testResult)
             throws RemoteException;
             */
 }

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-01 16:25:32 UTC (rev 15579)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorMasterProgram.java	2008-07-01 17:45:28 UTC (rev 15580)
@@ -34,11 +34,14 @@
 import java.rmi.RemoteException;
 import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
 
 import javax.rmi.ssl.SslRMIClientSocketFactory;
 import javax.rmi.ssl.SslRMIServerSocketFactory;
 
 import de.uniba.wiai.lspi.puppetor.rmi.AbstractRemotePuppeTorFactory;
+import de.uniba.wiai.lspi.puppetor.rmi.MasterConnector;
+import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorSlave;
 import de.uniba.wiai.lspi.puppetor.rmi.RemotePuppeTor;
 import de.uniba.wiai.lspi.puppetor.rmi.impl.RemotePuppeTorImplFactory;
 
@@ -52,11 +55,11 @@
  * @author Sebastian Hahn
  */
 public class PuppeTorMasterProgram {
-
+    
     /**
-     * The object being passed to the slaves
+     * The login object for clients
      */
-    private RemotePuppeTor impl;
+    final private UnicastRemoteObject master;
     
     /**
      * The port the server is supposed to listen on. This port must not be
@@ -74,11 +77,11 @@
      * Master application entry point
      * 
      * @param args
-     *     Command-line arguments
+     *     Command-line arguments - ignored for now.
      */
     public static void main(final String[] args) {
         final PuppeTorMasterProgram server = new PuppeTorMasterProgram();
-        server.exportObjects();
+        server.exportObject();
 
         //XXX do stuff with the clients-SH
     }
@@ -102,10 +105,22 @@
         AbstractRemotePuppeTorFactory.initialize(
                 new RemotePuppeTorImplFactory());
         
-        AbstractRemotePuppeTorFactory fact =
-            AbstractRemotePuppeTorFactory.getInstance();
+        class InnerMasterConnector extends UnicastRemoteObject implements MasterConnector {
+        	/**
+             * Required for serialization. Needs to change for new released versions.
+             */
+			private static final long serialVersionUID = 1L;
+
+			public RemotePuppeTor registerClient
+		        ( final PuppeTorSlave slave ) throws RemoteException {
+			    AbstractRemotePuppeTorFactory fact = 
+	                AbstractRemotePuppeTorFactory.getInstance();
+			    return fact.createRemotePuppeTor(slave);
+		    }
+        }
+        
         try {
-            impl = fact.createRemotePuppeTor();
+            master = new InnerMasterConnector();
         } catch (RemoteException e) {
             //We cannot do much better here. This is supposed to just work.
             System.out.println("Couldn't create remote object. Dying.");
@@ -117,17 +132,17 @@
     /**
      * Create an RMI registry that uses SSL-secured Sockets for communication,
      * requires client authentication, and bind our 
-     * <code>RemotePuppeTorImpl</code> in the registry. If this doesn't work,
+     * <code>MasterConnector</code> in the registry. If this doesn't work,
      * most likely the user's system configuration isn't correct.
      */
-    private void exportObjects() {
+    private void exportObject() {
         try {
             final Registry registry =
                     LocateRegistry.createRegistry(serverport,
                             new SslRMIClientSocketFactory(),
                             new SslRMIServerSocketFactory(null, null, true));
 
-            registry.bind("RemotePuppeTorImpl", impl);
+            registry.bind("Master", master);
         } catch (final Throwable th) {
             th.printStackTrace();
             System.out.println("Could not create the registry or bind an" +

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-01 16:25:32 UTC (rev 15579)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorSlaveProgram.java	2008-07-01 17:45:28 UTC (rev 15580)
@@ -39,6 +39,8 @@
 import javax.rmi.ssl.SslRMIClientSocketFactory;
 
 import de.uniba.wiai.lspi.puppetor.PuppeTorException;
+import de.uniba.wiai.lspi.puppetor.rmi.MasterConnector;
+import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorSlave;
 import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorTest;
 import de.uniba.wiai.lspi.puppetor.rmi.RemotePuppeTor;
 import de.uniba.wiai.lspi.puppetor.rmi.impl.PuppeTorSlaveImpl;
@@ -59,7 +61,7 @@
      * The <code>RemotePuppeTor</code> object that is exported by the server.
      * This variable may be written to only from the main thread.
      */
-    volatile private RemotePuppeTor server;
+    volatile private RemotePuppeTor master;
     
     /**
      * The port the master server is supposed to listen on. This port must not
@@ -80,6 +82,11 @@
      * careful to prevent naming collisions between slaves.
      */
     final private static String slaveName = "slave1";
+    
+    /**
+     * A representation of this slave node to be sent to the master.
+     */
+    final private PuppeTorSlave slave;
 
     /**
      * Slave application entry point
@@ -100,7 +107,7 @@
         //XXX How about we spawn a thread here that polls for new work and puts
         // it in a nice little queue that some worker threads use...
         try {
-            final PuppeTorTest job = slave.server.isThereNewWork(slaveName);
+            final PuppeTorTest job = slave.master.getNewJob();
             if (job != null) {
                 final Object res = job.doJob();
             }
@@ -119,23 +126,29 @@
      * Private constructor to set up RMI-related Java-internal variables.
      */
     private PuppeTorSlaveProgram() {
-        /**
+        /*
          * Set the location of the keystore where your private certificate is.
          */
         System.setProperty("javax.net.ssl.keyStore", "res/keystore");
-        /**
+        /*
          * Set the password for your keystore.
          */
         System.setProperty("javax.net.ssl.keyStorePassword", "asdasd");
-        /**
+        /* 
          * Set the location of the truststore which contains the exported
          * certificates of your slaves
          */
         System.setProperty("javax.net.ssl.trustStore", "res/truststore");
+        /*
+         * Create a new slave with the properties that are relevant for the
+         * computer and networking environment it runs on.
+         */
+        this.slave = new PuppeTorSlaveImpl(slaveName);
+        
     }
 
     /**
-     * Attempt to make a connection to the master through RMI. If the server is
+     * Attempt to make a connection to the master through RMI. If the master is
      * down, that is not a fatal condition, we want to keep trying until we can
      * reach it. Don't call this except from main().
      * 
@@ -148,12 +161,12 @@
                     LocateRegistry.getRegistry(serveraddress, serverport,
                             new SslRMIClientSocketFactory());
 
-            server = (RemotePuppeTor) registry.lookup("RemotePuppeTorImpl");
-            server.announceNewSlave(new PuppeTorSlaveImpl(slaveName));
+            ((MasterConnector)registry.lookup("Master")).registerClient(
+            		this.slave);
         } catch (final NotBoundException e) {
             e.printStackTrace();
-            System.out.println("We could connect, but the server does not " +
-            		"have <code>RemotePuppeTorImpl</code> exported." + e);
+            System.out.println("We could connect, but the master has not " +
+            		"exported the Master Object yet." + e);
             return false;
         } catch (final RemoteException e) {
             e.printStackTrace();

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-01 16:25:32 UTC (rev 15579)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/PuppeTorSlaveImpl.java	2008-07-01 17:45:28 UTC (rev 15580)
@@ -34,12 +34,13 @@
 import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorSlave;
 
 /**
- * Implements a <code>PuppeTorSlave</code>. Depending on what it is used for,
- * different constructors are provided to specify the client's capabilities.
+ * Describe a client including its capabilities and network location to the
+ * master. Also allow the master to query that information. A slave is not
+ * required to give more than its name, but it can only be used for very
+ * limited tests.
  * 
  * @author Sebastian Hahn
  */
-
 public final class PuppeTorSlaveImpl implements PuppeTorSlave {
 
     /**
@@ -58,8 +59,13 @@
      * information.
      * @param slaveName
      *     The slave's name
+     * @throws
+     *     NullPointerException
      */
-    public PuppeTorSlaveImpl(final String slaveName) {
+    public PuppeTorSlaveImpl(final String slaveName)
+        throws NullPointerException {
+        if(slaveName == null)
+        	throw new NullPointerException("slaveName must not be null");
         name = slaveName;
     }
 

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/RemotePuppeTorImpl.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/RemotePuppeTorImpl.java	2008-07-01 16:25:32 UTC (rev 15579)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/RemotePuppeTorImpl.java	2008-07-01 17:45:28 UTC (rev 15580)
@@ -42,9 +42,8 @@
 import de.uniba.wiai.lspi.puppetor.rmi.RemotePuppeTor;
 
 /**
- * Implementation for <code>RemotePuppeTor</code>. XXX Currently, this object
- * is shared for all the connecting slaves, but this may change. If this
- * changes, we don't need the slave's name for the method calls.-SH
+ * Represent the master at the slave, and give the master a way to interact
+ * with the respective slave.
  * 
  * @author Sebastian Hahn
  */
@@ -56,7 +55,13 @@
      */
     private static final long serialVersionUID = 1L;
     
+    
     /**
+     * Store the reference to the connected slave 
+     */
+    private final PuppeTorSlave slave;
+    
+    /**
      * We store all the connected <code>PuppeTorSlave</code>s here. Make sure
      * the key is never null.
      */
@@ -64,22 +69,17 @@
             new ConcurrentHashMap<String, PuppeTorSlave>();
 
     /**
-     * empty default constructor needed because of the 
-     * <code>RemoteException</code>
+     * Check the slave object for validity and save it for further reference
      * @throws RemoteException
      *     RMI
+     * @throws IllegalArgumentException
      */
-    public RemotePuppeTorImpl() throws RemoteException { }
-
-    public void announceNewSlave(final PuppeTorSlave slave)
-        throws RemoteException, IllegalArgumentException {
-        if(slave.getName() == null)
-            throw new NullPointerException( "The slave's name must not be null"
-                    );
-        if (null != slaves.putIfAbsent(slave.getName(), slave)) {
+    public RemotePuppeTorImpl( final PuppeTorSlave slave ) throws RemoteException {
+    	if (null != slaves.putIfAbsent(slave.getName(), slave)) {
             throw new IllegalArgumentException(slave.getName()
                     + " has already registered with this Server");
         }
+    	this.slave = slave;
     }
 
     /**
@@ -87,14 +87,10 @@
      * to give back useful tasks, but if the client is known, a new 
      * <code>CreateNetwork</code> test is submitted.-SH
      */
-    public PuppeTorTest isThereNewWork(final String slaveName)
-            throws RemoteException, IllegalArgumentException {
-        if (slaves.containsKey(slaveName)) { 
-            return new CreateNetwork();
-        } else {
-            throw new IllegalArgumentException( "The slave " + slaveName + 
-                    "has not registered yet.");
-        }
+    public PuppeTorTest getNewJob()
+            throws RemoteException {
+        return new CreateNetwork();
+        
     }
 
 //    public void repoprtResults(final String slaveName,
@@ -103,9 +99,15 @@
         // how it turned out to be. -SH
 //    }
 
-    /*
-     * public void unreferenced() { //XXX We would to notice when clients die.
-     * Realize that we need one object per client for this to work. I have to
-     * learn how it works ;) -SH }
+    /**
+     * 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.
      */
+    public void unreferenced() {
+    	slaves.remove(this.slave.getName());
+    }
+    
 }

Added: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/RemotePuppeTorImplFactory.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/RemotePuppeTorImplFactory.java	                        (rev 0)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/RemotePuppeTorImplFactory.java	2008-07-01 17:45:28 UTC (rev 15580)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008, Sebastian Hahn
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ *     * Neither the names of the copyright owners nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (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.impl;
+
+import java.rmi.RemoteException;
+import de.uniba.wiai.lspi.puppetor.rmi.AbstractRemotePuppeTorFactory;
+import de.uniba.wiai.lspi.puppetor.rmi.RemotePuppeTor;
+
+/**
+ * Create <code>RemotePuppeTorImpl</code> instances
+ * 
+ * @author Sebastian Hahn
+ */
+public class RemotePuppeTorImplFactory extends AbstractRemotePuppeTorFactory {
+
+    /**
+     * @return
+     *     a new <code>RemotePuppeTorImpl</code> instance.
+     */
+    @Override
+    public RemotePuppeTor createRemotePuppeTor() throws RemoteException{
+        return new RemotePuppeTorImpl();
+    }
+
+}



More information about the tor-commits mailing list