- java.lang.Object
-
- jdk.jshell.execution.DirectExecutionControl
-
- All Implemented Interfaces:
-
AutoCloseable,ExecutionControl
- 已知直接子类:
-
LocalExecutionControl,RemoteExecutionControl
public class DirectExecutionControl extends Object implements ExecutionControl
在当前进程中运行的一个ExecutionControl实现。 可直接使用,或通过Util.forwardExecutionControl(ExecutionControl, java.io.ObjectInput, java.io.ObjectOutput)通道。- 从以下版本开始:
- 9
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jdk.jshell.spi.ExecutionControl
ExecutionControl.ClassBytecodes, ExecutionControl.ClassInstallException, ExecutionControl.EngineTerminationException, ExecutionControl.ExecutionControlException, ExecutionControl.InternalException, ExecutionControl.NotImplementedException, ExecutionControl.ResolutionException, ExecutionControl.RunException, ExecutionControl.StoppedException, ExecutionControl.UserException
-
-
构造方法摘要
构造方法 Constructor 描述 DirectExecutionControl()使用默认的类加载创建一个实例。DirectExecutionControl(LoaderDelegate loaderDelegate)创建一个实例,将加载器操作委派给指定的委托。
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 voidaddToClasspath(String cp)将路径添加到执行类路径。protected voidclassesRedefined(ExecutionControl.ClassBytecodes[] cbcs)通知类已被重新定义。protected voidclientCodeEnter()标记输入用户代码。protected voidclientCodeLeave()标记离开用户代码。voidclose()关闭这个执行引擎。ObjectextensionCommand(String command, Object arg)运行非标准命令(或较新版本的标准命令)。protected Class<?>findClass(String name)查找具有指定二进制名称的类。protected Stringinvoke(方法 doitMethod)调用指定的“doit-method”,一个没有参数的静态方法。Stringinvoke(String className, String methodName)通过调用指定的包装类上的方法来调用可执行代码段。voidload(ExecutionControl.ClassBytecodes[] cbcs)尝试加载新类。voidredefine(ExecutionControl.ClassBytecodes[] cbcs)尝试重新定义以前加载的类。voidstop()中断一个正在运行的调用。protected StringthrowConvertedInvocationException(Throwable cause)将用户代码中的传入异常转换为ExecutionControl.ExecutionControlException的子类型的实例,并抛出转换的异常。protected StringthrowConvertedOtherException(Throwable ex)将代理代码中的传入异常转换为ExecutionControl.ExecutionControlException的子类型的实例,并抛出转换的异常。protected static StringvalueString(Object value)将Object值从ExecutionControl.invoke(String, String)或ExecutionControl.varValue(String, String)转换为String。StringvarValue(String className, String varName)返回变量的值。-
Methods inherited from interface jdk.jshell.spi.ExecutionControl
generate, generate
-
-
-
-
构造方法详细信息
-
DirectExecutionControl
public DirectExecutionControl(LoaderDelegate loaderDelegate)
创建一个实例,将加载器操作委派给指定的委托。- 参数
-
loaderDelegate- 负责处理加载类的loaderDelegate
-
DirectExecutionControl
public DirectExecutionControl()
使用默认的类加载创建一个实例。
-
-
方法详细信息
-
load
public void load(ExecutionControl.ClassBytecodes[] cbcs) throws ExecutionControl.ClassInstallException, ExecutionControl.NotImplementedException, ExecutionControl.EngineTerminationException
说明从接口ExecutionControl复制尝试加载新类。- Specified by:
-
load在接口ExecutionControl - 参数
-
cbcs- 要加载的类名和字节码 - 异常
-
ExecutionControl.ClassInstallException- 加载类时出现异常,部分或全部未加载 -
ExecutionControl.NotImplementedException- 如果没有实现 -
ExecutionControl.EngineTerminationException- 执行引擎已经终止
-
redefine
public void redefine(ExecutionControl.ClassBytecodes[] cbcs) throws ExecutionControl.ClassInstallException, ExecutionControl.NotImplementedException, ExecutionControl.EngineTerminationException
说明从接口ExecutionControl复制尝试重新定义以前加载的类。- Specified by:
-
redefine在接口ExecutionControl - 参数
-
cbcs- 重新定义的类名和字节码 - 异常
-
ExecutionControl.ClassInstallException- 异常重新定义类,有些或全部没有重新定义 -
ExecutionControl.NotImplementedException- 如果没有实现 -
ExecutionControl.EngineTerminationException- 执行引擎已终止
-
classesRedefined
protected void classesRedefined(ExecutionControl.ClassBytecodes[] cbcs) throws ExecutionControl.NotImplementedException, ExecutionControl.EngineTerminationException
通知类已被重新定义。- 参数
-
cbcs- 重新定义的类名和字节码 - 异常
-
ExecutionControl.NotImplementedException- 如果没有实现 -
ExecutionControl.EngineTerminationException- 执行引擎已经终止
-
invoke
public String invoke(String className, String methodName) throws ExecutionControl.RunException, ExecutionControl.InternalException, ExecutionControl.EngineTerminationException
描述从接口ExecutionControl复制通过调用指定的包装类上的方法来调用可执行代码段。 该方法必须没有参数并返回String。- Specified by:
-
invoke在接口ExecutionControl - 参数
-
className- 应该调用其方法的类 -
methodName- 要调用的方法的名称 - 结果
- 执行的结果或如果没有结果为null
- 异常
-
ExecutionControl.UserException- 调用引发用户异常 -
ExecutionControl.ResolutionException- 调用尝试直接或间接调用未解析的代码段 -
ExecutionControl.StoppedException-如果invoke()被取消ExecutionControl.stop() -
ExecutionControl.InternalException- 发生内部问题 -
ExecutionControl.EngineTerminationException- 执行引擎已终止 -
ExecutionControl.RunException
-
varValue
public String varValue(String className, String varName) throws ExecutionControl.RunException, ExecutionControl.EngineTerminationException, ExecutionControl.InternalException
描述从接口ExecutionControl复制返回变量的值。- Specified by:
-
varValue在接口ExecutionControl - 参数
-
className- 变量的包装类的名称 -
varName- 变量的名称 - 结果
- 变量的值
- 异常
-
ExecutionControl.UserException- 格式化该值引发用户异常 -
ExecutionControl.ResolutionException- 格式化尝试直接或间接调用未解析的代码段的值 -
ExecutionControl.StoppedException- 如果格式化值被ExecutionControl.stop()取消 -
ExecutionControl.EngineTerminationException- 执行引擎已终止 -
ExecutionControl.InternalException- 发生内部问题 -
ExecutionControl.RunException
-
addToClasspath
public void addToClasspath(String cp) throws ExecutionControl.EngineTerminationException, ExecutionControl.InternalException
说明从接口ExecutionControl复制将路径添加到执行类路径。- Specified by:
-
addToClasspath在接口ExecutionControl - 参数
-
cp- 要添加的路径 - 异常
-
ExecutionControl.EngineTerminationException- 执行引擎已经终止 -
ExecutionControl.InternalException- 发生内部问题
-
stop
public void stop() throws ExecutionControl.EngineTerminationException, ExecutionControl.InternalException中断一个正在运行的调用。不支持。
- Specified by:
-
stop在接口ExecutionControl - 异常
-
ExecutionControl.EngineTerminationException- 执行引擎已终止 -
ExecutionControl.InternalException- 发生内部问题
-
extensionCommand
public Object extensionCommand(String command, Object arg) throws ExecutionControl.RunException, ExecutionControl.EngineTerminationException, ExecutionControl.InternalException
描述从接口ExecutionControl复制运行非标准命令(或较新版本的标准命令)。- Specified by:
-
extensionCommand在接口ExecutionControl - 参数
-
command- 非标准命令 -
arg- 命令参数 - 结果
- 命令返回值
- 异常
-
ExecutionControl.UserException- 该命令引发用户异常 -
ExecutionControl.ResolutionException- 该命令尝试直接或间接调用未解析的代码段 -
ExecutionControl.StoppedException- 如果命令被ExecutionControl.stop()取消 -
ExecutionControl.EngineTerminationException- 执行引擎已终止 -
ExecutionControl.NotImplementedException- 如果没有实现 -
ExecutionControl.InternalException- 发生内部问题 -
ExecutionControl.RunException
-
close
public void close()
描述从接口ExecutionControl复制关闭这个执行引擎。 实现应该释放此执行引擎所持有的所有资源。关闭后,不要在此界面上调用方法。
- Specified by:
-
close在接口AutoCloseable - Specified by:
-
close在接口ExecutionControl
-
findClass
protected Class<?> findClass(String name) throws ClassNotFoundException
查找具有指定二进制名称的类。- 参数
-
name- 类的二进制名称 - 结果
- 类对象
- 异常
-
ClassNotFoundException- 如果找不到该类
-
invoke
protected String invoke(方法 doitMethod) throws 异常
调用指定的“doit-method”,一个没有参数的静态方法。 这个类中的invoke(java.lang.String, java.lang.String)会调用这个来调用。- 参数
-
doitMethod- 调用的方法 - 结果
- 该值或null
- 异常
-
异常- 由Method.invoke(Object, Object...)或任何ExecutionControl.ExecutionControlException抛出的任何异常传递。
-
valueString
protected static String valueString(Object value)
将Object价值从ExecutionControl.invoke(String, String)或ExecutionControl.varValue(String, String)转为String。- 参数
-
value- 要转换的值 - 结果
-
代表
String
-
throwConvertedInvocationException
protected String throwConvertedInvocationException(Throwable cause) throws ExecutionControl.RunException, ExecutionControl.InternalException
将用户代码中的传入异常转换为ExecutionControl.ExecutionControlException子类型的实例,并抛出转换的异常。- 参数
-
cause- 转换的例外 - 结果
- 永远不会回报,因为它总是抛出
- 异常
-
ExecutionControl.RunException- 用于正常的异常事件 -
ExecutionControl.InternalException- 内部问题
-
throwConvertedOtherException
protected String throwConvertedOtherException(Throwable ex) throws ExecutionControl.RunException, ExecutionControl.InternalException
将代理代码中的传入异常转换为ExecutionControl.ExecutionControlException子类型的实例,并抛出转换的异常。- 参数
-
ex- 转换的例外 - 结果
- 永远不会回报,因为它总是抛出
- 异常
-
ExecutionControl.RunException- 正常的异常事件 -
ExecutionControl.InternalException- 内部问题
-
clientCodeEnter
protected void clientCodeEnter() throws ExecutionControl.InternalException标记输入用户代码。- 异常
-
ExecutionControl.InternalException- 出现意外故障的情况
-
clientCodeLeave
protected void clientCodeLeave() throws ExecutionControl.InternalException标记离开用户代码。- 异常
-
ExecutionControl.InternalException- 在意外的故障案例中
-
-