use of com.sun.tools.attach.AttachNotSupportedException in project geode by apache.
the class MBeanProcessController method connect.
/**
* Connects to the JMX agent in the local process.
*
* @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
* in the process
* @throws IOException if the JDK management agent cannot be found and loaded
*/
private void connect() throws ConnectionFailedException, IOException {
try {
final JMXServiceURL jmxUrl = getJMXServiceURL();
this.jmxc = JMXConnectorFactory.connect(jmxUrl);
this.server = this.jmxc.getMBeanServerConnection();
} catch (AttachNotSupportedException e) {
throw new ConnectionFailedException("Failed to connect to process '" + this.pid + "'", e);
}
}
use of com.sun.tools.attach.AttachNotSupportedException in project geode by apache.
the class LocalProcessController method connect.
/**
* Connects to the JMX agent in the local process.
*
* @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
* in the process
* @throws IOException if the JDK management agent cannot be found and loaded
*/
void connect() throws ConnectionFailedException, IOException {
try {
final JMXServiceURL jmxUrl = getJMXServiceURL();
this.jmxc = JMXConnectorFactory.connect(jmxUrl);
this.server = this.jmxc.getMBeanServerConnection();
} catch (AttachNotSupportedException e) {
throw new ConnectionFailedException("Failed to connect to process '" + this.pid + "'", e);
}
}
use of com.sun.tools.attach.AttachNotSupportedException in project jdk8u_jdk by JetBrains.
the class JStack method runThreadDump.
// Attach to pid and perform a thread dump
private static void runThreadDump(String pid, String[] args) throws Exception {
VirtualMachine vm = null;
try {
vm = VirtualMachine.attach(pid);
} catch (Exception x) {
String msg = x.getMessage();
if (msg != null) {
System.err.println(pid + ": " + msg);
} else {
x.printStackTrace();
}
if ((x instanceof AttachNotSupportedException) && (loadSAClass() != null)) {
System.err.println("The -F option can be used when the target " + "process is not responding");
}
System.exit(1);
}
// Cast to HotSpotVirtualMachine as this is implementation specific
// method.
InputStream in = ((HotSpotVirtualMachine) vm).remoteDataDump((Object[]) args);
// read to EOF and just print output
byte[] b = new byte[256];
int n;
do {
n = in.read(b);
if (n > 0) {
String s = new String(b, 0, n, "UTF-8");
System.out.print(s);
}
} while (n > 0);
in.close();
vm.detach();
}
use of com.sun.tools.attach.AttachNotSupportedException in project jdk8u_jdk by JetBrains.
the class LocalVirtualMachine method getAttachableVMs.
private static void getAttachableVMs(Map<Integer, LocalVirtualMachine> map) {
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for (VirtualMachineDescriptor vmd : vms) {
try {
Integer vmid = Integer.valueOf(vmd.id());
if (!map.containsKey(vmid)) {
boolean attachable = false;
String address = null;
try {
VirtualMachine vm = VirtualMachine.attach(vmd);
attachable = true;
Properties agentProps = vm.getAgentProperties();
address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
vm.detach();
} catch (AttachNotSupportedException x) {
// not attachable
} catch (IOException x) {
// ignore
}
map.put(vmid, new LocalVirtualMachine(vmid.intValue(), vmd.displayName(), attachable, address));
}
} catch (NumberFormatException e) {
// do not support vmid different than pid
}
}
}
Aggregations