- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DirectExecutionControl,JdiDefaultExecutionControl,JdiExecutionControl,LocalExecutionControl,RemoteExecutionControl,StreamingExecutionControl
public interface ExecutionControl extends AutoCloseable
This interface specifies the functionality that must provided to implement a
pluggable JShell execution engine.
The audience for this Service Provider Interface is engineers wishing to implement their own version of the execution engine in support of the JShell API.
A Snippet is compiled into code wrapped in a 'wrapper class'. The execution engine is used by the core JShell implementation to load and, for executable Snippets, execute the Snippet.
Methods defined in this interface should only be called by the core JShell implementation.
- Since:
- 9
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classExecutionControl.ClassBytecodesBundles class name with class bytecodes.static classExecutionControl.ClassInstallExceptionA class install (load or redefine) encountered a problem.static classExecutionControl.EngineTerminationExceptionUnbidden execution engine termination has occurred.static classExecutionControl.ExecutionControlExceptionThe abstract base of allExecutionControlexceptions.static classExecutionControl.InternalExceptionAn internal problem has occurred.static classExecutionControl.NotImplementedExceptionThe command is not implemented.static classExecutionControl.ResolutionExceptionAn exception indicating that aDeclarationSnippetwith unresolved references has been encountered.static classExecutionControl.RunExceptionThe abstract base of of exceptions specific to running user code.static classExecutionControl.StoppedExceptionAn exception indicating that aninvoke(java.lang.String, java.lang.String)(or theoretically avarValue(java.lang.String, java.lang.String)) has been interrupted by astop().static classExecutionControl.UserExceptionA 'normal' user exception occurred. -
Method Summary
Modifier and Type Method Description voidaddToClasspath(String path)Adds the path to the execution class path.voidclose()Shuts down this execution engine.ObjectextensionCommand(String command, Object arg)Run a non-standard command (or a standard command from a newer version).static ExecutionControlgenerate(ExecutionEnv env, String spec)Search for a provider, then create and return theExecutionControlinstance.static ExecutionControlgenerate(ExecutionEnv env, String name, Map<String,String> parameters)Search for a provider, then create and return theExecutionControlinstance.Stringinvoke(String className, String methodName)Invokes an executable Snippet by calling a method on the specified wrapper class.voidload(ExecutionControl.ClassBytecodes[] cbcs)Attempts to load new classes.voidredefine(ExecutionControl.ClassBytecodes[] cbcs)Attempts to redefine previously loaded classes.voidstop()Interrupts a running invoke.StringvarValue(String className, String varName)Returns the value of a variable.
-
Method Details
-
load
void load(ExecutionControl.ClassBytecodes[] cbcs) throws ExecutionControl.ClassInstallException, ExecutionControl.NotImplementedException, ExecutionControl.EngineTerminationExceptionAttempts to load new classes.- Parameters:
cbcs- the class name and bytecodes to load- Throws:
ExecutionControl.ClassInstallException- exception occurred loading the classes, some or all were not loadedExecutionControl.NotImplementedException- if not implementedExecutionControl.EngineTerminationException- the execution engine has terminated
-
redefine
void redefine(ExecutionControl.ClassBytecodes[] cbcs) throws ExecutionControl.ClassInstallException, ExecutionControl.NotImplementedException, ExecutionControl.EngineTerminationExceptionAttempts to redefine previously loaded classes.- Parameters:
cbcs- the class name and bytecodes to redefine- Throws:
ExecutionControl.ClassInstallException- exception occurred redefining the classes, some or all were not redefinedExecutionControl.NotImplementedException- if not implementedExecutionControl.EngineTerminationException- the execution engine has terminated
-
invoke
String invoke(String className, String methodName) throws ExecutionControl.RunException, ExecutionControl.EngineTerminationException, ExecutionControl.InternalExceptionInvokes an executable Snippet by calling a method on the specified wrapper class. The method must have no arguments and return String.- Parameters:
className- the class whose method should be invokedmethodName- the name of method to invoke- Returns:
- the result of the execution or null if no result
- Throws:
ExecutionControl.UserException- the invoke raised a user exceptionExecutionControl.ResolutionException- the invoke attempted to directly or indirectly invoke an unresolved snippetExecutionControl.StoppedException- if theinvoke()was canceled bystop()ExecutionControl.EngineTerminationException- the execution engine has terminatedExecutionControl.InternalException- an internal problem occurredExecutionControl.RunException
-
varValue
String varValue(String className, String varName) throws ExecutionControl.RunException, ExecutionControl.EngineTerminationException, ExecutionControl.InternalExceptionReturns the value of a variable.- Parameters:
className- the name of the wrapper class of the variablevarName- the name of the variable- Returns:
- the value of the variable
- Throws:
ExecutionControl.UserException- formatting the value raised a user exceptionExecutionControl.ResolutionException- formatting the value attempted to directly or indirectly invoke an unresolved snippetExecutionControl.StoppedException- if the formatting the value was canceled bystop()ExecutionControl.EngineTerminationException- the execution engine has terminatedExecutionControl.InternalException- an internal problem occurredExecutionControl.RunException
-
addToClasspath
void addToClasspath(String path) throws ExecutionControl.EngineTerminationException, ExecutionControl.InternalExceptionAdds the path to the execution class path.- Parameters:
path- the path to add- Throws:
ExecutionControl.EngineTerminationException- the execution engine has terminatedExecutionControl.InternalException- an internal problem occurred
-
stop
Interrupts a running invoke.- Throws:
ExecutionControl.EngineTerminationException- the execution engine has terminatedExecutionControl.InternalException- an internal problem occurred
-
extensionCommand
Object extensionCommand(String command, Object arg) throws ExecutionControl.RunException, ExecutionControl.EngineTerminationException, ExecutionControl.InternalExceptionRun a non-standard command (or a standard command from a newer version).- Parameters:
command- the non-standard commandarg- the commands argument- Returns:
- the commands return value
- Throws:
ExecutionControl.UserException- the command raised a user exceptionExecutionControl.ResolutionException- the command attempted to directly or indirectly invoke an unresolved snippetExecutionControl.StoppedException- if the command was canceled bystop()ExecutionControl.EngineTerminationException- the execution engine has terminatedExecutionControl.NotImplementedException- if not implementedExecutionControl.InternalException- an internal problem occurredExecutionControl.RunException
-
close
void close()Shuts down this execution engine. Implementation should free all resources held by this execution engine.No calls to methods on this interface should be made after close.
- Specified by:
closein interfaceAutoCloseable
-
generate
static ExecutionControl generate(ExecutionEnv env, String name, Map<String,String> parameters) throws ThrowableSearch for a provider, then create and return theExecutionControlinstance.- Parameters:
env- the execution environment (provided by JShell)name- the name of providerparameters- the parameter map.- Returns:
- the execution engine
- Throws:
Throwable- an exception that occurred attempting to find or create the execution engine.IllegalArgumentException- if no ExecutionControlProvider has the specifiednameandparameters.
-
generate
Search for a provider, then create and return theExecutionControlinstance.- Parameters:
env- the execution environment (provided by JShell)spec- theExecutionControlspec, which is described in the documentation of this package documentation.- Returns:
- the execution engine
- Throws:
Throwable- an exception that occurred attempting to find or create the execution engine.IllegalArgumentException- if no ExecutionControlProvider has the specifiednameandparameters.IllegalArgumentException- ifspecis malformed
-