|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.util.newjvm.AbstractMasterJVM
edu.rice.cs.drjava.model.repl.newjvm.MainJVM
public class MainJVM
Manages a remote JVM. Includes methods for communication in both directions: MainJVMRemoteI provides callbacks allowing the remote JVM to access the model, and a variety of delegating methods wrap calls to the InterpreterJVMRemoteI methods, taking care of any RMI-related errors. In the case of errors, these interpreter-delegating methods communicate the failure via the return value. (Note that it is impossible to guarantee success of these methods -- the remote process may exit arbitrarily at any time -- and clients should behave gracefully when failures occur.)
The current design is flawed: strictly speaking, two sequential interpreter-delegating calls to this object may communicate with different JVMs if the remote JVM happens to reset in the interim. A better design would return a separate object for interfacing with each unique remote JVM. In this way, clients would know that all calls to a certain object would be forwarded to the same remote JVM.
| Nested Class Summary | |
|---|---|
private class |
MainJVM.DisposedState
|
static class |
MainJVM.DummyDebugModel
DebugModelCallback which does not react to events. |
static class |
MainJVM.DummyInteractionsModel
InteractionsModel which does not react to events. |
static class |
MainJVM.DummyJUnitModel
JUnitModel which does not react to events. |
private class |
MainJVM.FreshRunningState
Variant of RunningState where the interpreter JVM has not yet been used. |
private class |
MainJVM.FreshState
Fresh, hasn't yet been started. |
private class |
MainJVM.RestartingState
Waiting for stop, should automatically start when that happens. |
private class |
MainJVM.ResultHandler
Performs the appropriate action to return any type of result from a call to interpret back to the GlobalModel. |
private class |
MainJVM.RunningState
Has an active interpreter available. |
private class |
MainJVM.StartingState
Has been started, waiting for startup to complete. |
private class |
MainJVM.State
State-based implementation of the starting/stopping functionality. |
private class |
MainJVM.StoppingState
Waiting for stop, no restart. |
| Field Summary | |
|---|---|
private boolean |
_allowAssertions
Whether to allow "assert" statements to run in the remote JVM. |
private DebugModelCallback |
_debugModel
Listens to debug-related events |
private MainJVM.ResultHandler |
_handler
Instance of inner class to handle interpret result. |
private InteractionsModelCallback |
_interactionsModel
Listens to interactions-related events. |
private JUnitModelCallback |
_junitModel
Listens to JUnit-related events. |
private Iterable<File> |
_startupClassPath
Class path to use for starting the interpreter JVM |
private StateMonitor<MainJVM.State> |
_state
Contains the current InterpreterJVM stub, or null if it is not running. |
private File |
_workingDir
Working directory for slave JVM |
private static int |
MAX_STARTUP_FAILURES
Number of slave startup failures allowed before aborting the startup process. |
private static int |
STARTUP_TIMEOUT
Number of milliseconds to block while waiting for an InterpreterJVM stub. |
| Constructor Summary | |
|---|---|
MainJVM(File wd)
Creates a new MainJVM to interface to another JVM; the MainJVM has a link to the partially initialized global model. |
|
| Method Summary | |
|---|---|
private void |
_doStartup()
Call invokeSlave with the appropriate JVMBuilder. |
private int |
_getDebugPort()
Returns the debug port to use, as specified by the model. |
private void |
_handleRemoteException(RemoteException e)
Lets the model know if any exceptions occur while communicating with the Interpreter JVM. |
boolean |
addBuildDirectoryClassPath(File f)
Blocks until the interpreter is connected. |
boolean |
addExternalFilesClassPath(File f)
Blocks until the interpreter is connected. |
boolean |
addExtraClassPath(File f)
Blocks until the interpreter is connected. |
boolean |
addInterpreter(String name)
Adds a named interpreter to the list. |
boolean |
addProjectClassPath(File f)
Blocks until the interpreter is connected. |
boolean |
addProjectFilesClassPath(File f)
Blocks until the interpreter is connected. |
void |
classFileError(ClassFileError e)
Called if the slave JVM encounters an illegal class file in testing. |
void |
dispose()
Stop the interpreter JVM, do not restart it, and terminate the RMI server associated with this object. |
Option<List<String>> |
findTestClasses(List<String> classNames,
List<File> files)
Sets up a JUnit test suite in the Interpreter JVM and finds which classes are really TestCase classes (by loading them). |
Option<Iterable<File>> |
getClassPath()
Returns the current class path of the interpreter as a list of unique entries. |
String |
getConsoleInput()
Asks the main jvm for input from the console. |
File |
getFileForClassName(String className)
Called when the JUnitTestManager wants to open a file that is not currently open. |
Option<Pair<String,String>> |
getVariableToString(String var)
Gets the string representation of the value of a variable in the current interpreter, or "none" if the remote JVM is unavailable or an error occurs. |
protected void |
handleSlaveConnected(SlaveRemote newSlave)
Callback for when the slave JVM has connected, and the bidirectional communications link has been established. |
protected void |
handleSlaveQuit(int status)
Callback for when the slave JVM has quit. |
protected 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). |
boolean |
interpret(String s)
Interprets string s in the remote JVM. |
void |
nonTestCase(boolean isTestAll,
boolean didCompileFail)
Called if JUnit is invoked on a non TestCase class. |
boolean |
removeInterpreter(String name)
Removes the interpreter with the given name, if it exists. |
void |
restartInterpreterJVM(boolean force)
Get a "fresh" interpreter JVM. |
protected InterpretResult.Visitor<Void> |
resultHandler()
Declared as a getter in order to allow subclasses to override the standard behavior. |
boolean |
runTestSuite()
Runs the JUnit test suite already cached in the Interpreter JVM. |
Option<Pair<Boolean,Boolean>> |
setActiveInterpreter(String name)
Sets the current interpreter to the one specified by name. |
void |
setAllowAssertions(boolean allow)
Sets whether the remote JVM will run "assert" statements after the next restart. |
void |
setDebugModel(DebugModelCallback model)
Provides an object to listen to debug-related events. |
boolean |
setEnforceAllAccess(boolean enforce)
Sets the interpreter to enforce access to all members. |
boolean |
setEnforcePrivateAccess(boolean enforce)
Sets the interpreter to enforce access to private members. |
void |
setInteractionsModel(InteractionsModelCallback model)
Provides an object to listen to interactions-related events. |
void |
setJUnitModel(JUnitModelCallback model)
Provides an object to listen to test-related events. |
boolean |
setPackageScope(String packageName)
Sets the Interpreter to be in the given package. |
boolean |
setRequireSemicolon(boolean require)
Require a semicolon at the end of statements. |
boolean |
setRequireVariableType(boolean require)
Require variable declarations to include an explicit type. |
void |
setStartupClassPath(String classPath)
Sets the class path to use for starting the interpreter JVM. |
Option<Pair<Boolean,Boolean>> |
setToDefaultInterpreter()
Sets the default interpreter to be the current one. |
void |
setWorkingDirectory(File dir)
Sets the working directory for the interpreter (takes effect on next startup). |
void |
startInterpreterJVM()
Starts the interpreter if it's not running already. |
void |
stopInterpreterJVM()
Stop the interpreter if it's current running. |
void |
systemErrPrint(String s)
Forwards a call to System.err from InterpreterJVM to the local InteractionsModel. |
void |
systemOutPrint(String s)
Forwards a call to System.out from InterpreterJVM to the local InteractionsModel. |
void |
testEnded(String testName,
boolean wasSuccessful,
boolean causedError)
Called when a particular test has ended. |
void |
testStarted(String testName)
Called when a particular test is started. |
void |
testSuiteEnded(JUnitError[] errors)
Called when a full suite of tests has finished running. |
void |
testSuiteStarted(int numTests)
Called to indicate that a suite of tests has started running. |
| Methods inherited from class edu.rice.cs.util.newjvm.AbstractMasterJVM |
|---|
checkStillAlive, invokeSlave, isDisposed, quitSlave |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface edu.rice.cs.util.newjvm.MasterRemote |
|---|
checkStillAlive |
| Field Detail |
|---|
private static final int MAX_STARTUP_FAILURES
private static final int STARTUP_TIMEOUT
private final StateMonitor<MainJVM.State> _state
null if it is not running.
private final MainJVM.ResultHandler _handler
private volatile InteractionsModelCallback _interactionsModel
private volatile JUnitModelCallback _junitModel
private volatile DebugModelCallback _debugModel
private volatile boolean _allowAssertions
private volatile Iterable<File> _startupClassPath
private volatile File _workingDir
| Constructor Detail |
|---|
public MainJVM(File wd)
| Method Detail |
|---|
public void startInterpreterJVM()
public void stopInterpreterJVM()
startInterpreterJVM() is called
again, all methods that delegate to the interpreter JVM will fail, returning "false" or "none".)
public void restartInterpreterJVM(boolean force)
startInterpreterJVM() if no interpreter
is running. If a currently-running JVM is already "fresh", it is still stopped and restarted when
force is true.
public void dispose()
dispose in class AbstractMasterJVMprotected void handleSlaveConnected(SlaveRemote newSlave)
handleSlaveConnected in class AbstractMasterJVMprotected void handleSlaveQuit(int status)
handleSlaveQuit in class AbstractMasterJVMstatus - The exit code returned by the slave JVM.protected void handleSlaveWontStart(Exception e)
SlaveRemote.start(edu.rice.cs.util.newjvm.MasterRemote).
handleSlaveWontStart in class AbstractMasterJVMe - Exception that occurred during startup.public void systemErrPrint(String s)
systemErrPrint in interface MainJVMRemoteIs - String that was printed in the other JVMpublic void systemOutPrint(String s)
systemOutPrint in interface MainJVMRemoteIs - String that was printed in the other JVMpublic String getConsoleInput()
getConsoleInput in interface MainJVMRemoteI
public void nonTestCase(boolean isTestAll,
boolean didCompileFail)
nonTestCase in interface MainJVMRemoteIisTestAll - whether or not it was a use of the test all buttondidCompileFail - whether or not a compile before this JUnit attempt failedpublic void classFileError(ClassFileError e)
classFileError in interface MainJVMRemoteIe - the ClassFileError describing the error when loading the class filepublic void testSuiteStarted(int numTests)
testSuiteStarted in interface MainJVMRemoteInumTests - The number of tests in the suite to be run.public void testStarted(String testName)
testStarted in interface MainJVMRemoteItestName - The name of the test being started.
public void testEnded(String testName,
boolean wasSuccessful,
boolean causedError)
testEnded in interface MainJVMRemoteItestName - The name of the test that has ended.wasSuccessful - Whether the test passed or not.causedError - If not successful, whether the test caused an error or simply failed.public void testSuiteEnded(JUnitError[] errors)
testSuiteEnded in interface MainJVMRemoteIerrors - The array of errors from all failed tests in the suite.public File getFileForClassName(String className)
getFileForClassName in interface MainJVMRemoteIclassName - the name of the class for which we want to find the file
public void setInteractionsModel(InteractionsModelCallback model)
public void setJUnitModel(JUnitModelCallback model)
public void setDebugModel(DebugModelCallback model)
model - the debug modelpublic void setAllowAssertions(boolean allow)
public void setStartupClassPath(String classPath)
classPath - Class path for the interpreter JVMpublic void setWorkingDirectory(File dir)
protected InterpretResult.Visitor<Void> resultHandler()
public boolean interpret(String s)
true if successful; false if the subprocess is unavailable, the subprocess dies
during the call, or an unexpected exception occurs.public Option<Pair<String,String>> getVariableToString(String var)
var - the name of the variablepublic boolean addProjectClassPath(File f)
true if the change was successfully passed to
the remote JVM.
public boolean addBuildDirectoryClassPath(File f)
true if the change was successfully passed to
the remote JVM.
public boolean addProjectFilesClassPath(File f)
true if the change was successfully passed to
the remote JVM.
public boolean addExternalFilesClassPath(File f)
true if the change was successfully passed to
the remote JVM.
public boolean addExtraClassPath(File f)
true if the change was successfully passed to
the remote JVM.
public Option<Iterable<File>> getClassPath()
public boolean setPackageScope(String packageName)
packageName - Name of the package to enter.
public Option<List<String>> findTestClasses(List<String> classNames,
List<File> files)
classNames - the class names to run in a testfiles - the associated file
public boolean runTestSuite()
false if no test suite is cached, the remote JVM is unavailable, or an error occurs.
public boolean addInterpreter(String name)
false if the remote JVM is unavailable or
if an exception occurs. Blocks until the interpreter is connected.
name - the unique name for the interpreter
IllegalArgumentException - if the name is not uniquepublic boolean removeInterpreter(String name)
false if
the remote JVM is unavailable or if an exception occurs. Blocks until the interpreter is connected.
name - Name of the interpreter to removepublic Option<Pair<Boolean,Boolean>> setActiveInterpreter(String name)
name - the unique name of the interpreter to set active
public Option<Pair<Boolean,Boolean>> setToDefaultInterpreter()
public boolean setEnforceAllAccess(boolean enforce)
false if
the remote JVM is unavailable or if an exception occurs. Blocks until the interpreter is connected.
public boolean setEnforcePrivateAccess(boolean enforce)
false if
the remote JVM is unavailable or if an exception occurs. Blocks until the interpreter is connected.
public boolean setRequireSemicolon(boolean require)
false if
the remote JVM is unavailable or if an exception occurs. Blocks until the interpreter is connected.
public boolean setRequireVariableType(boolean require)
false if
the remote JVM is unavailable or if an exception occurs. Blocks until the interpreter is connected.
private void _doStartup()
private int _getDebugPort()
private void _handleRemoteException(RemoteException e)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||