[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r15564: Update the factory based on karsten's suggestions. Make use (in puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi: . execute impl)
Author: sebastian
Date: 2008-06-29 07:22:22 -0400 (Sun, 29 Jun 2008)
New Revision: 15564
Modified:
puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractRemotePuppeTorFactory.java
puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorMasterProgram.java
puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/RemotePuppeTorImpl.java
Log:
Update the factory based on karsten's suggestions. Make use of it, too.
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-06-29 10:12:39 UTC (rev 15563)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/AbstractRemotePuppeTorFactory.java 2008-06-29 11:22:22 UTC (rev 15564)
@@ -31,8 +31,10 @@
*/
package de.uniba.wiai.lspi.puppetor.rmi;
+import java.rmi.RemoteException;
+
/**
- * Create a new represantation of the server. Initialize this once with a
+ * Create a new representation of the server. Initialize this once with a
* concrete subclass of itself to create the actual <code>RemotePuppeTor</code>
* instance.
*
@@ -48,21 +50,27 @@
/**
* @return a new concrete
- * <code>AbstractRemotePuppeTorFactory<code>subclass as
- * specified by the initilization
+ * <code>AbstractRemotePuppeTorFactory<code>subclass as
+ * specified by the initialization
*/
- public RemotePuppeTor getInstance() {
- return factory.getInstance();
+ final public static AbstractRemotePuppeTorFactory getInstance() {
+ return factory;
}
/**
* @param factory
* save this as the factory if this hasn't been called before.
*/
- public void initialize(final AbstractRemotePuppeTorFactory factory) {
+ final public static void initialize(final AbstractRemotePuppeTorFactory factory) {
if (AbstractRemotePuppeTorFactory.factory != null) {
AbstractRemotePuppeTorFactory.factory = factory;
}
}
-
+
+ /**
+ * Override this to create a subclass of <code>RemotePuppeTor</code>
+ * @return
+ * <code>The new RemotePuppeTor</code> instance
+ */
+ public abstract RemotePuppeTor createRemotePuppeTor() 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-06-29 10:12:39 UTC (rev 15563)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/execute/PuppeTorMasterProgram.java 2008-06-29 11:22:22 UTC (rev 15564)
@@ -38,7 +38,9 @@
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
-import de.uniba.wiai.lspi.puppetor.rmi.impl.RemotePuppeTorImpl;
+import de.uniba.wiai.lspi.puppetor.rmi.AbstractRemotePuppeTorFactory;
+import de.uniba.wiai.lspi.puppetor.rmi.RemotePuppeTor;
+import de.uniba.wiai.lspi.puppetor.rmi.impl.RemotePuppeTorImplFactory;
/**
* The <code>PuppeTorMasterProgram</code> contains the main method for the
@@ -54,7 +56,7 @@
/**
* The object being passed to the slaves
*/
- private RemotePuppeTorImpl impl;
+ private RemotePuppeTor impl;
/**
* The port the server is supposed to listen on. This port must not be
@@ -86,29 +88,26 @@
* and create a <code>RemotePuppeTorImpl</code>.
*/
private PuppeTorMasterProgram() {
- /**
- * Set the location of the keystore where your private certificate is.
- */
+ //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.
- */
+ //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
- */
+
+ /* 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
- */
+ //Tell the RMI system the location of the master
System.setProperty("java.rmi.server.hostname", serveraddress);
+ //Set up the factories we want to use
+ AbstractRemotePuppeTorFactory.initialize(
+ new RemotePuppeTorImplFactory());
+
+ AbstractRemotePuppeTorFactory fact =
+ AbstractRemotePuppeTorFactory.getInstance();
try {
- impl = new RemotePuppeTorImpl();
+ impl = fact.createRemotePuppeTor();
} catch (RemoteException e) {
- /**
- * We cannot do much better here. This is supposed to just work.
- */
+ //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);
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-06-29 10:12:39 UTC (rev 15563)
+++ puppetor/branches/gsoc2008/src/de/uniba/wiai/lspi/puppetor/rmi/impl/RemotePuppeTorImpl.java 2008-06-29 11:22:22 UTC (rev 15564)
@@ -33,6 +33,7 @@
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
+import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import de.uniba.wiai.lspi.puppetor.rmi.CreateNetwork;
@@ -56,9 +57,10 @@
private static final long serialVersionUID = 1L;
/**
- * We store all the connected <code>PuppeTorSlave</code>s here
+ * We store all the connected <code>PuppeTorSlave</code>s here. Make sure
+ * the key is never null.
*/
- private static final ConcurrentHashMap<String, PuppeTorSlave> slaves =
+ private static final ConcurrentMap<String, PuppeTorSlave> slaves =
new ConcurrentHashMap<String, PuppeTorSlave>();
/**
@@ -69,17 +71,11 @@
*/
public RemotePuppeTorImpl() throws RemoteException { }
- /**
- * 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 announceNewSlave(final PuppeTorSlave slave)
- throws RemoteException, IllegalArgumentException {
+ 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)) {
throw new IllegalArgumentException(slave.getName()
+ " has already registered with this Server");
@@ -87,12 +83,9 @@
}
/**
- * Allows the slave to poll for new work. XXX Currently, there is no logic
+ * 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, IllegalArgumentException {