com.sun.jdi.connect.AttachingConnector Java Examples

The following examples show how to use com.sun.jdi.connect.AttachingConnector. 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: ProcessAttachTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void tryDebug(long pid) throws IOException,
        IllegalConnectorArgumentsException {
    AttachingConnector ac = Bootstrap.virtualMachineManager().attachingConnectors()
            .stream()
            .filter(c -> c.name().equals("com.sun.jdi.ProcessAttach"))
            .findFirst()
            .orElseThrow(() -> new RuntimeException("Unable to locate ProcessAttachingConnector"));

    Map<String, Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument) args
            .get("pid");
    arg.setValue("" + pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");
    VirtualMachine vm = ac.attach(args);

    // list all threads
    System.out.println("Attached! Now listing threads ...");
    vm.allThreads().stream().forEach(System.out::println);

    System.out.println("Debugger done.");
    vm.dispose();
}
 
Example #2
Source File: HotSwapper.java    From HotswapAgent with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Connects to the JVM.
 *
 * @param port	the port number used for the connection to the JVM.
 */
public HotSwapper(String port)
    throws IOException, IllegalConnectorArgumentsException
{
    jvm = null;
    request = null;
    newClassFiles = null;
    trigger = new Trigger();
    AttachingConnector connector
        = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");

    Map<String,Connector.Argument> arguments = connector.defaultArguments();
    arguments.get("hostname").setValue(HOST_NAME);
    arguments.get("port").setValue(port);
    jvm = connector.attach(arguments);
    EventRequestManager manager = jvm.eventRequestManager();
    request = methodEntryRequests(manager, TRIGGER_NAME);
}
 
Example #3
Source File: HotSwapperJpda.java    From HotswapAgent with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Connects to the JVM.
 *
 * @param port the port number used for the connection to the JVM.
 */
public HotSwapperJpda(String port)
        throws IOException, IllegalConnectorArgumentsException {
    jvm = null;
    request = null;
    newClassFiles = null;
    trigger = new Trigger();
    AttachingConnector connector
        = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");

    Map<String,Connector.Argument> arguments = connector.defaultArguments();
    arguments.get("hostname").setValue(HOST_NAME);
    arguments.get("port").setValue(port);
    jvm = connector.attach(arguments);
    EventRequestManager manager = jvm.eventRequestManager();
    request = methodEntryRequests(manager, TRIGGER_NAME);
}
 
Example #4
Source File: DebugUtility.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #5
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Map<String,? extends Argument> getArgs (
    AttachingConnector attachingConnector,
    String name
) {
    Map<String,? extends Argument> args = attachingConnector.defaultArguments ();
    args.get ("name").setValue (name);
    return args;
}
 
Example #6
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Map<String,? extends Argument> getArgs (
    AttachingConnector attachingConnector,
    String hostName,
    int portNumber
) {
    Map<String,? extends Argument> args = attachingConnector.defaultArguments ();
    args.get ("hostname").setValue (hostName);
    args.get ("port").setValue ("" + portNumber);
    return args;
}
 
Example #7
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static AttachingConnector findAttachingConnector (String s) {
    Iterator<AttachingConnector> iter = Bootstrap.virtualMachineManager ().
        attachingConnectors ().iterator ();
    while (iter.hasNext ()) {
        AttachingConnector ac = iter.next ();
        if (ac.transport() != null && ac.transport ().name ().toLowerCase ().indexOf (s) > -1)
            return ac;
    }
    return null;
}
 
Example #8
Source File: ProcessAttachDebugger.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #9
Source File: ProcessAttachDebugger.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #10
Source File: VMAcquirer.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine connect(AttachingConnector connector, String port)
        throws IllegalConnectorArgumentsException,
        IOException {
    Map<String, Connector.Argument> args = connector.defaultArguments();
    Connector.Argument pidArgument = args.get("port");
    args.get("hostname").setValue("localhost");
    if (pidArgument == null) {
        throw new IllegalStateException();
    }
    pidArgument.setValue(port);

    return connector.attach(args);
}
 
Example #11
Source File: VMAcquirer.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
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 #12
Source File: VMAcquirer.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Call this with the localhost port to connect to.
 */
