Example usage for java.lang.management ManagementFactory getRuntimeMXBean

List of usage examples for java.lang.management ManagementFactory getRuntimeMXBean

Introduction

In this page you can find the example usage for java.lang.management ManagementFactory getRuntimeMXBean.

Prototype

public static RuntimeMXBean getRuntimeMXBean() 

Source Link

Document

Returns the managed bean for the runtime system of the Java virtual machine.

Usage

From source file:org.apache.sentry.service.thrift.LeaderStatusMonitor.java

/**
 * Generate ID for the activator. <p>
 *
 * Ideally we would like something like host@pid, but Java doesn't provide a good
 * way to determine pid value, so we use
 * {@link RuntimeMXBean#getName()} which usually contains host
 * name and pid./*w w  w. j ava 2 s.  c  om*/
 */
private static String generateIncarnationId() {
    return ManagementFactory.getRuntimeMXBean().getName();
}

From source file:org.apache.htrace.core.TracerId.java

/**
 * <p>Get the process ID by looking at the name of the managed bean for the
 * runtime system of the Java virtual machine.</p>
 *
 * Although this is undocumented, in the Oracle JVM this name is of the form
 * [OS_PROCESS_ID]@[HOSTNAME]./*from   w w  w  .j a v  a2  s  .  c o m*/
 */
private static long getOsPidFromManagementFactory() {
    try {
        return Long.parseLong(ManagementFactory.getRuntimeMXBean().getName().split("@")[0]);
    } catch (NumberFormatException e) {
        LOG.error("Failed to get the operating system process ID from the name "
                + "of the managed bean for the JVM.", e);
        return 0L;
    }
}

From source file:org.callimachusproject.webdriver.helpers.BrowserFunctionalTestCase.java

private static String getBuild() {
    String build = System.getProperty("org.callimachusproject.test.build");
    String implementationVersion = Version.class.getPackage().getImplementationVersion();
    if (build != null) {
        return build;
    } else if (implementationVersion != null) {
        return implementationVersion;
    } else {/*  ww w  .  ja v  a  2  s  .  com*/
        RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
        long startTime = bean.getStartTime();
        long code = startTime % (1000 * 60 * 60 * 24 * 30) / 1000 / 60;
        String version = Version.getInstance().getVersionCode();
        return version + "+" + Long.toHexString(code);
    }
}

From source file:org.jvoicexml.systemtest.mobicents.BroadcastServletDemo.java

public BroadcastServletDemo() {
    VNXLog.info("constructor  :" + this + " ProcessID:" + ManagementFactory.getRuntimeMXBean().getName()
            + " CurrentThreadID:" + Thread.currentThread().getId() + " " + Thread.currentThread().toString()
            + " " + Thread.currentThread() + " VAppCfg:" + VAppCfg.getInstance());

}

From source file:org.wso2.carbon.integration.tests.carbontools.CarbonServerBasicOperationTestCase.java

@Test(groups = { "carbon.core" }, description = "Testing carbondump.bat execution", dependsOnMethods = {
        "testStopCommand" })
public void testCarbonDumpCommandOnWindows() throws Exception {
    Process processDump = null;//from w ww .  ja  v a2 s .  c om
    String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
    try {
        if (CarbonCommandToolsUtil.getCurrentOperatingSystem()
                .contains(OperatingSystems.WINDOWS.name().toLowerCase())) {

            RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
            Field jvmField = runtimeMXBean.getClass().getDeclaredField("jvm");
            jvmField.setAccessible(true);
            VMManagement vmManagement = (VMManagement) jvmField.get(runtimeMXBean);
            Method getProcessIdMethod = vmManagement.getClass().getDeclaredMethod("getProcessId");
            getProcessIdMethod.setAccessible(true);
            Integer processId = (Integer) getProcessIdMethod.invoke(vmManagement);

            String[] cmdArray = new String[] { "cmd.exe", "/c", "carbondump.bat", "-carbonHome", carbonHome,
                    "-pid", Integer.toString(processId) };
            processDump = CarbonCommandToolsUtil.runScript(carbonHome + "/bin", cmdArray);
            assertTrue(isDumpFileFound(carbonHome), "Couldn't find the dump file");
        } else {
            //Skip test from linux
            throw new SkipException(" This test method is only for windows");
        }
    } finally {
        if (processDump != null) {
            processDump.destroy();
        }
    }
}

