sun.jvmstat.monitor.VmIdentifier Java Examples

The following examples show how to use sun.jvmstat.monitor.VmIdentifier. 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: JCmd.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #2
Source File: JCmd.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #3
Source File: JCmd.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #4
Source File: AutoImportLocalNode.java    From Jpom with MIT License 6 votes vote down vote up
@PreLoadMethod
private static void loadAgent() {
    nodeService = SpringUtil.getBean(NodeService.class);
    List<NodeModel> list = nodeService.list();
    if (list != null && !list.isEmpty()) {
        return;
    }
    //
    try {
        List<MonitoredVm> monitoredVms = JvmUtil.listMainClass(AGENT_MAIN_CLASS);
        monitoredVms.forEach(monitoredVm -> {
            VmIdentifier vmIdentifier = monitoredVm.getVmIdentifier();
            findPid(vmIdentifier.getUserInfo());
        });
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("自动添加本机节点错误", e);
    }
}
 
Example #5
Source File: CheckDuplicateRun.java    From Jpom with MIT License 6 votes vote down vote up
static void check() {
    try {
        Class appClass = JpomApplication.getAppClass();
        String pid = String.valueOf(JpomManifest.getInstance().getPid());
        List<MonitoredVm> monitoredVms = JvmUtil.listMainClass(appClass.getName());
        monitoredVms.forEach(monitoredVm -> {
            VmIdentifier vmIdentifier = monitoredVm.getVmIdentifier();
            if (pid.equals(vmIdentifier.getUserInfo())) {
                return;
            }
            DefaultSystemLog.getLog().info("Jpom 程序建议一个机器上只运行一个对应的程序:" + JpomApplication.getAppType() + "  pid:" + vmIdentifier.getUserInfo());
        });
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("检查异常", e);
    }
}
 
Example #6
Source File: JCmd.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #7
Source File: JCmd.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #8
Source File: TestPollingInterval.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException,
        MonitorException, URISyntaxException {
    LingeredApp app = null;
    try {
        List<String> vmArgs = new ArrayList<String>();
        vmArgs.add("-XX:+UsePerfData");
        vmArgs.addAll(Utils.getVmOptions());
        app = LingeredApp.startApp(vmArgs);

        MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
        String uriString = "//" + app.getPid() + "?mode=r"; // NOI18N
        VmIdentifier vmId = new VmIdentifier(uriString);
        MonitoredVm vm = localHost.getMonitoredVm(vmId);
        System.out.println("Monitored vm command line: " + MonitoredVmUtil.commandLine(vm));

        vm.setInterval(INTERVAL);
        localHost.setInterval(INTERVAL);

        Asserts.assertEquals(vm.getInterval(), INTERVAL, "Monitored vm interval should be equal the test value");
        Asserts.assertEquals(localHost.getInterval(), INTERVAL, "Monitored host interval should be equal the test value");
    } finally {
        LingeredApp.stopApp(app);
    }

}
 
Example #9
Source File: JCmd.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #10
Source File: JCmd.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #11
Source File: JCmd.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #12
Source File: JCmd.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #13
Source File: JCmd.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #14
Source File: JCmd.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #15
Source File: JCmd.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #16
Source File: CR6672135.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int vmInterval;
    int hostInterval;

    try {
        MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
        Set vms = localHost.activeVms();
        Integer vmInt =  (Integer) vms.iterator().next();
        String uriString = "//" + vmInt + "?mode=r"; // NOI18N
        VmIdentifier vmId = new VmIdentifier(uriString);
        MonitoredVm vm = localHost.getMonitoredVm(vmId);

        vm.setInterval(INTERVAL);
        localHost.setInterval(INTERVAL);
        vmInterval = vm.getInterval();
        hostInterval = localHost.getInterval();
    } catch (Exception ex) {
        throw new Error ("Test failed",ex);
    }
    System.out.println("VM "+vmInterval);
    if (vmInterval != INTERVAL) {
        throw new Error("Test failed");
    }
    System.out.println("Host "+hostInterval);
    if (hostInterval != INTERVAL) {
        throw new Error("Test failed");
    }
}
 
Example #17
Source File: HotSpotAttachProvider.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a VM is attachable. If it's not attachable,
 * an AttachNotSupportedException will be thrown. For example,
 * 1.4.2 or 5.0 VM are not attachable. There are cases that
 * we can't determine if a VM is attachable or not and this method
 * will just return.
 *
 * This method uses the jvmstat counter to determine if a VM
 * is attachable. If the target VM does not have a jvmstat
 * share memory buffer, this method returns.
 *
 * @exception AttachNotSupportedException if it's not attachable
 */
