edu.rice.cs.util.newjvm
Class AbstractSlaveJVM

java.lang.Object
  extended by edu.rice.cs.util.newjvm.AbstractSlaveJVM
All Implemented Interfaces:
SlaveRemote, Remote
Direct Known Subclasses:
IntegratedMasterSlaveTest.CounterSlave, InterpreterJVM

public abstract class AbstractSlaveJVM
extends Object
implements SlaveRemote

A partial implementation of a SlaveRemote that provides the quit functionality and that also periodically checks if the master is still alive and automatically quits if not.

Version:
$Id: AbstractSlaveJVM.java 4691 2008-12-02 23:33:27Z dlsmith $

Field Summary
protected static Log _log
           
protected  String _pollMasterThreadName
          Name of the thread to periodically poll the master.
protected  String _quitSlaveThreadName
          Name of the thread to quit the slave.
static int CHECK_MAIN_VM_ALIVE_SECONDS
           
 
Constructor Summary
AbstractSlaveJVM()
           
 
Method Summary
protected  void beforeQuit()
          This method is called just before the JVM is quit.
protected abstract  void handleStart(MasterRemote master)
          Called when the slave JVM has started running.
 void quit()
          Quits the slave JVM, calling beforeQuit() before it does.
protected  void quitFailed(Throwable th)
          This method is called if the interpreterJVM cannot be exited (likely because of a unexpected security manager.)
 void start(MasterRemote master)
          Initializes the Slave JVM including starting background thread to periodically poll the master JVM and automatically quit if it's dead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHECK_MAIN_VM_ALIVE_SECONDS

public static final int CHECK_MAIN_VM_ALIVE_SECONDS
See Also:
Constant Field Values

_log

protected static final Log _log

_quitSlaveThreadName

protected volatile String _quitSlaveThreadName
Name of the thread to quit the slave.


_pollMasterThreadName

protected volatile String _pollMasterThreadName
Name of the thread to periodically poll the master.

Constructor Detail

AbstractSlaveJVM

public AbstractSlaveJVM()
                 throws RemoteException
Throws:
RemoteException
Method Detail

quit

public final void quit()
Quits the slave JVM, calling beforeQuit() before it does.

Specified by:
quit in interface SlaveRemote

beforeQuit

protected void beforeQuit()
This method is called just before the JVM is quit. It can be overridden to provide cleanup code, etc.


quitFailed

protected void quitFailed(Throwable th)
This method is called if the interpreterJVM cannot be exited (likely because of a unexpected security manager.)


start

public final void start(MasterRemote master)
                 throws RemoteException
Initializes the Slave JVM including starting background thread to periodically poll the master JVM and automatically quit if it's dead. Unsynchronized because (i) this method can only be called once (without throwing an error) and _master is immutable once assigned here until quit() (ii) this method does not depend on any mutable state in this (which constrains handleStart(edu.rice.cs.util.newjvm.MasterRemote)); and (iii) this method (and perhaps handleStart(edu.rice.cs.util.newjvm.MasterRemote)) perform remote calls on master. This method delegates starting actions other than polling master to handleStart(edu.rice.cs.util.newjvm.MasterRemote).

Specified by:
start in interface SlaveRemote
Parameters:
master - The remote link to the master JVM. Note that the implementation of the slave class will have to downcast this reference to the correct master remote interface. Also note that because of the GJ erasure semantics, this can't have the type it, which is MasterRemote. Luckily it doesn't matter much here to use the erased type.
Throws:
RemoteException

handleStart

protected abstract void handleStart(MasterRemote master)
Called when the slave JVM has started running. Subclasses must implement this method.