From source file:com.adobe.aem.demomachine.gui.AemDemo.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private void initialize() {

    // Initialize properties
    setDefaultProperties(AemDemoUtils/*from  w  ww  . j a  va2 s  . c om*/
            .loadProperties(buildFile.getParentFile().getAbsolutePath() + File.separator + "build.properties"));
    setPersonalProperties(AemDemoUtils.loadProperties(buildFile.getParentFile().getAbsolutePath()
            + File.separator + "conf" + File.separator + "build-personal.properties"));

    // Constructing the main frame
    frameMain = new JFrame();
    frameMain.setBounds(100, 100, 700, 530);
    frameMain.getContentPane().setLayout(null);

    // Main menu bar for the Frame
    JMenuBar menuBar = new JMenuBar();

    JMenu mnAbout = new JMenu("AEM Demo Machine");
    mnAbout.setMnemonic(KeyEvent.VK_A);
    menuBar.add(mnAbout);

    JMenuItem mntmUpdates = new JMenuItem("Check for Updates");
    mntmUpdates.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmUpdates.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "demo_update");
        }
    });
    mnAbout.add(mntmUpdates);

    JMenuItem mntmDoc = new JMenuItem("Help and Documentation");
    mntmDoc.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_H, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmDoc.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties,
                    AemDemoConstants.OPTIONS_DOCUMENTATION));
        }
    });
    mnAbout.add(mntmDoc);

    JMenuItem mntmScripts = new JMenuItem("Demo Scripts (VPN)");
    mntmScripts.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties,
                    AemDemoConstants.OPTIONS_SCRIPTS));
        }
    });
    mnAbout.add(mntmScripts);

    JMenuItem mntmDiagnostics = new JMenuItem("Diagnostics");
    mntmDiagnostics.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Map<String, String> env = System.getenv();
            System.out.println("====== System Environment Variables ======");
            for (String envName : env.keySet()) {
                System.out.format("%s=%s%n", envName, env.get(envName));
            }
            System.out.println("====== JVM Properties ======");
            RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
            List<String> jvmArgs = runtimeMXBean.getInputArguments();
            for (String arg : jvmArgs) {
                System.out.println(arg);
            }
            System.out.println("====== Runtime Properties ======");
            Properties props = System.getProperties();
            props.list(System.out);
        }
    });
    mnAbout.add(mntmDiagnostics);

    JMenuItem mntmQuit = new JMenuItem("Quit");
    mntmQuit.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmQuit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(-1);
        }
    });
    mnAbout.add(mntmQuit);

    JMenu mnNew = new JMenu("New");
    menuBar.add(mnNew);

    // New Demo Machine
    JMenuItem mntmNewDemo = new JMenuItem("Demo Environment");
    mntmNewDemo.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmNewDemo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (AemDemo.this.getBuildInProgress()) {

                JOptionPane.showMessageDialog(null,
                        "A Demo Environment is currently being built. Please wait until it is finished.");

            } else {

                final AemDemoNew dialogNew = new AemDemoNew(AemDemo.this);
                dialogNew.setModal(true);
                dialogNew.setVisible(true);
                dialogNew.getDemoBuildName().requestFocus();
                ;

            }
        }
    });
    mnNew.add(mntmNewDemo);

    JMenuItem mntmNewOptions = new JMenuItem("Demo Properties");
    mntmNewOptions.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmNewOptions.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            final AemDemoOptions dialogOptions = new AemDemoOptions(AemDemo.this);
            dialogOptions.setModal(true);
            dialogOptions.setVisible(true);

        }
    });
    mnNew.add(mntmNewOptions);

    JMenu mnUpdate = new JMenu("Add-ons");
    menuBar.add(mnUpdate);

    // Sites Add-on
    JMenu mnSites = new JMenu("Sites");
    mnUpdate.add(mnSites);

    JMenuItem mntmSitesDownloadAddOn = new JMenuItem("Download Demo Add-on");
    mntmSitesDownloadAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_sites");
        }
    });
    mnSites.add(mntmSitesDownloadAddOn);

    JMenuItem mntmSitesDownloadFP = new JMenuItem("Download Packages (PackageShare)");
    mntmSitesDownloadFP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_sites_packages");
        }
    });
    mnSites.add(mntmSitesDownloadFP);

    // Assets Add-on
    JMenu mnAssets = new JMenu("Assets");
    mnUpdate.add(mnAssets);

    JMenuItem mntmAssetsDownloadAddOn = new JMenuItem("Download Demo Add-on");
    mntmAssetsDownloadAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_assets");
        }
    });
    mnAssets.add(mntmAssetsDownloadAddOn);

    JMenuItem mntmAssetsDownloadFP = new JMenuItem("Download Packages (PackageShare)");
    mntmAssetsDownloadFP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_assets_packages");
        }
    });
    mnAssets.add(mntmAssetsDownloadFP);

    // Communities Add-on
    JMenu mnCommunities = new JMenu("Communities/Livefyre");
    mnUpdate.add(mnCommunities);

    JMenuItem mntmAemCommunitiesFeaturePacks = new JMenuItem("Download Packages (PackageShare)");
    mntmAemCommunitiesFeaturePacks.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_communities_packages");
        }
    });
    mnCommunities.add(mntmAemCommunitiesFeaturePacks);

    // Forms Add-on
    JMenu mnForms = new JMenu("Forms");
    mnUpdate.add(mnForms);

    JMenuItem mntmAemFormsAddon = new JMenuItem("Download Demo Add-on");
    mntmAemFormsAddon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_forms");
        }
    });
    mnForms.add(mntmAemFormsAddon);

    JMenuItem mntmAemFormsFP = new JMenuItem("Download Packages (PackageShare)");
    mntmAemFormsFP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_forms_packages");
        }
    });
    mnForms.add(mntmAemFormsFP);

    // Mobile Add-on
    JMenu mnApps = new JMenu("Mobile");
    mnUpdate.add(mnApps);

    JMenuItem mntmAemAppsAddon = new JMenuItem("Download Demo Add-on");
    mntmAemAppsAddon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_apps");
        }
    });
    mnApps.add(mntmAemAppsAddon);

    JMenuItem mntmAemApps = new JMenuItem("Download Packages (PackageShare)");
    mntmAemApps.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_apps_packages");
        }
    });
    mnApps.add(mntmAemApps);

    // Commerce Add-on
    JMenu mnCommerce = new JMenu("Commerce");
    mnUpdate.add(mnCommerce);

    JMenu mnCommerceDownload = new JMenu("Download Packages");
    mnCommerce.add(mnCommerceDownload);

    // Commerce EP
    JMenuItem mnCommerceDownloadEP = new JMenuItem("ElasticPath (PackageShare)");
    mnCommerceDownloadEP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_commerce_ep");
        }
    });
    mnCommerceDownload.add(mnCommerceDownloadEP);

    // Commerce WebSphere
    JMenuItem mnCommerceDownloadWAS = new JMenuItem("WebSphere (PackageShare)");
    mnCommerceDownloadWAS.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_commerce_websphere");
        }
    });
    mnCommerceDownload.add(mnCommerceDownloadWAS);

    // WeRetail Add-on
    JMenu mnWeRetail = new JMenu("We-Retail");
    mnUpdate.add(mnWeRetail);

    JMenuItem mnWeRetailAddon = new JMenuItem("Download Demo Add-on");
    mnWeRetailAddon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_weretail");
        }
    });
    mnWeRetail.add(mnWeRetailAddon);

    // Download all section
    mnUpdate.addSeparator();

    JMenuItem mntmAemDownloadAll = new JMenuItem("Download All Add-ons");
    mntmAemDownloadAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_all");
        }
    });
    mnUpdate.add(mntmAemDownloadAll);

    JMenu mnInfrastructure = new JMenu("Infrastructure");
    menuBar.add(mnInfrastructure);

    JMenu mnMongo = new JMenu("MongoDB");

    JMenuItem mntmInfraMongoDB = new JMenuItem("Download");
    mntmInfraMongoDB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_mongo");
        }
    });
    mnMongo.add(mntmInfraMongoDB);

    JMenuItem mntmInfraMongoDBInstall = new JMenuItem("Install");
    mntmInfraMongoDBInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_mongo");
        }
    });
    mnMongo.add(mntmInfraMongoDBInstall);
    mnMongo.addSeparator();

    JMenuItem mntmInfraMongoDBStart = new JMenuItem("Start");
    mntmInfraMongoDBStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mongo_start");
        }
    });
    mnMongo.add(mntmInfraMongoDBStart);

    JMenuItem mntmInfraMongoDBStop = new JMenuItem("Stop");
    mntmInfraMongoDBStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mongo_stop");
        }
    });
    mnMongo.add(mntmInfraMongoDBStop);
    mnInfrastructure.add(mnMongo);

    // SOLR options
    JMenu mnSOLR = new JMenu("SOLR");

    JMenuItem mntmInfraSOLR = new JMenuItem("Download");
    mntmInfraSOLR.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_solr");
        }
    });
    mnSOLR.add(mntmInfraSOLR);

    JMenuItem mntmInfraSOLRInstall = new JMenuItem("Install");
    mntmInfraSOLRInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_solr");
        }
    });
    mnSOLR.add(mntmInfraSOLRInstall);
    mnSOLR.addSeparator();

    JMenuItem mntmInfraSOLRStart = new JMenuItem("Start");
    mntmInfraSOLRStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "solr_start");
        }
    });
    mnSOLR.add(mntmInfraSOLRStart);

    JMenuItem mntmInfraSOLRStop = new JMenuItem("Stop");
    mntmInfraSOLRStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "solr_stop");
        }
    });
    mnSOLR.add(mntmInfraSOLRStop);

    mnInfrastructure.add(mnSOLR);

    // MySQL options
    JMenu mnMySQL = new JMenu("MySQL");

    JMenuItem mntmInfraMysql = new JMenuItem("Download");
    mntmInfraMysql.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_mysql");
        }
    });
    mnMySQL.add(mntmInfraMysql);

    JMenuItem mntmInfraMysqlInstall = new JMenuItem("Install");
    mntmInfraMysqlInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_mysql");
        }
    });
    mnMySQL.add(mntmInfraMysqlInstall);

    mnMySQL.addSeparator();

    JMenuItem mntmInfraMysqlStart = new JMenuItem("Start");
    mntmInfraMysqlStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mysql_start");
        }
    });
    mnMySQL.add(mntmInfraMysqlStart);

    JMenuItem mntmInfraMysqlStop = new JMenuItem("Stop");
    mntmInfraMysqlStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mysql_stop");
        }
    });
    mnMySQL.add(mntmInfraMysqlStop);

    mnInfrastructure.add(mnMySQL);

    // James options
    JMenu mnJames = new JMenu("James SMTP/POP");

    JMenuItem mntmInfraJames = new JMenuItem("Download");
    mntmInfraJames.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_james");
        }
    });
    mnJames.add(mntmInfraJames);

    JMenuItem mntmInfraJamesInstall = new JMenuItem("Install");
    mntmInfraJamesInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_james");
        }
    });
    mnJames.add(mntmInfraJamesInstall);
    mnJames.addSeparator();

    JMenuItem mntmInfraJamesStart = new JMenuItem("Start");
    mntmInfraJamesStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "james_start");
        }
    });
    mnJames.add(mntmInfraJamesStart);

    JMenuItem mntmInfraJamesStop = new JMenuItem("Stop");
    mntmInfraJamesStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "james_stop");
        }
    });
    mnJames.add(mntmInfraJamesStop);

    mnInfrastructure.add(mnJames);

    // FFMPEPG options
    JMenu mnFFMPEG = new JMenu("FFMPEG");

    JMenuItem mntmInfraFFMPEG = new JMenuItem("Download");
    mntmInfraFFMPEG.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_ffmpeg");
        }
    });
    mnFFMPEG.add(mntmInfraFFMPEG);

    JMenuItem mntmInfraFFMPEGInstall = new JMenuItem("Install");
    mntmInfraFFMPEGInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_ffmpeg");
        }
    });
    mnFFMPEG.add(mntmInfraFFMPEGInstall);

    mnInfrastructure.add(mnFFMPEG);

    mnInfrastructure.addSeparator();

    // InDesignServer options
    JMenu mnInDesignServer = new JMenu("InDesign Server");

    JMenuItem mntmInfraInDesignServerDownload = new JMenuItem("Download");
    mntmInfraInDesignServerDownload.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_indesignserver");
        }
    });
    mnInDesignServer.add(mntmInfraInDesignServerDownload);

    mnInDesignServer.addSeparator();

    JMenuItem mntmInfraInDesignServerStart = new JMenuItem("Start");
    mntmInfraInDesignServerStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "start_indesignserver");
        }
    });
    mnInDesignServer.add(mntmInfraInDesignServerStart);

    JMenuItem mntmInfraInDesignServerStop = new JMenuItem("Stop");
    mntmInfraInDesignServerStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "stop_indesignserver");
        }
    });
    mnInDesignServer.add(mntmInfraInDesignServerStop);

    mnInfrastructure.add(mnInDesignServer);

    mnInfrastructure.addSeparator();

    JMenuItem mntmInfraInstall = new JMenuItem("All in One Setup");
    mntmInfraInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "infrastructure");
        }
    });
    mnInfrastructure.add(mntmInfraInstall);

    JMenu mnOther = new JMenu("Other");
    menuBar.add(mnOther);

    JMenu mntmAemDownload = new JMenu("AEM & License files (VPN)");

    JMenuItem mntmAemLoad = new JMenuItem("Download Latest AEM Load");
    mntmAemLoad.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemLoad.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_load");
        }
    });
    mntmAemDownload.add(mntmAemLoad);

    JMenuItem mntmAemSnapshot = new JMenuItem("Download Latest AEM Snapshot");
    mntmAemSnapshot.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemSnapshot.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_snapshot");
        }
    });
    mntmAemDownload.add(mntmAemSnapshot);

    JMenuItem mntmAemDownloadAEM62 = new JMenuItem("Download AEM 6.2");
    mntmAemDownloadAEM62.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_aem62");
        }
    });
    mntmAemDownload.add(mntmAemDownloadAEM62);

    JMenuItem mntmAemDownloadAEM61 = new JMenuItem("Download AEM 6.1");
    mntmAemDownloadAEM61.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_aem61");
        }
    });
    mntmAemDownload.add(mntmAemDownloadAEM61);

    JMenuItem mntmAemDownloadAEM60 = new JMenuItem("Download AEM 6.0");
    mntmAemDownloadAEM60.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_aem60");
        }
    });
    mntmAemDownload.add(mntmAemDownloadAEM60);

    JMenuItem mntmAemDownloadCQ561 = new JMenuItem("Download CQ 5.6.1");
    mntmAemDownloadCQ561.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_cq561");
        }
    });
    mntmAemDownload.add(mntmAemDownloadCQ561);

    JMenuItem mntmAemDownloadCQ56 = new JMenuItem("Download CQ 5.6");
    mntmAemDownloadCQ56.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_cq56");
        }
    });
    mntmAemDownload.add(mntmAemDownloadCQ56);

    JMenuItem mntmAemDownloadOthers = new JMenuItem("Other Releases & License files");
    mntmAemDownloadOthers.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties,
                    AemDemoConstants.OPTIONS_DOWNLOAD));
        }
    });
    mntmAemDownload.add(mntmAemDownloadOthers);

    mnOther.add(mntmAemDownload);

    JMenuItem mntmAemHotfix = new JMenuItem("Download Latest Hotfixes (PackageShare)");
    mntmAemHotfix.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemHotfix.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_hotfixes_packages");
        }
    });
    mnOther.add(mntmAemHotfix);

    JMenuItem mntmAemAcs = new JMenuItem("Download Latest ACS Commons and Tools");
    mntmAemAcs.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemAcs.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_acs");
        }
    });
    mnOther.add(mntmAemAcs);

    // Adding the menu bar
    frameMain.setJMenuBar(menuBar);

    // Adding other form elements
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(24, 163, 650, 230);
    frameMain.getContentPane().add(scrollPane);

    final JTextArea textArea = new JTextArea("");
    textArea.setEditable(false);
    scrollPane.setViewportView(textArea);

    // List of demo machines available
    JScrollPane scrollDemoList = new JScrollPane();
    scrollDemoList.setBounds(24, 34, 208, 100);
    frameMain.getContentPane().add(scrollDemoList);
    listModelDemoMachines = AemDemoUtils.listDemoMachines(buildFile.getParentFile().getAbsolutePath());
    listDemoMachines = new JList(listModelDemoMachines);
    listDemoMachines.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listDemoMachines.setSelectedIndex(AemDemoUtils.getSelectedIndex(listDemoMachines,
            this.getDefaultProperties(), this.getPersonalProperties(), AemDemoConstants.OPTIONS_BUILD_DEFAULT));
    scrollDemoList.setViewportView(listDemoMachines);

    // Capturing the output stream of ANT commands
    AemDemoOutputStream out = new AemDemoOutputStream(textArea);
    System.setOut(new PrintStream(out));

    JButton btnStart = new JButton("Start");
    btnStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            AemDemoUtils.antTarget(AemDemo.this, "start");

        }
    });

    btnStart.setBounds(250, 29, 117, 29);
    frameMain.getContentPane().add(btnStart);

    // Set Start as the default button
    JRootPane rootPane = SwingUtilities.getRootPane(btnStart);
    rootPane.setDefaultButton(btnStart);

    JButton btnInfo = new JButton("Details");
    btnInfo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            AemDemoUtils.antTarget(AemDemo.this, "details");

        }
    });
    btnInfo.setBounds(250, 59, 117, 29);
    frameMain.getContentPane().add(btnInfo);

    // Rebuild action
    JButton btnRebuild = new JButton("Rebuild");
    btnRebuild.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (AemDemo.this.getBuildInProgress()) {

                JOptionPane.showMessageDialog(null,
                        "A Demo Environment is currently being built. Please wait until it is finished.");

            } else {

                final AemDemoRebuild dialogRebuild = new AemDemoRebuild(AemDemo.this);
                dialogRebuild.setModal(true);
                dialogRebuild.setVisible(true);
                dialogRebuild.getDemoBuildName().requestFocus();
                ;

            }

        }
    });

    btnRebuild.setBounds(250, 89, 117, 29);
    frameMain.getContentPane().add(btnRebuild);

    // Stop action 
    JButton btnStop = new JButton("Stop");
    btnStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            int dialogResult = JOptionPane.showConfirmDialog(null,
                    "Are you sure you really want to stop the running instances?", "Warning",
                    JOptionPane.YES_NO_OPTION);
            if (dialogResult == JOptionPane.NO_OPTION) {
                return;
            }
            AemDemoUtils.antTarget(AemDemo.this, "stop");

        }
    });
    btnStop.setBounds(500, 29, 117, 29);
    frameMain.getContentPane().add(btnStop);

    JButton btnExit = new JButton("Exit");
    btnExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(-1);
        }
    });
    btnExit.setBounds(550, 408, 117, 29);
    frameMain.getContentPane().add(btnExit);

    JButton btnClear = new JButton("Clear");
    btnClear.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textArea.setText("");
        }
    });
    btnClear.setBounds(40, 408, 117, 29);
    frameMain.getContentPane().add(btnClear);

    JButton btnBackup = new JButton("Backup");
    btnBackup.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "backup");
        }
    });
    btnBackup.setBounds(500, 59, 117, 29);
    frameMain.getContentPane().add(btnBackup);

    JButton btnRestore = new JButton("Restore");
    btnRestore.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "restore");
        }
    });
    btnRestore.setBounds(500, 89, 117, 29);
    frameMain.getContentPane().add(btnRestore);

    JButton btnDelete = new JButton("Delete");
    btnDelete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int dialogResult = JOptionPane.showConfirmDialog(null,
                    "Are you sure you really want to permanently delete the selected demo configuration?",
                    "Warning", JOptionPane.YES_NO_OPTION);
            if (dialogResult == JOptionPane.NO_OPTION) {
                return;
            }
            AemDemoUtils.antTarget(AemDemo.this, "uninstall");
        }
    });
    btnDelete.setBounds(500, 119, 117, 29);
    frameMain.getContentPane().add(btnDelete);

    JLabel lblSelectYourDemo = new JLabel("Select your Demo Environment");
    lblSelectYourDemo.setBounds(24, 10, 219, 16);
    frameMain.getContentPane().add(lblSelectYourDemo);

    JLabel lblCommandOutput = new JLabel("Command Output");
    lblCommandOutput.setBounds(24, 143, 160, 16);
    frameMain.getContentPane().add(lblCommandOutput);

    // Initializing and launching the ticker
    String tickerOn = AemDemoUtils.getPropertyValue(buildFile, "demo.ticker");
    if (tickerOn == null || (tickerOn != null && tickerOn.equals("true"))) {
        AemDemoMarquee mp = new AemDemoMarquee(AemDemoConstants.Credits, 60);
        mp.setBounds(140, 440, 650, 30);
        frameMain.getContentPane().add(mp);
        mp.start();
    }

    // Launching the download tracker task
    AemDemoDownload aemDownload = new AemDemoDownload(AemDemo.this);
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    executor.scheduleAtFixedRate(aemDownload, 0, 5, TimeUnit.SECONDS);

    // Loading up the README.md file
    String line = null;
    try {
        FileReader fileReader = new FileReader(
                buildFile.getParentFile().getAbsolutePath() + File.separator + "README.md");
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        while ((line = bufferedReader.readLine()) != null) {
            if (line.indexOf("AEM Demo Machine!") > 0) {
                line = line + " (version: " + aemDemoMachineVersion + ")";
            }
            if (!line.startsWith("Double"))
                System.out.println(line);
        }
        bufferedReader.close();
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }

}