void testAttachable(String id) throws AttachNotSupportedException {
    MonitoredVm mvm = null;
    try {
        VmIdentifier vmid = new VmIdentifier(id);
        MonitoredHost host = MonitoredHost.getMonitoredHost(vmid);
        mvm = host.getMonitoredVm(vmid);

        if (MonitoredVmUtil.isAttachable(mvm)) {
            // it's attachable; so return false
            return;
        }
    } catch (Throwable t) {
        if (t instanceof ThreadDeath) {
            ThreadDeath td = (ThreadDeath)t;
            throw td;
        }
        // we do not know what this id is
        return;
    } finally {
        if (mvm != null) {
            mvm.detach();
        }
    }

    // we're sure it's not attachable; throw exception
    throw new AttachNotSupportedException(
              "The VM does not support the attach mechanism");
}
 
Example #18
Source File: IgniteNodeRunner.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Kill all Jvm runned by {#link IgniteNodeRunner}. Works based on jps command.
 *
 * @return List of killed process ids.
 * @throws Exception If exception.
 */
public static List<Integer> killAll() throws Exception {
    MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(new HostIdentifier("localhost"));

    Set<Integer> jvms = monitoredHost.activeVms();

    List<Integer> res = new ArrayList<>();

    for (Integer jvmId : jvms) {
        try {
            MonitoredVm vm = monitoredHost.getMonitoredVm(new VmIdentifier("//" + jvmId + "?mode=r"), 0);

            if (IgniteNodeRunner.class.getName().equals(MonitoredVmUtil.mainClass(vm, true))) {
                Process killProc = Runtime.getRuntime().exec(U.isWindows() ?
                    new String[] {"taskkill", "/pid", jvmId.toString(), "/f", "/t"} :
                    new String[] {"kill", "-9", jvmId.toString()});

                killProc.waitFor();

                res.add(jvmId);
            }
        }
        catch (Exception e) {
            // Print stack trace just for information.
            X.printerrln("Could not kill IgniteNodeRunner java processes. Jvm pid = " + jvmId, e);
        }
    }

    return res;
}
 
Example #19
Source File: MonitorVmStartTerminate.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean hasMainArgs(Integer id, String args) {
    try {
        VmIdentifier vmid = new VmIdentifier("//" + id.intValue());
        MonitoredVm target = host.getMonitoredVm(vmid);
        String monitoredArgs = MonitoredVmUtil.mainArgs(target);
        if (monitoredArgs != null && monitoredArgs.contains(args)) {
            return true;
        }
    } catch (URISyntaxException | MonitorException e) {
        // ok. process probably not running
    }
    return false;
}
 
Example #20
Source File: HotSpotAttachProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a VM is attachable. If it's not attachable,
 * an AttachNotSupportedException will be thrown. For example,
 * 1.4.2 or 5.0 VM are not attachable. There are cases that
 * we can't determine if a VM is attachable or not and this method
 * will just return.
 *
 * This method uses the jvmstat counter to determine if a VM
 * is attachable. If the target VM does not have a jvmstat
 * share memory buffer, this method returns.
 *
 * @exception AttachNotSupportedException if it's not attachable
 */
void testAttachable(String id) throws AttachNotSupportedException {
    MonitoredVm mvm = null;
    try {
        VmIdentifier vmid = new VmIdentifier(id);
        MonitoredHost host = MonitoredHost.getMonitoredHost(vmid);
        mvm = host.getMonitoredVm(vmid);

        if (MonitoredVmUtil.isAttachable(mvm)) {
            // it's attachable; so return false
            return;
        }
    } catch (Throwable t) {
        if (t instanceof ThreadDeath) {
            ThreadDeath td = (ThreadDeath)t;
            throw td;
        }
        // we do not know what this id is
        return;
    } finally {
        if (mvm != null) {
            mvm.detach();
        }
    }

    // we're sure it's not attachable; throw exception
    throw new AttachNotSupportedException(
              "The VM does not support the attach mechanism");
}
 
Example #21
Source File: HotSpotAttachProvider.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a VM is attachable. If it's not attachable,
 * an AttachNotSupportedException will be thrown. For example,
 * 1.4.2 or 5.0 VM are not attachable. There are cases that
 * we can't determine if a VM is attachable or not and this method
 * will just return.
 *
 * This method uses the jvmstat counter to determine if a VM
 * is attachable. If the target VM does not have a jvmstat
 * share memory buffer, this method returns.
 *
 * @exception AttachNotSupportedException if it's not attachable
 */
void testAttachable(String id) throws AttachNotSupportedException {
    MonitoredVm mvm = null;
    try {
        VmIdentifier vmid = new VmIdentifier(id);
        MonitoredHost host = MonitoredHost.getMonitoredHost(vmid);
        mvm = host.getMonitoredVm(vmid);

        if (MonitoredVmUtil.isAttachable(mvm)) {
            // it's attachable; so return false
            return;
        }
    } catch (Throwable t) {
        if (t instanceof ThreadDeath) {
            ThreadDeath td = (ThreadDeath)t;
            throw td;
        }
        // we do not know what this id is
        return;
    } finally {
        if (mvm != null) {
            mvm.detach();
        }
    }

    // we're sure it's not attachable; throw exception
    throw new AttachNotSupportedException(
              "The VM does not support the attach mechanism");
}
 
Example #22
Source File: CR6672135.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int vmInterval;
    int hostInterval;

    try {
        MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
        Set vms = localHost.activeVms();
        Integer vmInt =  (Integer) vms.iterator().next();
        String uriString = "//" + vmInt + "?mode=r"; // NOI18N
        VmIdentifier vmId = new VmIdentifier(uriString);
        MonitoredVm vm = localHost.getMonitoredVm(vmId);

        vm.setInterval(INTERVAL);
        localHost.setInterval(INTERVAL);
        vmInterval = vm.getInterval();
        hostInterval = localHost.getInterval();
    } catch (Exception ex) {
        throw new Error ("Test failed",ex);
    }
    System.out.println("VM "+vmInterval);
    if (vmInterval != INTERVAL) {
        throw new Error("Test failed");
    }
    System.out.println("Host "+hostInterval);
    if (hostInterval != INTERVAL) {
        throw new Error("Test failed");
    }
}
 
