edu.rice.cs.util.newjvm
Class AbstractMasterJVM

java.lang.Object
  extended by edu.rice.cs.util.newjvm.AbstractMasterJVM
All Implemented Interfaces:
MasterRemote, Remote
Direct Known Subclasses:
MainJVM

public abstract class AbstractMasterJVM
extends Object
implements MasterRemote

An abstract class implementing the logic to invoke and control, via RMI, a second Java virtual machine. This class is used by subclassing it. (See package documentation for more details.) This class runs in both the master and the slave JVMs.

Version:
$Id: AbstractMasterJVM.java 4693 2008-12-08 16:39:42Z dlsmith $

Field Summary
static Log _log
           
protected  Object _masterJVMLock
          Lock for accessing the critical state of this AbstractMasterJVM including _monitorThread.
protected  SlaveRemote _slave
          The slave JVM remote stub if it's connected; null if not connected.
protected  String _waitForQuitThreadName
          Name for the thread that waits for the slave to exit.
 
Constructor Summary
protected AbstractMasterJVM(String slaveClassName)
          Sets up the master JVM object, but does not actually invoke the slave JVM.
 
Method Summary
 void checkStillAlive()
          No-op to prove that the master is still alive.
 void dispose()
          Withdraws RMI exports for this.
abstract  void errorStartingSlave(Throwable cause)
          Called if the slave JVM dies before it is able to register.
protected  SlaveRemote getSlave()
          Returns slave remote instance, or null if not connected.
protected abstract  void handleSlaveConnected()
          Callback for when the slave JVM has connected, and the bidirectional communications link has been established.
protected abstract  void handleSlaveQuit(int status)
          Callback for when the slave JVM has quit.
protected  void invokeSlave()
          Invokes slave JVM without any JVM arguments.
protected  void invokeSlave(String[] jvmArgs, File workDir)
          Invokes slave JVM, using the system classpath.
protected  void invokeSlave(String[] jvmArgs, String cp, File workDir)
          Creates and invokes slave JVM.
protected  boolean isStartupInProgress()
          Returns true if the slave is in the process of starting.
protected  void quitSlave()
          Quits slave JVM.
 void registerSlave(SlaveRemote slave)
          Registers a slave JVM.
protected  void slaveQuitDuringStartup(int status)
          Action to take if the slave JVM quits before registering.
 void waitSlaveDone()
          Waits until no slave JVM is running under control of "this"
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

public static final Log _log

_waitForQuitThreadName

protected volatile String _waitForQuitThreadName
Name for the thread that waits for the slave to exit.


_masterJVMLock

protected final Object _masterJVMLock
Lock for accessing the critical state of this AbstractMasterJVM including _monitorThread.


_slave

protected volatile SlaveRemote _slave
The slave JVM remote stub if it's connected; null if not connected.

Constructor Detail

AbstractMasterJVM

protected AbstractMasterJVM(String slaveClassName)
                     throws RemoteException
Sets up the master JVM object, but does not actually invoke the slave JVM.

Parameters:
slaveClassName - The fully-qualified class name of the class to start up in the second JVM. This class must implement the interface specified by this class's type parameter, which must be a subclass of SlaveRemote.
Throws:
RemoteException
Method Detail

handleSlaveConnected

protected abstract void handleSlaveConnected()
Callback for when the slave JVM has connected, and the bidirectional communications link has been established. During this call, getSlave() is guaranteed to not return null.


handleSlaveQuit

protected abstract void handleSlaveQuit(int status)
Callback for when the slave JVM has quit. During this call, getSlave() is guaranteed to return null.

Parameters:
status - The exit code returned by the slave JVM.

invokeSlave

protected final void invokeSlave()
                          throws IOException,
                                 RemoteException
Invokes slave JVM without any JVM arguments.

Throws:
IllegalStateException - if slave JVM already connected or startUp is in progress.
IOException
RemoteException

invokeSlave

protected final void invokeSlave(String[] jvmArgs,
                                 File workDir)
                          throws IOException,
                                 RemoteException
Invokes slave JVM, using the system classpath.

Parameters:
jvmArgs - Array of arguments to pass to the JVM on startUp
Throws:
IllegalStateException - if slave JVM already connected or startUp is in progress.
IOException
RemoteException

invokeSlave

protected final void invokeSlave(String[] jvmArgs,
                                 String cp,
                                 File workDir)
                          throws IOException,
                                 RemoteException
Creates and invokes slave JVM.

Parameters:
jvmArgs - Array of arguments to pass to the JVM on startUp
cp - Classpath to use when starting the JVM
Throws:
IllegalStateException - if slave JVM already connected or startUp is in progress.
IOException
RemoteException

waitSlaveDone

public void waitSlaveDone()
Waits until no slave JVM is running under control of "this"


slaveQuitDuringStartup

protected void slaveQuitDuringStartup(int status)
Action to take if the slave JVM quits before registering. Assumes _masterJVMLock is held.

Parameters:
status - Status code of the JVM

errorStartingSlave

public abstract void errorStartingSlave(Throwable cause)
                                 throws RemoteException
Called if the slave JVM dies before it is able to register.

Specified by:
errorStartingSlave in interface MasterRemote
Parameters:
cause - The Throwable which caused the slave to die.
Throws:
RemoteException

checkStillAlive

public void checkStillAlive()
No-op to prove that the master is still alive.

Specified by:
checkStillAlive in interface MasterRemote

registerSlave

public void registerSlave(SlaveRemote slave)
                   throws RemoteException
Description copied from interface: MasterRemote
Registers a slave JVM. This method is called by the slave JVM after a connection is made.

Specified by:
registerSlave in interface MasterRemote
Throws:
RemoteException

dispose

public void dispose()
             throws RemoteException
Withdraws RMI exports for this.

Throws:
RemoteException

quitSlave

protected final void quitSlave()
                        throws RemoteException
Quits slave JVM. On exit, _slave == null. _quitOnStartup may be true

Throws:
IllegalStateException - if no slave JVM is connected
RemoteException

getSlave

protected final SlaveRemote getSlave()
Returns slave remote instance, or null if not connected.


isStartupInProgress

protected boolean isStartupInProgress()
Returns true if the slave is in the process of starting.