From source file:net.pms.util.ProcessUtil.java

public static ArrayList<String> getUMSCommand() {
    ArrayList<String> reboot = new ArrayList<>();
    reboot.add(StringUtil.quoteArg(System.getProperty("java.home") + File.separator + "bin" + File.separator
            + ((Platform.isWindows() && System.console() == null) ? "javaw" : "java")));
    for (String jvmArg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
        reboot.add(StringUtil.quoteArg(jvmArg));
    }//from  w ww.  j  a  va  2 s. co m
    reboot.add("-cp");
    reboot.add(ManagementFactory.getRuntimeMXBean().getClassPath());
    // Could also use generic main discovery instead:
    // see http://stackoverflow.com/questions/41894/0-program-name-in-java-discover-main-class
    reboot.add(PMS.class.getName());
    return reboot;
}

From source file:com.thoughtworks.go.server.service.PipelineConfigServicePerformanceTest.java

private void takeHeapDump(File dumpDir, int i) {
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    CommandLine commandLine = CommandLine.createCommandLine("jmap").withArgs("-J-d64",
            String.format("-dump:format=b,file=%s/%s.hprof", dumpDir.getAbsoluteFile(), i),
            ManagementFactory.getRuntimeMXBean().getName().split("@")[0]);
    LOGGER.info(commandLine.describe());
    int exitCode = commandLine.run(outputStreamConsumer, new NamedProcessTag("thread" + i));
    LOGGER.info(outputStreamConsumer.getAllOutput());
    assertThat(exitCode, is(0));/*from  w ww  .j av  a 2 s.  com*/
    LOGGER.info("Heap dump available at " + dumpDir.getAbsolutePath());
}