Example #23
Source File: HotSpotAttachProvider.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a VM is attachable. If it's not attachable,
 * an AttachNotSupportedException will be thrown. For example,
 * 1.4.2 or 5.0 VM are not attachable. There are cases that
 * we can't determine if a VM is attachable or not and this method
 * will just return.
 *
 * This method uses the jvmstat counter to determine if a VM
 * is attachable. If the target VM does not have a jvmstat
 * share memory buffer, this method returns.
 *
 * @exception AttachNotSupportedException if it's not attachable
 */
void testAttachable(String id) throws AttachNotSupportedException {
    MonitoredVm mvm = null;
    try {
        VmIdentifier vmid = new VmIdentifier(id);
        MonitoredHost host = MonitoredHost.getMonitoredHost(vmid);
        mvm = host.getMonitoredVm(vmid);

        if (MonitoredVmUtil.isAttachable(mvm)) {
            // it's attachable; so return false
            return;
        }
    } catch (Throwable t) {
        if (t instanceof ThreadDeath) {
            ThreadDeath td = (ThreadDeath)t;
            throw td;
        }
        // we do not know what this id is
        return;
    } finally {
        if (mvm != null) {
            mvm.detach();
        }
    }

    // we're sure it's not attachable; throw exception
    throw new AttachNotSupportedException(
              "The VM does not support the attach mechanism");
}
 
Example #24
Source File: CR6672135.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int vmInterval;
    int hostInterval;

    try {
        MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
        Set vms = localHost.activeVms();
        Integer vmInt =  (Integer) vms.iterator().next();
        String uriString = "//" + vmInt + "?mode=r"; // NOI18N
        VmIdentifier vmId = new VmIdentifier(uriString);
        MonitoredVm vm = localHost.getMonitoredVm(vmId);

        vm.setInterval(INTERVAL);
        localHost.setInterval(INTERVAL);
        vmInterval = vm.getInterval();
        hostInterval = localHost.getInterval();
    } catch (Exception ex) {
        throw new Error ("Test failed",ex);
    }
    System.out.println("VM "+vmInterval);
    if (vmInterval != INTERVAL) {
        throw new Error("Test failed");
    }
    System.out.println("Host "+hostInterval);
    if (hostInterval != INTERVAL) {
        throw new Error("Test failed");
    }
}
 
Example #25
Source File: MonitorVmStartTerminate.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean hasMainArgs(Integer id, String args) {
    try {
        VmIdentifier vmid = new VmIdentifier("//" + id.intValue());
        MonitoredVm target = host.getMonitoredVm(vmid);
        String monitoredArgs = MonitoredVmUtil.mainArgs(target);
        if (monitoredArgs != null && monitoredArgs.contains(args)) {
            return true;
        }
    } catch (URISyntaxException | MonitorException e) {
        // ok. process probably not running
    }
    return false;
}
 
Example #26
Source File: HotSpotAttachProvider.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a VM is attachable. If it's not attachable,
 * an AttachNotSupportedException will be thrown. For example,
 * 1.4.2 or 5.0 VM are not attachable. There are cases that
 * we can't determine if a VM is attachable or not and this method
 * will just return.
 *
 * This method uses the jvmstat counter to determine if a VM
 * is attachable. If the target VM does not have a jvmstat
 * share memory buffer, this method returns.
 *
 * @exception AttachNotSupportedException if it's not attachable
 */
