-
public interface VirtualMachineManager目标虚拟机的连接经理。 VirtualMachineManager允许一个应用程序调试多个目标虚拟机。 (请注意,不支持相反;目标VM只能由一个调试器应用程序进行调试。)此接口包含管理与远程目标VM的连接的方法,并获取可用目标VM的VirtualMachine镜像。可以使用几个不同的
Connector对象之一进行连接。 每个连接器封装了将调试器与目标VM连接的不同方式。VirtualMachineManager支持将调试器连接到虚拟机的许多不同方案。 下表列出了四个例子。 这些示例在Sun的实现中使用命令行语法。 一些
Four scenarios for connecting a debugger to a virtual machine" Scenario Description Debugger launches target VM (simplest, most-common scenario) Debugger calls theConnector实现可能需要略微不同的处理,如下所示。LaunchingConnector.launch(java.util.Map)method of the default connector, obtained withdefaultConnector(). The target VM is launched, and a connection between that VM and the debugger is established. AVirtualMachinemirror is returned.Or, for more control
- Debugger selects a connector from the list returned by
launchingConnectors()with desired characteristics (for example, transport type, etc.). - Debugger calls the
LaunchingConnector.launch(java.util.Map)method of the selected connector. The target VM is launched, and a connection between that VM and the debugger is established. AVirtualMachinemirror is returned.
- Target VM is launched using the options
-agentlib:jdwp=transport=xxx,server=y - Target VM generates and outputs the tranport-specific address at which it will listen for a connection.
- Debugger is launched. Debugger selects a connector in the list returned by
attachingConnectors()matching the transport with the name "xxx". - Debugger presents the default connector parameters (obtained through
Connector.defaultArguments()) to the end user, allowing the user to fill in the transport-specific address generated by the target VM. - Debugger calls the
AttachingConnector.attach(java.util.Map)method of the selected to attach to the target VM. AVirtualMachinemirror is returned.
- At startup, debugger selects one or more connectors from the list returned by
listeningConnectors()for one or more transports. - Debugger calls the
ListeningConnector.startListening(java.util.Map)method for each selected connector. For each call, a transport-specific address string is generated and returned. The debugger makes the transport names and corresponding address strings available to the end user. - Debugger calls
ListeningConnector.accept(java.util.Map)for each selected connector to wait for a target VM to connect. - Later, target VM is launched by end user with the options
-agentlib:jdwp=transport=xxx,address=yyywhere "xxx" the transport for one of the connectors selected by the the debugger and "yyy" is the address generated byListeningConnector.accept(java.util.Map)for that transport. - Debugger's call to
ListeningConnector.accept(java.util.Map)returns aVirtualMachinemirror.
- Target VM is launched with the options
-agentlib:jdwp=launch=cmdline,onuncaught=y,transport=xxx,server=y - Later, an uncaught exception is thrown in the target VM. The target VM generates the tranport-specific address at which it will listen for a connection.
- Target VM launches the debugger with the following items concatenated together (separated by spaces) to form the command line:
- The launch= value
- The transport= value
- The generated transport-specific address at which VM is listening for debugger connection.
- Upon launch, debugger selects a connector in the list returned by
attachingConnectors()matching the transport with the name "xxx". - Debugger changes the default connector parameters (obtained through
Connector.defaultArguments()) to specify the transport specific address at which the VM is listenig. Optionally, other connector arguments can be presented to the user. - Debugger calls the
AttachingConnector.attach(java.util.Map)method of the selected to attach to the target VM. AVirtualMachinemirror is returned.
连接器在启动时创建。 也就是说,它们是在第一次调用
Bootstrap.virtualMachineManager()时创建的。 可以通过调用allConnectors方法从VirtualMachineManager获取在启动时创建的所有连接器的列表。连接器在启动时创建,如果它们安装在平台上。 此外,由VirtualMachineManager自动创建连接器以封装平台上安装的任何
TransportService实现。 这两种机制用于创建连接器。如果连接器安装在
Connector类型的定义类加载器中可见的jar文件中,并且该jar文件包含资源目录META-INF/services名为com.sun.jdi.connect.Connector的提供程序配置文件,以及提供程序配置文件列出Connector实现的全限定类名。 连接器是实现Connector接口的类。 更适当地该类实现的特定连接器类型中的一种,即AttachingConnector,ListeningConnector,或LaunchingConnector。 提供程序配置文件的格式是每行一个完全限定的类名。 每个类周围的空格和制表符字符以及空白行都被忽略。 注释字符为'#'(0x23),并且在每行上,忽略第一个注释字符之后的所有字符。 文件必须以UTF-8编码。在启动时,VirtualMachineManager将尝试加载和实例化(使用无参数构造函数)提供程序配置文件中列出的每个类。 加载或创建连接器时抛出的异常被捕获并被忽略。 换句话说,即使发生错误,启动过程仍然继续。
除了安装在平台上的连接器之外,VirtualMachineManager还将创建连接器来封装平台上安装的任何
TransportService实现。 如果安装在适用于TransportService类型的定义类加载器的jar文件中,则该平台上将安装TransportService ,该jar文件包含资源目录META-INF/services名为com.sun.jdi.connect.spi.TransportService的提供程序配置文件,并且提供程序配置文件列表TransportService实施的全限定类名。 TransportService是TransportService的具体子类。 提供程序配置文件的格式与“连接器”的提供程序配置文件相同,除了列出的每个类都必须是实现TransportService接口的类的完全限定类名称。对于安装在平台上的每个TransportService,VirtualMachineManager将创建相应的
AttachingConnector和ListeningConnector。 这些连接器被创建来封装一个Transport,这又封装了TransportService。Attach将根据连接字符串Attach的传输服务的名称进行命名。 例如,如果传输服务name()方法返回telepathic则telepathic将被命名为telepathicAttach。 类似的ListeningConnector将被命名为Listen标记到传输服务名称的字符串。 AttachedConnector和ListeningConnector的description()方法将委托给基础传输服务的description()方法。 AttachedConnector和ListeningConnector都将有两个连接器Arguments。 一个StringArgument命名为address是连接参数指定的地址过于重视,还是要听的。 甲IntegerArgument命名timeout是该连接器的参数时附接,或接受来指定超时。 根据传输服务是否支持附加超时或接受超时,超时连接器可能会被忽略。虚拟机管理器的初始化将失败,如果虚拟机管理器无法创建任何连接器,则将发生错误
Bootstrap.virtualMachineManager()。- 从以下版本开始:
- 1.3
- Debugger selects a connector from the list returned by
-
-
方法摘要
所有方法 接口方法 抽象方法 Modifier and Type 方法 描述 List<Connector>allConnectors()返回所有已知的Connector对象的列表。List<AttachingConnector>attachingConnectors()返回已知的AttachingConnector对象的列表。List<VirtualMachine>connectedVirtualMachines()列出连接到调试器的所有目标虚拟机。VirtualMachinecreateVirtualMachine(Connection connection)创建一个新的虚拟机。VirtualMachinecreateVirtualMachine(Connection connection, Process process)为目标虚拟机创建虚拟机镜像。LaunchingConnectordefaultConnector()标识默认连接器。List<LaunchingConnector>launchingConnectors()返回已知的LaunchingConnector对象的列表。List<ListeningConnector>listeningConnectors()返回已知的ListeningConnector对象的列表。intmajorInterfaceVersion()返回JDI界面的主版本号。intminorInterfaceVersion()返回JDI接口的次要版本号。
-
-
-
方法详细信息
-
defaultConnector
LaunchingConnector defaultConnector()
标识默认连接器。 当不需要选择具有特定特性的连接器时,该连接器应用作发射连接器。- 结果
-
默认为
LaunchingConnector
-
launchingConnectors
List<LaunchingConnector> launchingConnectors()
返回已知的LaunchingConnector对象的列表。 任何返回的对象都可用于启动新的目标VM,并立即为其创建一个VirtualMachine镜像。 请注意,启动连接器启动的目标虚拟机不能保证稳定,直到接收到VMStartEvent。- 结果
-
LaunchingConnector对象的列表。
-
attachingConnectors
List<AttachingConnector> attachingConnectors()
返回已知的AttachingConnector对象的列表。 任何返回的对象都可以用于附加到现有的目标VM并为其创建一个VirtualMachine镜像。- 结果
-
一个
AttachingConnector对象的列表。
-
listeningConnectors
List<ListeningConnector> listeningConnectors()
返回已知的ListeningConnector对象的列表。 任何返回的对象都可用于侦听由目标VM发起的连接,并为其创建一个VirtualMachine镜像。- 结果
-
一个
ListeningConnector个对象的列表。
-
allConnectors
List<Connector> allConnectors()
返回所有已知的Connector对象的列表。- 结果
-
一个
Connector个对象的列表。
-
connectedVirtualMachines
List<VirtualMachine> connectedVirtualMachines()
列出连接到调试器的所有目标虚拟机。 该列表包括发起连接的任何目标虚拟机的VirtualMachine实例以及此管理器已启动连接的任何目标虚拟机。 目标VM将保留在此列表中,直到VM断开连接。 在将VM从列表中删除后,将将VMDisconnectEvent置于事件队列中。- 结果
-
一个
VirtualMachine个对象的列表,每个镜像一个目标虚拟机。
-
majorInterfaceVersion
int majorInterfaceVersion()
返回JDI界面的主版本号。 请参阅VirtualMachine.version()目标VM版本和信息以及VirtualMachine.description()更多版本信息。- 结果
- 整数主版本号。
-
minorInterfaceVersion
int minorInterfaceVersion()
返回JDI接口的次要版本号。 请参阅VirtualMachine.version()目标VM版本和信息以及VirtualMachine.description()更多版本信息。- 结果
- 整数小版本号
-
createVirtualMachine
VirtualMachine createVirtualMachine(Connection connection, Process process) throws IOException
为目标虚拟机创建虚拟机镜像。为已存在
Connection的目标虚拟机创建虚拟机镜像。 当Connector建立连接并与目标VM成功握手时,将创建连接。 然后,连接器可以使用此方法创建虚拟机镜像来表示目标VM的复合状态。process参数指定标签虚拟机的Process对象。 可以指定为null。 如果目标虚拟机由LaunchingConnector启动,则应指定process参数,否则,在创建的虚拟机上调用VirtualMachine.process()将返回null。存在此方法,以便连接器可以在建立与目标VM的连接时创建虚拟机镜像。 只有开发新的Connector实现的开发者才需要直接使用这种方法。
- 参数
-
connection- 与目标虚拟机的打开连接。 -
process- 如果启动, 则为目标VM的Process对象。null如果没有启动。 - 结果
- 代表目标虚拟机的新虚拟机。
- 异常
-
IOException- 如果发生I / O错误 -
IllegalStateException- 如果连接未打开 - 从以下版本开始:
- 1.5
- 另请参见:
-
Connection.isOpen(),VirtualMachine.process()
-
createVirtualMachine
VirtualMachine createVirtualMachine(Connection connection) throws IOException
创建一个新的虚拟机。这种方便的方法就像调用
createVirtualMachine(Connection, Process)方法一样,并指定null作为process参数。存在此方法,以便连接器可以在建立与目标VM的连接时创建虚拟机镜像。 只有开发新的Connector实现的开发者才需要直接使用这种方法。
- 结果
- 新的虚拟机
- 异常
-
IOException- 如果发生I / O错误 -
IllegalStateException- 如果连接未打开 - 从以下版本开始:
- 1.5
-
-