From source file:org.jenkinsci.remoting.engine.HandlerLoopbackLoadStress.java

public HandlerLoopbackLoadStress(Config config)
        throws IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException,
        UnrecoverableKeyException, KeyManagementException, OperatorCreationException {
    this.config = config;
    KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
    gen.initialize(2048); // maximum supported by JVM with export restrictions
    keyPair = gen.generateKeyPair();//from  w ww .j a v  a 2s  .c o  m

    Date now = new Date();
    Date firstDate = new Date(now.getTime() + TimeUnit.DAYS.toMillis(10));
    Date lastDate = new Date(now.getTime() + TimeUnit.DAYS.toMillis(-10));

    SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfo
            .getInstance(keyPair.getPublic().getEncoded());

    X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.INSTANCE);
    X500Name subject = nameBuilder.addRDN(BCStyle.CN, getClass().getSimpleName()).addRDN(BCStyle.C, "US")
            .build();

    X509v3CertificateBuilder certGen = new X509v3CertificateBuilder(subject, BigInteger.ONE, firstDate,
            lastDate, subject, subjectPublicKeyInfo);

    JcaX509ExtensionUtils instance = new JcaX509ExtensionUtils();

    certGen.addExtension(X509Extension.subjectKeyIdentifier, false,
            instance.createSubjectKeyIdentifier(subjectPublicKeyInfo));

    ContentSigner signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider(BOUNCY_CASTLE_PROVIDER)
            .build(keyPair.getPrivate());

    certificate = new JcaX509CertificateConverter().setProvider(BOUNCY_CASTLE_PROVIDER)
            .getCertificate(certGen.build(signer));

    char[] password = "password".toCharArray();

    KeyStore store = KeyStore.getInstance("jks");
    store.load(null, password);
    store.setKeyEntry("alias", keyPair.getPrivate(), password, new Certificate[] { certificate });

    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmf.init(store, password);

    context = SSLContext.getInstance("TLS");
    context.init(kmf.getKeyManagers(), new TrustManager[] { new BlindTrustX509ExtendedTrustManager() }, null);

    mainHub = IOHub.create(executorService);
    // on windows there is a bug whereby you cannot mix ServerSockets and Sockets on the same selector
    acceptorHub = File.pathSeparatorChar == 59 ? IOHub.create(executorService) : mainHub;
    legacyHub = new NioChannelHub(executorService);
    executorService.submit(legacyHub);
    serverSocketChannel = ServerSocketChannel.open();

    JnlpProtocolHandler handler = null;
    for (JnlpProtocolHandler h : new JnlpProtocolHandlerFactory(executorService).withNioChannelHub(legacyHub)
            .withIOHub(mainHub).withSSLContext(context).withPreferNonBlockingIO(!config.bio)
            .withClientDatabase(new JnlpClientDatabase() {
                @Override
                public boolean exists(String clientName) {
                    return true;
                }

                @Override
                public String getSecretOf(@Nonnull String clientName) {
                    return secretFor(clientName);
                }
            }).withSSLClientAuthRequired(false).handlers()) {
        if (config.name.equals(h.getName())) {
            handler = h;
            break;
        }
    }
    if (handler == null) {
        throw new RuntimeException("Unknown handler: " + config.name);
    }
    this.handler = handler;

    acceptor = new Acceptor(serverSocketChannel);
    runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    _getProcessCpuTime = _getProcessCpuTime(operatingSystemMXBean);
    garbageCollectorMXBeans = new ArrayList<GarbageCollectorMXBean>(
            ManagementFactory.getGarbageCollectorMXBeans());
    Collections.sort(garbageCollectorMXBeans, new Comparator<GarbageCollectorMXBean>() {
        @Override
        public int compare(GarbageCollectorMXBean o1, GarbageCollectorMXBean o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    stats = new Stats();
}

From source file:org.renjin.primitives.System.java

/**
 * Returns object of class "proc_time" which is a numeric vector of
 * length 5, containing the user, system, and total elapsed times for
 * the currently running R process, and the cumulative sum of user
 * and system times of any child processes spawned by it on which it
 * has waited. /*from  www  .ja  v a 2s.  c  o m*/
 *
 * _The user time is the CPU time charged for the execution of user
 *  instructions of the calling process. The system time is the CPU
 *  time charged for execution by the system on behalf of the calling
 *  process._
 */
@Builtin("proc.time")
public static DoubleVector procTime() {

    DoubleArrayVector.Builder result = new DoubleArrayVector.Builder();
    StringVector.Builder names = new StringVector.Builder();

    long totalCPUTime;
    long userCPUTime;
    long elapsedTime;

    // There doesn't seem to be any platform-independent way of accessing
    // CPU use for the whole JVM process, so we'll have to make do
    // with the timings for the thread we're running on.
    //
    // Additionally, the MX Beans may not be available in all environments,
    // so we need to fallback to app
    try {
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        totalCPUTime = threadMXBean.getCurrentThreadCpuTime();
        userCPUTime = threadMXBean.getCurrentThreadUserTime();

        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        elapsedTime = runtimeMXBean.getUptime();
    } catch (Error e) {
        // ThreadMXBean is not available in all environments
        // Specifically, AppEngine will throw variously SecurityErrors or
        // ClassNotFoundErrors if we try to access these classes
        userCPUTime = totalCPUTime = java.lang.System.nanoTime();
        elapsedTime = new Date().getTime();
    }

    // user.self
    names.add("user.self");
    result.add(userCPUTime / NANOSECONDS_PER_SECOND);

    // sys.self
    names.add("sys.self");
    result.add((totalCPUTime - userCPUTime) / NANOSECONDS_PER_SECOND);

    // elapsed
    // (wall clock time)
    names.add("elapsed");
    result.add(elapsedTime / MILLISECONDS_PER_SECOND);

    // AFAIK, we don't have any platform independent way of accessing
    // this info.

    // user.child
    names.add("user.child");
    result.add(0);

    // sys.child
    names.add("sys.child");
    result.add(0);

    result.setAttribute(Symbols.NAMES, names.build());
    result.setAttribute(Symbols.CLASS, StringVector.valueOf("proc_time"));
    return result.build();

}