void testAttachable(String id) throws AttachNotSupportedException {
    MonitoredVm mvm = null;
    try {
        VmIdentifier vmid = new VmIdentifier(id);
        MonitoredHost host = MonitoredHost.getMonitoredHost(vmid);
        mvm = host.getMonitoredVm(vmid);

        if (MonitoredVmUtil.isAttachable(mvm)) {
            // it's attachable; so return false
            return;
        }
    } catch (Throwable t) {
        if (t instanceof ThreadDeath) {
            ThreadDeath td = (ThreadDeath)t;
            throw td;
        }
        // we do not know what this id is
        return;
    } finally {
        if (mvm != null) {
            mvm.detach();
        }
    }

    // we're sure it's not attachable; throw exception
    throw new AttachNotSupportedException(
              "The VM does not support the attach mechanism");
}
 
Example #27
Source File: CR6672135.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int vmInterval;
    int hostInterval;

    try {
        MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
        Set vms = localHost.activeVms();
        Integer vmInt =  (Integer) vms.iterator().next();
        String uriString = "//" + vmInt + "?mode=r"; // NOI18N
        VmIdentifier vmId = new VmIdentifier(uriString);
        MonitoredVm vm = localHost.getMonitoredVm(vmId);

        vm.setInterval(INTERVAL);
        localHost.setInterval(INTERVAL);
        vmInterval = vm.getInterval();
        hostInterval = localHost.getInterval();
    } catch (Exception ex) {
        throw new Error ("Test failed",ex);
    }
    System.out.println("VM "+vmInterval);
    if (vmInterval != INTERVAL) {
        throw new Error("Test failed");
    }
    System.out.println("Host "+hostInterval);
    if (hostInterval != INTERVAL) {
        throw new Error("Test failed");
    }
}
 
Example #28
Source File: CR6672135.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int vmInterval;
    int hostInterval;

    try {
        MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
        Set vms = localHost.activeVms();
        Integer vmInt =  (Integer) vms.iterator().next();
        String uriString = "//" + vmInt + "?mode=r"; // NOI18N
        VmIdentifier vmId = new VmIdentifier(uriString);
        MonitoredVm vm = localHost.getMonitoredVm(vmId);

        vm.setInterval(INTERVAL);
        localHost.setInterval(INTERVAL);
        vmInterval = vm.getInterval();
        hostInterval = localHost.getInterval();
    } catch (Exception ex) {
        throw new Error ("Test failed",ex);
    }
    System.out.println("VM "+vmInterval);
    if (vmInterval != INTERVAL) {
        throw new Error("Test failed");
    }
    System.out.println("Host "+hostInterval);
    if (hostInterval != INTERVAL) {
        throw new Error("Test failed");
    }
}
 
Example #29
Source File: MonitorVmStartTerminate.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private boolean hasMainArgs(Integer id, String args) {
    try {
        VmIdentifier vmid = new VmIdentifier("//" + id.intValue());
        MonitoredVm target = host.getMonitoredVm(vmid);
        String monitoredArgs = MonitoredVmUtil.mainArgs(target);
        if (monitoredArgs != null && monitoredArgs.contains(args)) {
            return true;
        }
    } catch (URISyntaxException | MonitorException e) {
        // ok. process probably not running
    }
    return false;
}
 
Example #30
Source File: HotSpotAttachProvider.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a VM is attachable. If it's not attachable,
 * an AttachNotSupportedException will be thrown. For example,
 * 1.4.2 or 5.0 VM are not attachable. There are cases that
 * we can't determine if a VM is attachable or not and this method
 * will just return.
 *
 * This method uses the jvmstat counter to determine if a VM
 * is attachable. If the target VM does not have a jvmstat
 * share memory buffer, this method returns.
 *
 * @exception AttachNotSupportedException if it's not attachable
 */
void testAttachable(String id) throws AttachNotSupportedException {
    MonitoredVm mvm = null;
    try {
        VmIdentifier vmid = new VmIdentifier(id);
        MonitoredHost host = MonitoredHost.getMonitoredHost(vmid);
        mvm = host.getMonitoredVm(vmid);

        if (MonitoredVmUtil.isAttachable(mvm)) {
            // it's attachable; so return false
            return;
        }
    } catch (Throwable t) {
        if (t instanceof ThreadDeath) {
            ThreadDeath td = (ThreadDeath)t;
            throw td;
        }
        // we do not know what this id is
        return;
    } finally {
        if (mvm != null) {
            mvm.detach();
        }
    }

    // we're sure it's not attachable; throw exception
    throw new AttachNotSupportedException(
              "The VM does not support the attach mechanism");
}