use of com.sun.tools.attach.VirtualMachineDescriptor in project sts4 by spring-projects.
the class SpringBootAppCache method refresh.
private void refresh() {
List<VirtualMachineDescriptor> currentVms = VirtualMachine.list();
ImmutableMap.Builder<VirtualMachineDescriptor, SpringBootApp> newAppsBuilder = ImmutableMap.builder();
for (VirtualMachineDescriptor vm : currentVms) {
SpringBootApp existingApp = apps.get(vm);
if (existingApp != null) {
newAppsBuilder.put(vm, existingApp);
} else {
try {
newAppsBuilder.put(vm, new SpringBootApp(vm));
} catch (Exception e) {
// Ignore problems attaching to a VM. We will try again on next polling loop, if vm still exists.
// The most likely cause is that the VM already died since we obtained a reference to it.
}
}
}
HashSet<VirtualMachineDescriptor> oldVms = new HashSet<>(apps.keySet());
ImmutableMap<VirtualMachineDescriptor, SpringBootApp> newApps = newAppsBuilder.build();
oldVms.removeAll(newApps.keySet());
for (VirtualMachineDescriptor oldVm : oldVms) {
apps.get(oldVm).dispose();
}
apps = newApps;
nextRefreshAfter = System.currentTimeMillis() + EXPIRE_AFTER.toMillis();
}
use of com.sun.tools.attach.VirtualMachineDescriptor in project Aeron by real-logic.
the class ClusterNetworkTopologyTest method setUp.
@BeforeEach
void setUp() {
Tests.await(() -> {
final List<VirtualMachineDescriptor> list = VirtualMachine.list();
final List<VirtualMachineDescriptor> echoServices = list.stream().filter((vm) -> EchoServiceNode.class.getName().equals(vm.displayName())).collect(Collectors.toList());
if (!echoServices.isEmpty()) {
System.out.println(echoServices);
Tests.sleep(200, () -> "Failed to shutdown EchoServiceNode");
}
return echoServices.isEmpty();
}, SECONDS.toNanos(10));
baseDir = FileResolveUtil.resolveClusterScriptDir();
IoUtil.delete(new File(baseDir, "node0"), true);
IoUtil.delete(new File(baseDir, "node1"), true);
IoUtil.delete(new File(baseDir, "node2"), true);
}
use of com.sun.tools.attach.VirtualMachineDescriptor in project jdk8u_jdk by JetBrains.
the class JCmd method main.
public static void main(String[] args) {
Arguments arg = null;
try {
arg = new Arguments(args);
} catch (IllegalArgumentException ex) {
System.err.println("Error parsing arguments: " + ex.getMessage() + "\n");
Arguments.usage();
System.exit(1);
}
if (arg.isShowUsage()) {
Arguments.usage();
System.exit(1);
}
if (arg.isListProcesses()) {
List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
for (VirtualMachineDescriptor vmd : vmds) {
System.out.println(vmd.id() + " " + vmd.displayName());
}
System.exit(0);
}
List<String> pids = new ArrayList<String>();
if (arg.getPid() == 0) {
// find all VMs
List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
for (VirtualMachineDescriptor vmd : vmds) {
if (!isJCmdProcess(vmd)) {
pids.add(vmd.id());
}
}
} else if (arg.getProcessSubstring() != null) {
// use the partial class-name match
List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
for (VirtualMachineDescriptor vmd : vmds) {
if (isJCmdProcess(vmd)) {
continue;
}
try {
String mainClass = getMainClass(vmd);
if (mainClass != null && mainClass.indexOf(arg.getProcessSubstring()) != -1) {
pids.add(vmd.id());
}
} catch (MonitorException | URISyntaxException e) {
if (e.getMessage() != null) {
System.err.println(e.getMessage());
} else {
Throwable cause = e.getCause();
if ((cause != null) && (cause.getMessage() != null)) {
System.err.println(cause.getMessage());
} else {
e.printStackTrace();
}
}
}
}
if (pids.isEmpty()) {
System.err.println("Could not find any processes matching : '" + arg.getProcessSubstring() + "'");
System.exit(1);
}
} else if (arg.getPid() == -1) {
System.err.println("Invalid pid specified");
System.exit(1);
} else {
// Use the found pid
pids.add(arg.getPid() + "");
}
boolean success = true;
for (String pid : pids) {
System.out.println(pid + ":");
if (arg.isListCounters()) {
listCounters(pid);
} else {
try {
executeCommandForPid(pid, arg.getCommand());
} catch (AttachOperationFailedException ex) {
System.err.println(ex.getMessage());
success = false;
} catch (Exception ex) {
ex.printStackTrace();
success = false;
}
}
}
System.exit(success ? 0 : 1);
}
use of com.sun.tools.attach.VirtualMachineDescriptor in project jdk8u_jdk by JetBrains.
the class HotSpotAttachProvider method listVirtualMachines.
/*
* This listVirtualMachines implementation is based on jvmstat. Can override
* this in platform implementations when there is a more efficient mechanism
* available.
*/
public List<VirtualMachineDescriptor> listVirtualMachines() {
ArrayList<VirtualMachineDescriptor> result = new ArrayList<VirtualMachineDescriptor>();
MonitoredHost host;
Set<Integer> vms;
try {
host = MonitoredHost.getMonitoredHost(new HostIdentifier((String) null));
vms = host.activeVms();
} catch (Throwable t) {
if (t instanceof ExceptionInInitializerError) {
t = t.getCause();
}
if (t instanceof ThreadDeath) {
throw (ThreadDeath) t;
}
if (t instanceof SecurityException) {
return result;
}
// shouldn't happen
throw new InternalError(t);
}
for (Integer vmid : vms) {
String pid = vmid.toString();
// default to pid if name not available
String name = pid;
boolean isAttachable = false;
MonitoredVm mvm = null;
try {
mvm = host.getMonitoredVm(new VmIdentifier(pid));
try {
isAttachable = MonitoredVmUtil.isAttachable(mvm);
// use the command line as the display name
name = MonitoredVmUtil.commandLine(mvm);
} catch (Exception e) {
}
if (isAttachable) {
result.add(new HotSpotVirtualMachineDescriptor(this, pid, name));
}
} catch (Throwable t) {
if (t instanceof ThreadDeath) {
throw (ThreadDeath) t;
}
} finally {
if (mvm != null) {
mvm.detach();
}
}
}
return result;
}
use of com.sun.tools.attach.VirtualMachineDescriptor 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