use of com.sun.jdi.connect.Connector.Argument in project HotswapAgent by HotswapProjects.
the class JDIRedefiner method connect.
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);
}
}
use of com.sun.jdi.connect.Connector.Argument in project ceylon by eclipse.
the class TracerImpl method start.
public void start() throws Exception {
VirtualMachineManager vmm = com.sun.jdi.Bootstrap.virtualMachineManager();
LaunchingConnector conn = vmm.defaultConnector();
Map<String, Argument> defaultArguments = conn.defaultArguments();
defaultArguments.get("main").setValue(mainClass);
defaultArguments.get("options").setValue("-cp " + classPath);
System.out.println(defaultArguments);
vm = conn.launch(defaultArguments);
err = vm.process().getErrorStream();
out = vm.process().getInputStream();
eq = vm.eventQueue();
rm = vm.eventRequestManager();
outer: while (true) {
echo(err, System.err);
echo(out, System.out);
events = eq.remove();
for (Event event : events) {
if (event instanceof VMStartEvent) {
System.out.println(event);
break outer;
} else if (event instanceof VMDisconnectEvent || event instanceof VMDeathEvent) {
System.out.println(event);
vm = null;
rm = null;
eq = null;
break outer;
}
}
events.resume();
}
echo(err, System.err);
echo(out, System.out);
}
use of com.sun.jdi.connect.Connector.Argument in project processing by processing.
the class Runner method launchVirtualMachine.
public boolean launchVirtualMachine(boolean present, String[] args) {
StringList vmParams = getMachineParams();
StringList sketchParams = getSketchParams(present, args);
// PApplet.printArray(sketchParams);
int port = 8000 + (int) (Math.random() * 1000);
String portStr = String.valueOf(port);
// Added 'quiet=y' for 3.0.2 to prevent command line parsing problems
// https://github.com/processing/processing/issues/4098
String jdwpArg = "-agentlib:jdwp=transport=dt_socket,address=" + portStr + ",server=y,suspend=y,quiet=y";
// Everyone works the same under Java 7 (also on OS X)
StringList commandArgs = new StringList();
commandArgs.append(Platform.getJavaPath());
commandArgs.append(jdwpArg);
commandArgs.append(vmParams);
commandArgs.append(sketchParams);
// the next chance to cancel will be after connecting to the VM
if (cancelled) {
return false;
}
launchJava(commandArgs.array());
AttachingConnector connector = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach");
//PApplet.println(connector); // gets the defaults
Map<String, Argument> arguments = connector.defaultArguments();
// Connector.Argument addressArg =
// (Connector.Argument)arguments.get("address");
// addressArg.setValue(addr);
Connector.Argument portArg = arguments.get("port");
portArg.setValue(portStr);
try {
// while (!available) {
while (true) {
try {
Messages.log(getClass().getName() + " attempting to attach to VM");
synchronized (cancelLock) {
vm = connector.attach(arguments);
if (cancelled && vm != null) {
// cancelled and connected to the VM, handle closing now
Messages.log(getClass().getName() + " aborting, launch cancelled");
close();
return false;
}
}
// vm = connector.attach(arguments);
if (vm != null) {
Messages.log(getClass().getName() + " attached to the VM");
// available = true;
return true;
}
} catch (ConnectException ce) {
// This will fire ConnectException (socket not available) until
// the VM finishes starting up and opens its socket for us.
Messages.log(getClass().getName() + " socket for VM not ready");
// e.printStackTrace();
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
Messages.loge(getClass().getName() + " interrupted", ie);
// ie.printStackTrace(sketchErr);
}
} catch (IOException e) {
Messages.loge(getClass().getName() + " while attaching to VM", e);
}
}
// } catch (IOException exc) {
// throw new Error("Unable to launch target VM: " + exc);
} catch (IllegalConnectorArgumentsException exc) {
throw new Error("Internal error: " + exc);
}
}
use of com.sun.jdi.connect.Connector.Argument in project ceylon-compiler by ceylon.
the class TracerImpl method start.
public void start() throws Exception {
VirtualMachineManager vmm = com.sun.jdi.Bootstrap.virtualMachineManager();
LaunchingConnector conn = vmm.defaultConnector();
Map<String, Argument> defaultArguments = conn.defaultArguments();
defaultArguments.get("main").setValue(mainClass);
defaultArguments.get("options").setValue("-cp " + classPath);
System.out.println(defaultArguments);
vm = conn.launch(defaultArguments);
err = vm.process().getErrorStream();
out = vm.process().getInputStream();
eq = vm.eventQueue();
rm = vm.eventRequestManager();
outer: while (true) {
echo(err, System.err);
echo(out, System.out);
events = eq.remove();
for (Event event : events) {
if (event instanceof VMStartEvent) {
System.out.println(event);
break outer;
} else if (event instanceof VMDisconnectEvent || event instanceof VMDeathEvent) {
System.out.println(event);
vm = null;
rm = null;
eq = null;
break outer;
}
}
events.resume();
}
echo(err, System.err);
echo(out, System.out);
}
Aggregations