List of usage examples for java.lang.management ManagementFactory getRuntimeMXBean
public static RuntimeMXBean getRuntimeMXBean()
From source file:net.centro.rtb.monitoringcenter.infos.JvmInfo.java
public static JvmInfo create() { JvmInfo jvmInfo = new JvmInfo(); jvmInfo.specVersion = SystemUtils.JAVA_SPECIFICATION_VERSION; jvmInfo.classVersion = SystemUtils.JAVA_CLASS_VERSION; jvmInfo.jreVersion = SystemUtils.JAVA_VERSION; jvmInfo.jreVendor = SystemUtils.JAVA_VENDOR; jvmInfo.vmName = SystemUtils.JAVA_VM_NAME; jvmInfo.vmVendor = SystemUtils.JAVA_VM_VENDOR; jvmInfo.vmVersion = SystemUtils.JAVA_VM_VERSION; RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); jvmInfo.inputArguments = new ArrayList<>(runtimeMXBean.getInputArguments()); jvmInfo.startedTimestamp = new Date(runtimeMXBean.getStartTime()); jvmInfo.defaultTimeZone = TimeZone.getDefault().getID(); jvmInfo.defaultCharset = Charset.defaultCharset().displayName(); return jvmInfo; }
From source file:org.apache.hadoop.chukwa.inputtools.mdl.LoaderServer.java
public void init() throws IOException { String pidLong = ManagementFactory.getRuntimeMXBean().getName(); String[] items = pidLong.split("@"); String pid = items[0];// w w w . j ava2 s .c om String chukwaPath = System.getProperty("CHUKWA_HOME"); StringBuffer pidFilesb = new StringBuffer(); pidFilesb.append(chukwaPath).append("/var/run/").append(name).append(".pid"); try { File pidFile = new File(pidFilesb.toString()); pidFileOutput = new FileOutputStream(pidFile); pidFileOutput.write(pid.getBytes()); pidFileOutput.flush(); FileChannel channel = pidFileOutput.getChannel(); LoaderServer.lock = channel.tryLock(); if (LoaderServer.lock != null) { log.info("Initlization succeeded..."); } else { throw (new IOException()); } } catch (IOException ex) { System.out.println("Initializaiton failed: can not write pid file."); log.error("Initialization failed..."); log.error(ex.getMessage()); System.exit(-1); throw ex; } }
From source file:com.roche.iceboar.settings.GlobalSettingsFactory.java
/** * Reads system properties (incl. those specified in JNLP file). * * @param args// www . j a va2 s . c o m */ public static GlobalSettings getGlobalSettings(String[] args) { long jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime(); String codeBase = getCodeBase(); Properties properties = System.getProperties(); boolean showDebug = getShowDebug(properties); String frameTitle = properties.getProperty(JNLP_FRAME_TITLE, DEFAULT_FRAME_TITLE); String currentJavaVersion = properties.getProperty(JAVA_VERSION); String targetJavaVersion = getTargetJavaVersion(currentJavaVersion, properties); String tempDirectory = properties.getProperty(TEMP_DIRECTORY); String mainClass = properties.getProperty(JNLP_MAIN_CLASS); String targetJavaURL = getTargetJavaUrl(codeBase, properties); List<String> jarURLs = getDependenciesJars(codeBase, properties); List<String> allPropertiesForTarget = getAllPropertiesForTarget(properties); String initialHeapSize = properties.getProperty(JNLP_INITIAL_HEAP_SIZE); String maxHeapSize = properties.getProperty(JNLP_MAX_HEAP_SIZE); String javaVmArgs = properties.getProperty(JNLP_JAVA_VM_ARGS); String operationSystemName = properties.getProperty(OS_NAME); String pathSeparator = properties.getProperty(PATH_SEPARATOR); boolean closeOnEnd = getCloseOnEnd(properties); String cachePath = tempDirectory + ".IceBoar.cache"; CacheStatus cacheStatus = getCacheStatus(cachePath); List<String> icons = getIcons(codeBase, properties); String splash = getSplashScreen(codeBase, properties); boolean hideFrameBorder = getHideFrameBorder(properties); GlobalSettings settings = GlobalSettings.builder().applicationArguments(args).jvmStartTime(jvmStartTime) .showDebug(showDebug).frameTitle(frameTitle).currentJavaVersion(currentJavaVersion) .targetJavaVersion(targetJavaVersion).tempDirectory(tempDirectory).mainClass(mainClass) .targetJavaURL(targetJavaURL).jarURLs(jarURLs).allPropertiesForTarget(allPropertiesForTarget) .operationSystemName(operationSystemName).pathSeparator(pathSeparator) .initialHeapSize(initialHeapSize).maxHeapSize(maxHeapSize).javaVmArgs(javaVmArgs) .closeOnEnd(closeOnEnd).cachePath(cachePath).cacheStatus(cacheStatus).icons(icons) .customSplashImage(splash).hideFrameBorder(hideFrameBorder).build(); return settings; }
From source file:org.bonitasoft.engine.classloader.BonitaClassLoaderTest.java
@Test public void releaseShouldRemoveAllScopeFolderAndItsContent() throws IOException { final Map<String, byte[]> resources = new HashMap<String, byte[]>(1); resources.put("myJar.jar", "Salut le monde".getBytes()); final File tempDir = new File(IOUtil.TMP_DIRECTORY, "BonitaClassLoaderTest_JVM_" + ManagementFactory.getRuntimeMXBean().getName()); if (tempDir.exists()) { FileUtils.deleteDirectory(tempDir); }//from w w w . j ava 2 s. c om final BonitaClassLoader bonitaClassLoader = new BonitaClassLoader(resources, "here", 154L, tempDir.toURI(), BonitaClassLoader.class.getClassLoader()); assertThat(tempDir).as("bonitaClassLoader tempDir:%s should exists after bonitaClassLoader creation", tempDir.getAbsolutePath()).exists(); // when bonitaClassLoader.destroy(); // then assertThat(tempDir).as("bonitaClassLoader tempDir:%s should not exists after bonitaClassLoader release", tempDir.getAbsolutePath()).doesNotExist(); }
From source file:org.apache.hadoop.chukwa.util.PidFile.java
public void init() throws IOException { String pidLong = ManagementFactory.getRuntimeMXBean().getName(); String[] items = pidLong.split("@"); String pid = items[0];//from ww w .ja v a2 s .c o m String chukwaPath = System.getProperty("CHUKWA_HOME"); StringBuffer pidFilesb = new StringBuffer(); String pidDir = System.getenv("CHUKWA_PID_DIR"); if (pidDir == null) { pidDir = chukwaPath + File.separator + "var" + File.separator + "run"; } pidFilesb.append(pidDir).append(File.separator).append(name).append(".pid"); try { File existsFile = new File(pidDir); if (!existsFile.exists()) { boolean success = (new File(pidDir)).mkdirs(); if (!success) { throw (new IOException()); } } File pidFile = new File(pidFilesb.toString()); pidFileOutput = new FileOutputStream(pidFile); pidFileOutput.write(pid.getBytes()); pidFileOutput.flush(); FileChannel channel = pidFileOutput.getChannel(); PidFile.lock = channel.tryLock(); if (PidFile.lock != null) { log.debug("Initlization succeeded..."); } else { throw (new IOException("Can not get lock on pid file: " + pidFilesb)); } } catch (IOException ex) { System.out.println("Initialization failed: can not write pid file to " + pidFilesb); log.error("Initialization failed..."); log.error(ex.getMessage()); System.exit(-1); throw ex; } }
From source file:org.apache.hadoop.hbase.client.ClientIdGenerator.java
/** * @return PID of the current process, if it can be extracted from JVM name, or null. *//*from w ww . j a v a 2 s . c om*/ public static Long getPid() { String name = ManagementFactory.getRuntimeMXBean().getName(); String[] nameParts = name.split("@"); if (nameParts.length == 2) { // 12345@somewhere try { return Long.parseLong(nameParts[0]); } catch (NumberFormatException ex) { LOG.warn("Failed to get PID from [" + name + "]", ex); } } else { LOG.warn("Don't know how to get PID from [" + name + "]"); } return null; }
From source file:org.springframework.xd.dirt.listener.RedisContainerEventListener.java
@Override protected void onContainerStartedEvent(ContainerStartedEvent event) { String name = ManagementFactory.getRuntimeMXBean().getName(); if (logger.isInfoEnabled()) { logger.info("started container: " + name); }/* w w w . j a v a2s. co m*/ Container container = event.getSource(); this.redisTemplate.boundHashOps("containers").put(container.getId(), name); }
From source file:io.galeb.router.handlers.InfoHandler.java
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); exchange.getResponseHeaders().put(Headers.SERVER, "GALEB"); exchange.setStatusCode(StatusCodes.OK); long uptimeJVM = ManagementFactory.getRuntimeMXBean().getUptime(); String uptime = getUptimeSO(); String version = getClass().getPackage().getImplementationVersion(); Map<String, Object> infoJson = new HashMap<>(); infoJson.put("uptime-so", uptime); infoJson.put("uptime-jvm", uptimeJVM); infoJson.put("version", version); exchange.getResponseSender().send(gson.toJson(infoJson)); exchange.endExchange();/*from w ww. j av a2s . co m*/ }
From source file:org.apache.hms.common.util.PidFile.java
public void init(int port) throws IOException { String pidLong = ManagementFactory.getRuntimeMXBean().getName(); String[] items = pidLong.split("@"); String pid = items[0];/*from ww w .j ava2 s .c om*/ String chukwaPath = System.getProperty("HMS_HOME"); StringBuffer pidFilesb = new StringBuffer(); String pidDir = System.getenv("HMS_PID_DIR"); if (pidDir == null) { pidDir = chukwaPath + File.separator + "var" + File.separator + "run"; } pidFilesb.append(pidDir).append(File.separator).append(name).append(".pid"); try { serverSocket = new ServerSocket(port); File existsFile = new File(pidDir); if (!existsFile.exists()) { boolean success = (new File(pidDir)).mkdirs(); if (!success) { throw (new IOException()); } } File pidFile = new File(pidFilesb.toString()); pidFileOutput = new FileOutputStream(pidFile); pidFileOutput.write(pid.getBytes()); pidFileOutput.flush(); log.debug("Initlization succeeded..."); } catch (IOException ex) { System.out.println("Initialization failed: can not write pid file to " + pidFilesb); log.error("Initialization failed..."); log.error(ex.getMessage()); System.exit(-1); throw ex; } }
From source file:org.apache.ambari.common.util.PidFile.java
public void init(int port) throws IOException { String pidLong = ManagementFactory.getRuntimeMXBean().getName(); String[] items = pidLong.split("@"); String pid = items[0];// w w w .ja v a 2s . c o m String chukwaPath = System.getProperty("AMBARI_HOME"); StringBuffer pidFilesb = new StringBuffer(); String pidDir = System.getenv("AMBARI_PID_DIR"); if (pidDir == null) { pidDir = chukwaPath + File.separator + "var" + File.separator + "run"; } pidFilesb.append(pidDir).append(File.separator).append(name).append(".pid"); try { serverSocket = new ServerSocket(port); File existsFile = new File(pidDir); if (!existsFile.exists()) { boolean success = (new File(pidDir)).mkdirs(); if (!success) { throw (new IOException()); } } File pidFile = new File(pidFilesb.toString()); pidFileOutput = new FileOutputStream(pidFile); pidFileOutput.write(pid.getBytes()); pidFileOutput.flush(); log.debug("Initlization succeeded..."); } catch (IOException ex) { System.out.println("Initialization failed: can not write pid file to " + pidFilesb); log.error("Initialization failed..."); log.error(ex.getMessage()); System.exit(-1); throw ex; } }