[or-cvs] r15551: lots of refactoring and commenting on things for PuppeTor (in puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi: . execute)

sebastian at seul.org sebastian at seul.org
Sat Jun 28 18:47:06 UTC 2008


Author: sebastian
Date: 2008-06-28 14:47:05 -0400 (Sat, 28 Jun 2008)
New Revision: 15551

Modified:
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/CreateNetwork.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorSlave.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorTest.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorTestResult.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/RemotePuppeTor.java
   puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/RemotePuppeTorImpl.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
Log:
lots of refactoring and commenting on things for PuppeTor

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/CreateNetwork.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/CreateNetwork.java	2008-06-28 15:08:04 UTC (rev 15550)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/CreateNetwork.java	2008-06-28 18:47:05 UTC (rev 15551)
@@ -7,16 +7,16 @@
  *
  *     * 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

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-06-28 15:08:04 UTC (rev 15550)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorSlave.java	2008-06-28 18:47:05 UTC (rev 15551)
@@ -7,16 +7,16 @@
  *
  *     * 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
@@ -31,12 +31,20 @@
  */
 package de.uniba.wiai.lspi.puppetor.rmi;
 
-public class PuppeTorSlave {
+import java.io.Serializable;
 
-    protected final String name;
+/**
+ * A <code>PuppeTorSlave</code> represents a slave instance ready for tests.
+ * It carries information about the testing capabilities of a given slave. A
+ * slave may not provide information except for its name, which is always
+ * mandatory. The slave will not be used for non-client traffic, though.
+ * 
+ * @author Sebastian Hahn
+ */
+public interface PuppeTorSlave extends Serializable {
 
-    public PuppeTorSlave(final String slaveName) {
-        name = slaveName;
-    }
-
+    /**
+     * @return The slave's name.
+     */
+    public String getName();
 }

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-06-28 15:08:04 UTC (rev 15550)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorTest.java	2008-06-28 18:47:05 UTC (rev 15551)
@@ -7,16 +7,16 @@
  *
  *     * 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
@@ -36,7 +36,22 @@
 
 import de.uniba.wiai.lspi.puppetor.PuppeTorException;
 
+/**
+ * <code>PuppeTorTest</code> describes a test and the kind of slave it can run
+ * on, as well as other network settings that are required for the test to
+ * work. A test should be able to tell whether it was successfully run or not
+ * when passed a PuppeTorTestResult.
+ * 
+ * @author killerchicken
+ */
 public interface PuppeTorTest extends Serializable {
+    /**
+     * XXX this goes away. I just put it in to see whether a remote test would
+     * actually execut on a slave.
+     * @return
+     * @throws RemoteException
+     * @throws PuppeTorException
+     */
     public Object doJob() throws RemoteException, PuppeTorException;
     // public //hier dann halt network etc hin
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorTestResult.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorTestResult.java	2008-06-28 15:08:04 UTC (rev 15550)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/PuppeTorTestResult.java	2008-06-28 18:47:05 UTC (rev 15551)
@@ -7,16 +7,16 @@
  *
  *     * 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
@@ -33,6 +33,10 @@
 
 import java.io.Serializable;
 
+/**
+ * XXX unused for now. this will hold the result of a 
+ * /<code>PuppeTorTest</code> -SH
+*/
 public interface PuppeTorTestResult extends Serializable {
     public PuppeTorTest getJob();
 }

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-06-28 15:08:04 UTC (rev 15550)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/RemotePuppeTor.java	2008-06-28 18:47:05 UTC (rev 15551)
@@ -7,16 +7,16 @@
  *
  *     * 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
@@ -35,17 +35,55 @@
 import java.rmi.RemoteException;
 
 /**
+ * <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.
+ * 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.
+ * XXX We will need a way to allow the master to access this, as well as a way
+ * for clients with open ports to register for callback support instead of
+ * polling for new tasks =SH
+ * 
  * @author Sebastian Hahn
- * 
  */
-public interface RemotePuppeTor extends Remote/*
-                                                 * , UnreferencedXXX
-                                                 * Unreferenced-SH
-                                                 */{
-    public void announceNewClient(String slaveName) throws RemoteException;
+public interface RemotePuppeTor extends Remote{
 
-    public PuppeTorTest isThereNewWork(String slaveName) throws RemoteException;
+    /**
+     * 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 void repoprtResults(String slaveName, PuppeTorTestResult jobResult)
+    /**
+     * 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)
             throws RemoteException;
+            */
 }

Modified: puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/RemotePuppeTorImpl.java
===================================================================
--- puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/RemotePuppeTorImpl.java	2008-06-28 15:08:04 UTC (rev 15550)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/RemotePuppeTorImpl.java	2008-06-28 18:47:05 UTC (rev 15551)
@@ -7,16 +7,16 @@
  *
  *     * 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
@@ -36,50 +36,78 @@
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
- * @author killerchicken
+ * 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
  * 
+ * @author Sebastian Hahn
  */
 public class RemotePuppeTorImpl extends UnicastRemoteObject implements
         RemotePuppeTor {
 
+    /**
+     * Required for serialization. Needs to change for new released versions.
+     */
     private static final long serialVersionUID = 1L;
+    
+    /**
+     * We store all the connected <code>PuppeTorSlave</code>s here
+     */
     private static final ConcurrentHashMap<String, PuppeTorSlave> slaves =
             new ConcurrentHashMap<String, PuppeTorSlave>();
 
-    public RemotePuppeTorImpl() throws RemoteException {
-    }
+    /**
+     * empty default constructor needed because of the 
+     * <code>RemoteException</code>
+     * @throws RemoteException
+     *     RMI
+     */
+    public RemotePuppeTorImpl() throws RemoteException { }
 
-    /*
-     * XXX maybe it is not a good idea to throw an Exception at the client when
-     * it has already registered? -SH
+    /**
+     * A new slave that has just connected is required to call this method
+     * once and only once to register it with the server
+     * @throws IllegalArgumentException
+     *     Thrown if either slave.getName() returns NULL or the slave's name
+     *     is already registered.
+     * @throws RemoteException
+     *     RMI
      */
-    public void announceNewClient(final String slaveName)
-            throws RemoteException {
-        if (null != slaves.putIfAbsent(slaveName, new PuppeTorSlave(slaveName))) {
-            throw new IllegalArgumentException(slaveName
+    public void announceNewSlave(final PuppeTorSlave slave)
+    throws RemoteException, IllegalArgumentException {
+        if (null != slaves.putIfAbsent(slave.getName(), slave)) {
+            throw new IllegalArgumentException(slave.getName()
                     + " has already registered with this Server");
         }
     }
 
+    /**
+     * Allows the slave to poll for new work. XXX Currently, there is no logic
+     * to give back useful tasks, but if the client is known, a new 
+     * <code>CreateNetwork</code> test is submitted.-SH
+     * 
+     * @throws IllegalArgumentException
+     *     Thrown if the slave hasn't registered yet.
+     */
     public PuppeTorTest isThereNewWork(final String slaveName)
-            throws RemoteException {
-        if (slaves.containsKey(slaveName)) {
+            throws RemoteException, IllegalArgumentException {
+        if (slaves.containsKey(slaveName)) { 
             return new CreateNetwork();
         } else {
-            System.out.println("noch net da");
+            throw new IllegalArgumentException( "The slave " + slaveName + 
+                    "has not registered yet.");
         }
-        return null;
     }
 
-    public void repoprtResults(final String slaveName,
-            final PuppeTorTestResult jobResult) throws RemoteException {
+//    public void repoprtResults(final String slaveName,
+//            final PuppeTorTestResult jobResult) throws RemoteException {
         // XXX We want to let the server know that the client did some work and
-        // how it turned
-        // out to be. -SH
-    }
+        // how it turned out to be. -SH
+//    }
 
     /*
-     * public void unreferenced() { //XXX We want to notice when clients die.
-     * Realize that we need one object per client // for this to work. -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 }
      */
 }

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-06-28 15:08:04 UTC (rev 15550)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorMasterProgram.java	2008-06-28 18:47:05 UTC (rev 15551)
@@ -31,6 +31,7 @@
  */
 package de.uniba.wiai.lspi.puppetor.rmi.execute;
 
+import java.rmi.RemoteException;
 import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
 
@@ -39,46 +40,100 @@
 
 import de.uniba.wiai.lspi.puppetor.rmi.RemotePuppeTorImpl;
 
+/**
+ * The <code>PuppeTorMasterProgram</code> contains the main method for the
+ * master instance of a distributed PuppeTor testing infrastructure. Currently,
+ * configuration of the the master's network settings are implemented as 
+ * instance variables of <code>PuppeTorMasterProgram</code>.
+ * XXX eventually, using configuration files would be better -SH
+ * 
+ * @author Sebastian Hahn
+ */
 public class PuppeTorMasterProgram {
 
+    /**
+     * The object being passed to the slaves
+     */
     private RemotePuppeTorImpl impl;
-    final private static int port = 2050;
+    
+    /**
+     * The port the server is supposed to listen on. This port must not be
+     * firewalled and must be forwarded to the machine if necessary.
+     */
+    final private static int serverport = 2050;
+    
+    /**
+     * The address this server should bind on. Use 127.0.0.1 for local testing.
+     * XXX Someone should check if this works with IPv6 -SH
+     */
     final private static String serveraddress = "78.47.18.109";
 
     /**
+     * Master application entry point
+     * 
      * @param args
+     *     Command-line arguments
      */
     public static void main(final String[] args) {
-        setupRMI();
         final PuppeTorMasterProgram server = new PuppeTorMasterProgram();
         server.exportObjects();
 
-        // do stuff with the clients
+        //XXX do stuff with the clients-SH
     }
 
-    private static void setupRMI() {
+    /**
+     * Private constructor to set up RMI-related Java-internal variables
+     * and create a <code>RemotePuppeTorImpl</code>.
+     */
+    private PuppeTorMasterProgram() {
+        /**
+         * 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");
+        /**
+         * Tell the RMI system the location of the master
+         */
         System.setProperty("java.rmi.server.hostname", serveraddress);
+        try {
+            impl = new RemotePuppeTorImpl();
+        } catch (RemoteException e) {
+            /**
+             * We cannot do much better here. This is supposed to just work.
+             */
+            System.out.println("Couldn't create remote object. Dying.");
+            e.printStackTrace();
+            System.exit(1);
+        }
     }
 
+    /**
+     * 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,
+     * most likely the user's system configuration isn't correct.
+     */
     private void exportObjects() {
         try {
-            impl = new RemotePuppeTorImpl();
             final Registry registry =
-                    LocateRegistry.createRegistry(port,
+                    LocateRegistry.createRegistry(serverport,
                             new SslRMIClientSocketFactory(),
                             new SslRMIServerSocketFactory(null, null, true));
 
             registry.bind("RemotePuppeTorImpl", impl);
-
-            System.out.println("RemotePuppeTorImpl bound in registry");
         } catch (final Throwable th) {
             th.printStackTrace();
-            System.out.println("Exception occurred: " + th);
+            System.out.println("Could not create the registry or bind an" +
+              "object in it. Please check your system's configuration. " + th);
+            System.exit(1);
         }
-
     }
-
 }

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-06-28 15:08:04 UTC (rev 15550)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorSlaveProgram.java	2008-06-28 18:47:05 UTC (rev 15551)
@@ -39,72 +39,132 @@
 import javax.rmi.ssl.SslRMIClientSocketFactory;
 
 import de.uniba.wiai.lspi.puppetor.PuppeTorException;
+import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorSlaveImpl;
 import de.uniba.wiai.lspi.puppetor.rmi.PuppeTorTest;
 import de.uniba.wiai.lspi.puppetor.rmi.RemotePuppeTor;
 
+/**
+ * The <code>PuppeTorSlaveProgram</code> contains the main method for the
+ * slave instances of a distributed PuppeTor testing infrastructure. Currently,
+ * configuration of the the master's network settings and some slave-specific
+ * options are implemented as instance variables of 
+ * <code>PuppeTorSlaveProgram</code>.
+ * XXX eventually, using configuration files would be better -SH
+ * 
+ * @author Sebastian Hahn
+ */
 public class PuppeTorSlaveProgram {
+    
+    /**
+     * 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;
+    
+    /**
+     * The port the master server is supposed to listen on. This port must not
+     * be firewalled and must be forwarded to the machine if necessary. Use the
+     * same value as you used for the master's configuration.
+     */
+    final private static int serverport = 2050;
 
-    final private static int port = 2050;
+    /**
+     * The address master server listens on. Use the same value as you used
+     * for the master's configuration.
+     * XXX Someone should check if this works with IPv6 -SH
+     */
     final private static String serveraddress = "78.47.18.109";
+    
+    /**
+     * Each slave is identified by its unique <code>slaveName</code>. Be
+     * careful to prevent naming collisions between slaves.
+     */
     final private static String slaveName = "slave1";
 
     /**
+     * Slave application entry point
+     * 
      * @param args
+     *     Command-line arguments
      */
     public static void main(final String[] args) {
-        setupRMI();
         final PuppeTorSlaveProgram slave = new PuppeTorSlaveProgram();
         while (slave.connectToMaster() == false) {
             try {
                 Thread.sleep(60000); // wait one minute
             } catch (final InterruptedException e) {
-                // and immediatly retry if we're interrupted
+                // and immediatly retry if we're interrupted.
+                //XXX this isn't a good idea. we should quit.-SH
             }
         }
-
+        //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);
+            if (job != null) {
+                final Object res = job.doJob();
+            }
+        } catch (final PuppeTorException e) { 
+            e.printStackTrace();
+            System.out
+                    .println("PuppeTor didn't do what we wanted it to do." +
+                    		" For now, that's a fatal error. " + e);
+            System.exit(1);
+        } catch (RemoteException e) {
+            //XXX Need to handle the exception... -SH 
+        }
     }
 
-    private static void setupRMI() {
+    /**
+     * 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");
     }
 
-    private boolean connectToMaster() { // XXX Really only connect to the master
-                                        // here -SH
+    /**
+     * Attempt to make a connection to the master through RMI. If the server 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().
+     * 
+     * @return
+     *     true if the connection was successful, false otherwise.
+     */
+    private boolean connectToMaster() {
         try {
             final Registry registry =
-                    LocateRegistry.getRegistry(serveraddress, port,
+                    LocateRegistry.getRegistry(serveraddress, serverport,
                             new SslRMIClientSocketFactory());
 
-            final RemotePuppeTor server =
-                    (RemotePuppeTor) registry.lookup("RemotePuppeTorImpl");
-            server.announceNewClient(slaveName);
-            try {
-                final PuppeTorTest job = server.isThereNewWork(slaveName);
-                if (job != null) {
-                    final Object res = job.doJob();
-                }
-            } catch (final PuppeTorException e) { // XXX Don't die on this!-SH
-                e.printStackTrace();
-                System.out
-                        .println("PuppeTor didn't do what we wanted it to do. For now, that's a fatal error. "
-                                + e);
-                System.exit(1);
-            }
+            server = (RemotePuppeTor) registry.lookup("RemotePuppeTorImpl");
+            server.announceNewSlave(new PuppeTorSlaveImpl(slaveName));
         } catch (final NotBoundException e) {
             e.printStackTrace();
-            System.out.println("We could connect, but the server is broken: "
-                    + e);
-            System.exit(1);
+            System.out.println("We could connect, but the server does not " +
+            		"have <code>RemotePuppeTorImpl</code> exported." + e);
+            return false;
         } catch (final RemoteException e) {
             e.printStackTrace();
-            System.out.println("Exception occured: " + e);
+            //XXX remove the next line once this stabilizes-SH
+            System.out.println("Server down " + e);
             return false;
         } catch (final IllegalArgumentException e) {
             e.printStackTrace();
-            System.out.println("We're already connected to the server! " + e);
-            System.exit(1);
+            System.out.println("A slave with this name is already connected " +
+              "to the server! " + e);
+            return false;
         }
         return true;
     }



More information about the tor-commits mailing list