本文整理汇总了Java中com.sun.jdi.Bootstrap类的典型用法代码示例。如果您正苦于以下问题:Java Bootstrap类的具体用法?Java Bootstrap怎么用?Java Bootstrap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bootstrap类属于com.sun.jdi包,在下文中一共展示了Bootstrap类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
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);
}
}
示例2: findListeningConnector
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
private static ListeningConnector findListeningConnector (String s) {
Iterator iter = Bootstrap.virtualMachineManager ().
listeningConnectors ().iterator ();
while (iter.hasNext ()) {
ListeningConnector ac = (ListeningConnector) iter.next ();
if (ac.transport() != null && ac.transport ().name ().toLowerCase ().indexOf (s) > -1)
return ac;
}
return null;
}
示例3: attach
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
/**
* Attach to a target VM using the specified address and Connector arguments.
*/
public VirtualMachine attach(String address, Map<String, ? extends Connector.Argument> args)
throws IOException, IllegalConnectorArgumentsException
{
String ts = argument(ARG_TIMEOUT, args).value();
int timeout = 0;
if (ts.length() > 0) {
timeout = Integer.decode(ts).intValue();
}
Connection connection = transportService.attach(address, timeout, 0);
return Bootstrap.virtualMachineManager().createVirtualMachine(connection);
}
示例4: createVirtualMachine
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
private VirtualMachine createVirtualMachine(Class vmImplClass,
String debugServerName)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
java.lang.reflect.Method connectByServerMethod =
vmImplClass.getMethod(
"createVirtualMachineForServer",
new Class[] {
VirtualMachineManager.class,
String.class,
Integer.TYPE
});
return (VirtualMachine) connectByServerMethod.invoke(null,
new Object[] {
Bootstrap.virtualMachineManager(),
debugServerName,
new Integer(0)
});
}
示例5: createVirtualMachine
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
private VirtualMachine createVirtualMachine(Class vmImplClass,
String javaExec, String corefile)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
"createVirtualMachineForCorefile",
new Class[] {
VirtualMachineManager.class,
String.class, String.class,
Integer.TYPE
});
return (VirtualMachine) connectByCoreMethod.invoke(null,
new Object[] {
Bootstrap.virtualMachineManager(),
javaExec,
corefile,
new Integer(0)
});
}
示例6: main
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
List<ListeningConnector> connectors = Bootstrap.virtualMachineManager().listeningConnectors();
for (ListeningConnector lc: connectors) {
Map<String,Connector.Argument> cargs = lc.defaultArguments();
Connector.IntegerArgument timeout = (Connector.IntegerArgument)cargs.get("timeout");
/*
* If the Connector has a argument named "timeout" then we set the timeout to 1 second
* and start it listening on its default address. It should throw TranpsortTimeoutException.
*/
if (timeout != null) {
System.out.println("Testing " + lc.name());
timeout.setValue(1000);
System.out.println("Listening on: " + lc.startListening(cargs));
try {
lc.accept(cargs);
throw new RuntimeException("Connection accepted from some debuggee - unexpected!");
} catch (TransportTimeoutException e) {
System.out.println("Timed out as expected.\n");
}
lc.stopListening(cargs);
}
}
}
示例7: tryDebug
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
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();
}
示例8: getDebugSession
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
public static IDebugSession getDebugSession(String projectName, String mainClass) throws Exception {
setupProject(projectName);
return debugSessionMap.computeIfAbsent(projectName, (name) -> {
String projectRoot = new File(rootPath, name).getAbsolutePath();
try {
final IDebugSession debugSession = DebugUtility.launch(Bootstrap.virtualMachineManager(), mainClass, "", "",
null, new File(projectRoot, "bin").getAbsolutePath(), null, null);
debugSession.getEventHub().events().subscribe(debugEvent -> {
if (debugEvent.event instanceof VMDisconnectEvent) {
try {
debugSession.getEventHub().close();
} catch (Exception e) {
// do nothing.
}
}
});
return debugSession;
} catch (Exception ex) {
return null;
}
});
}
示例9: attach
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
public PermissionDebugger attach() throws IOException, IllegalConnectorArgumentsException {
VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
List<AttachingConnector> connectors = vmm.attachingConnectors();
AttachingConnector connector =
connectors
.stream()
.filter(c -> c.transport().name().equals(transport))
.findFirst()
.orElseThrow(
() -> new IOException(String.format("Failed to find transport %s", transport)));
Map<String, Argument> map = connector.defaultArguments();
Argument portArg = map.get(PORT_KEY);
portArg.setValue(port);
map.put(PORT_KEY, portArg);
vm = connector.attach(map);
return this;
}
示例10: connect
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
@BeforeClass
public static void connect() throws Exception {
SocketAttachingConnector socketConnector = null;
for (Connector connector : Bootstrap.virtualMachineManager().allConnectors()) {
if (connector instanceof SocketAttachingConnector) {
socketConnector = (SocketAttachingConnector) connector;
}
}
if (socketConnector == null) {
throw new RuntimeException("Failed to find SocketAttachingConnector");
}
Map<String, ? extends Connector.Argument> args = socketConnector.defaultArguments();
Connector.IntegerArgument port = (Connector.IntegerArgument) args.get("port");
port.setValue(PORT);
Connector.StringArgument hostname = (Connector.StringArgument) args.get("hostname");
hostname.setValue("localhost");
virtualMachine = socketConnector.attach(args);
}
示例11: findLaunchingConnector
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
private static LaunchingConnector findLaunchingConnector () {
Iterator<LaunchingConnector> iter = Bootstrap.virtualMachineManager ().
launchingConnectors ().iterator ();
while (iter.hasNext ()) {
LaunchingConnector lc = iter.next ();
if (lc.name ().indexOf ("RawCommandLineLaunch") > -1)
return lc;
}
return null;
}
示例12: findLaunchingConnector
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
/**
* Find a com.sun.jdi.CommandLineLaunch connector
*/
LaunchingConnector findLaunchingConnector() {
List<Connector> connectors = Bootstrap.virtualMachineManager().allConnectors();
for (Connector connector : connectors) {
if (connector.name().equals("com.sun.jdi.CommandLineLaunch")) {
return (LaunchingConnector)connector;
}
}
throw new Error("No launching connector");
}
示例13: findLaunchingConnector
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
/**
* Find a com.sun.jdi.CommandLineLaunch connector
*/
static LaunchingConnector findLaunchingConnector() {
List <Connector> connectors = Bootstrap.virtualMachineManager().allConnectors();
Iterator <Connector> iter = connectors.iterator();
while (iter.hasNext()) {
Connector connector = iter.next();
if (connector.name().equals("com.sun.jdi.CommandLineLaunch")) {
return (LaunchingConnector)connector;
}
}
throw new Error("No launching connector");
}
示例14: list
import com.sun.jdi.Bootstrap; //导入依赖的package包/类
public void list() {
List<Connector> l = Bootstrap.virtualMachineManager().allConnectors();
for(Connector c: l) {
System.out.println(c.name());
}
}