|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.util.newjvm.AbstractMasterJVM
public abstract class AbstractMasterJVM
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.)
The state-changing methods of this class consistently block until a precondition for the state
change is satisfied — for example, quitSlave() cannot complete until a slave is
running. Only one thread may change the state at a time. Thus, clients should be careful
to only invoke state-changing methods when they are guaranteed to succeed (only invoking
quitSlave(), for example, when it is known to have been matched by a successful
invokeSlave invocation).
| Nested Class Summary | |
|---|---|
private static class |
AbstractMasterJVM.SlaveFactory
Loads an instance of the given AbstractSlaveJVM class. |
private static class |
AbstractMasterJVM.State
Synchronization strategy: compare-and-swap guarantees that only one thread enters a STARTING, or QUITTING, or DISPOSED state. |
| Field Summary | |
|---|---|
private LazyThunk<MasterRemote> |
_masterStub
|
private StateMonitor<AbstractMasterJVM.State> |
_monitor
|
private SlaveRemote |
_slave
The slave JVM remote stub (non-null when the state is RUNNING). |
private AbstractMasterJVM.SlaveFactory |
_slaveFactory
|
| Constructor Summary | |
|---|---|
protected |
AbstractMasterJVM(String slaveClassName)
Set up the master JVM object. |
| Method Summary | |
|---|---|
private static void |
attemptQuit(SlaveRemote slave)
Make a best attempt to invoke slave.quit(). |
void |
checkStillAlive()
No-op to prove that the master is still alive. |
protected void |
dispose()
Free the resources required for this object to respond to RMI invocations (useful for applications -- such as testing -- that produce a large number of MasterJVMs as a program runs). |
protected abstract void |
handleSlaveConnected(SlaveRemote newSlave)
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 abstract void |
handleSlaveWontStart(Exception e)
Callback for when the slave JVM fails to either run or respond to SlaveRemote.start(edu.rice.cs.util.newjvm.MasterRemote). |
protected void |
invokeSlave(JVMBuilder jvmBuilder)
Creates and starts the slave JVM. |
protected boolean |
isDisposed()
|
protected void |
quitSlave()
Quits slave JVM. |
private void |
transition(AbstractMasterJVM.State from,
AbstractMasterJVM.State to)
Make a thread-safe state transition. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final StateMonitor<AbstractMasterJVM.State> _monitor
private final AbstractMasterJVM.SlaveFactory _slaveFactory
private final LazyThunk<MasterRemote> _masterStub
private volatile SlaveRemote _slave
| Constructor Detail |
|---|
protected AbstractMasterJVM(String slaveClassName)
slaveClassName - The fully-qualified class name of the class to start up in the second JVM. Must be a
subclass of AbstractSlaveJVM.| Method Detail |
|---|
protected abstract void handleSlaveConnected(SlaveRemote newSlave)
protected abstract void handleSlaveQuit(int status)
status - The exit code returned by the slave JVM.protected abstract void handleSlaveWontStart(Exception e)
SlaveRemote.start(edu.rice.cs.util.newjvm.MasterRemote).
e - Exception that occurred during startup.protected final void invokeSlave(JVMBuilder jvmBuilder)
handleSlaveConnected(edu.rice.cs.util.newjvm.SlaveRemote)
or handleSlaveWontStart(java.lang.Exception) before returning.
jvmBuilder - JVMBuilder to use in starting the remote process.
IllegalStateException - If this object has been disposed.protected final void quitSlave()
IllegalStateException - If this object has been disposed.private static void attemptQuit(SlaveRemote slave)
slave.quit(). Log an error if it fails.
protected void dispose()
private void transition(AbstractMasterJVM.State from,
AbstractMasterJVM.State to)
from state is reached and this
thread is successful in performing the transition (only one thread can do so at a time). Throws
an IllegalStateException if the DISPOSED state is reached first, since there is never a transition
out of the disposed state (the alternative is to block permanently).
protected boolean isDisposed()
public void checkStillAlive()
checkStillAlive in interface MasterRemote
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||