public VirtualMachine connect(int port)
        throws IOException {
    String strPort = Integer.toString(port);
    AttachingConnector connector = getConnector();
    try {
        return connect(connector, strPort);
    } catch (IllegalConnectorArgumentsException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #13
Source File: ProcessAttachDebugger.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #14
Source File: ProcessAttachDebugger.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #15
Source File: ProcessAttachDebugger.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #16
Source File: ExclusiveBind.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the first debuggee
    Process process1 = launch(address, true, "HelloWorld");

    // give first debuggee time to suspend
    Thread.currentThread().sleep(5000);

    // launch a second debuggee with the same address
    Process process2 = launch(address, false, "HelloWorld");

    // get exit status from second debuggee
    int exitCode = process2.waitFor();

    // clean-up - attach to first debuggee and resume it
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);
    vm.resume();

    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
 
Example #17
Source File: ProcessAttachDebugger.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #18
Source File: ProcessAttachDebugger.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #19
Source File: ExclusiveBind.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the first debuggee
    Process process1 = launch(address, true, "HelloWorld");

    // give first debuggee time to suspend
    Thread.currentThread().sleep(5000);

    // launch a second debuggee with the same address
    Process process2 = launch(address, false, "HelloWorld");

    // get exit status from second debuggee
    int exitCode = process2.waitFor();

    // clean-up - attach to first debuggee and resume it
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);
    vm.resume();

    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
 
Example #20
Source File: JdiUtils.java    From java-svc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static AttachingConnector getSocketConnector() {
	for (AttachingConnector connector : Bootstrap.virtualMachineManager().attachingConnectors()) {
		if (connector.name().equals("com.sun.jdi.SocketAttach")) {
			return connector;
		}
	}
	return null;
}
 
Example #21
Source File: VMAcquirer.java    From gravel with Apache License 2.0 5 votes vote down vote up
private VirtualMachine connect(
    AttachingConnector connector, String port)
    throws IllegalConnectorArgumentsException,
    IOException {
  Map<String, AttachingConnector.Argument> args = connector
      .defaultArguments();
  AttachingConnector.Argument pidArgument = args.get("port");
  if (pidArgument == null) {
    throw new IllegalStateException();
  }
  pidArgument.setValue(port);

  return connector.attach(args);
}
 
Example #22
Source File: ProcessAttachDebugger.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #23
Source File: VMAcquirer.java    From gravel with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #24
Source File: VMAcquirer.java    From gravel with Apache License 2.0 5 votes vote down vote up
/**
 * Call this with the localhost port to connect to.
 */
public VirtualMachine connect(int port)
    throws IOException {
  String strPort = Integer.toString(port);
  AttachingConnector connector = getConnector();
  try {
    VirtualMachine vm = connect(connector, strPort);
    return vm;
  } catch (IllegalConnectorArgumentsException e) {
    throw new IllegalStateException(e);
  }
}
 
Example #25
Source File: ProcessAttachDebugger.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #26
Source File: LaunchUtilities.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
    * Returns the default 'com.sun.jdi.SocketAttach' connector.
    *
    * @return the {@link AttachingConnector}
    */
public static AttachingConnector getAttachingConnector() {
       List<?> connectors = Bootstrap.virtualMachineManager().attachingConnectors();
       for (int i = 0; i < connectors.size(); i++) {
           AttachingConnector c = (AttachingConnector) connectors.get(i);
           if ("com.sun.jdi.SocketAttach".equals(c.name())) { //$NON-NLS-1$
			return c;
		}
       }

       return null;
   }
 
Example #27
Source File: ProcessAttachDebugger.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #28
Source File: JDIRedefiner.java    From HotswapAgent with GNU General Public License v2.0 5 votes vote down vote up
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 #29
Source File: HelloWorld.java    From java-svc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static VirtualMachine connect(String host, String port)
		throws IOException, IllegalConnectorArgumentsException {
	AttachingConnector socketConnector = getSocketConnector();
	Map<String, Argument> arguments = socketConnector.defaultArguments();
	arguments.get("hostname").setValue(host);
	((IntegerArgument) arguments.get("port")).setValue(Integer.parseInt(port));
	return socketConnector.attach(arguments);
}
 
Example #30
Source File: HelloWorld.java    From java-svc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static AttachingConnector getSocketConnector() {
	for (AttachingConnector connector : Bootstrap.virtualMachineManager().attachingConnectors()) {
		if (connector.name().equals("com.sun.jdi.SocketAttach")) {
			return connector;
		}
	}
	return null;
}