Java Code Examples for com.sun.jdi.VirtualMachineManager#attachingConnectors()
The following examples show how to use
com.sun.jdi.VirtualMachineManager#attachingConnectors() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DebugUtility.java From java-debug with Eclipse Public License 1.0 | 6 votes |
/** * Attach to an existing debuggee VM. * @param vmManager * the virtual machine manager * @param hostName * the machine where the debuggee VM is launched on * @param port * the debug port that the debuggee VM exposed * @param attachTimeout * the timeout when attaching to the debuggee VM * @return an instance of IDebugSession * @throws IOException * when unable to attach. * @throws IllegalConnectorArgumentsException * when one of the connector arguments is invalid. */ public static IDebugSession attach(VirtualMachineManager vmManager, String hostName, int port, int attachTimeout) throws IOException, IllegalConnectorArgumentsException { List<AttachingConnector> connectors = vmManager.attachingConnectors(); AttachingConnector connector = connectors.get(0); // in JDK 10, the first AttachingConnector is not the one we want final String SUN_ATTACH_CONNECTOR = "com.sun.tools.jdi.SocketAttachingConnector"; for (AttachingConnector con : connectors) { if (con.getClass().getName().equals(SUN_ATTACH_CONNECTOR)) { connector = con; break; } } Map<String, Argument> arguments = connector.defaultArguments(); arguments.get(HOSTNAME).setValue(hostName); arguments.get(PORT).setValue(String.valueOf(port)); arguments.get(TIMEOUT).setValue(String.valueOf(attachTimeout)); return new DebugSession(connector.attach(arguments)); }
Example 2
Source File: JPDASupport.java From netbeans with Apache License 2.0 | 5 votes |
public static JPDASupport attach (String mainClass, String[] args, File[] classPath) throws IOException, DebuggerStartException { Process process = launchVM (mainClass, args, classPath, "", true); String line = readLine (process.getInputStream ()); int port = Integer.parseInt (line.substring (line.lastIndexOf (':') + 1).trim ()); ProcessIO pio = new ProcessIO (process); pio.go (); VirtualMachineManager vmm = Bootstrap.virtualMachineManager(); List aconnectors = vmm.attachingConnectors(); AttachingConnector connector = null; for (Iterator i = aconnectors.iterator(); i.hasNext();) { AttachingConnector ac = (AttachingConnector) i.next(); Transport t = ac.transport (); if (t != null && t.name().equals("dt_socket")) { connector = ac; break; } } if (connector == null) throw new RuntimeException ("No attaching socket connector available"); JPDADebugger jpdaDebugger = JPDADebugger.attach ( "localhost", port, createServices () ); return new JPDASupport (jpdaDebugger); }
Example 3
Source File: VMAcquirer.java From nopol with GNU General Public License v2.0 | 5 votes |
private AttachingConnector getConnector() { VirtualMachineManager vmManager = Bootstrap.virtualMachineManager(); for (Connector connector : vmManager.attachingConnectors()) { if ("com.sun.jdi.SocketAttach".equals(connector.name())) { return (AttachingConnector) connector; } } throw new IllegalStateException(); }
Example 4
Source File: JDIRedefiner.java From HotswapAgent with GNU General Public License v2.0 | 5 votes |
private VirtualMachine connect(int port) throws IOException { VirtualMachineManager manager = Bootstrap.virtualMachineManager(); // Find appropiate connector List<AttachingConnector> connectors = manager.attachingConnectors(); AttachingConnector chosenConnector = null; for (AttachingConnector c : connectors) { if (c.transport().name().equals(TRANSPORT_NAME)) { chosenConnector = c; break; } } if (chosenConnector == null) { throw new IllegalStateException("Could not find socket connector"); } // Set port argument AttachingConnector connector = chosenConnector; Map<String, Argument> defaults = connector.defaultArguments(); Argument arg = defaults.get(PORT_ARGUMENT_NAME); if (arg == null) { throw new IllegalStateException("Could not find port argument"); } arg.setValue(Integer.toString(port)); // Attach try { System.out.println("Connector arguments: " + defaults); return connector.attach(defaults); } catch (IllegalConnectorArgumentsException e) { throw new IllegalArgumentException("Illegal connector arguments", e); } }
Example 5
Source File: VMAcquirer.java From gravel with Apache License 2.0 | 5 votes |
private AttachingConnector getConnector() { VirtualMachineManager vmManager = Bootstrap .virtualMachineManager(); for (AttachingConnector connector : vmManager .attachingConnectors()) { if ("com.sun.jdi.SocketAttach".equals(connector .name())) { return (AttachingConnector) connector; } } throw new IllegalStateException(); }