List of usage examples for java.lang.management ManagementFactory getRuntimeMXBean
public static RuntimeMXBean getRuntimeMXBean()
From source file:com.opengamma.web.WebAbout.java
/** * Gets the JVM input arguments.//from w w w.j a v a 2 s . c o m * @return the JVM input arguments */ public List<String> getJvmArguments() { List<String> args = new ArrayList<>(ManagementFactory.getRuntimeMXBean().getInputArguments()); for (ListIterator<String> it = args.listIterator(); it.hasNext();) { String arg = it.next(); if (arg.contains("secret") || arg.contains("password")) { int index = arg.indexOf("secret") + 6; if (index < 0) { index = arg.indexOf("password") + 8; } it.set(arg.substring(0, index) + "*************"); } } return args; }
From source file:lineage2.gameserver.network.telnet.commands.TelnetStatus.java
/** * Method getStartTime./*from w w w. j a v a 2 s . com*/ * @return String */ public static String getStartTime() { return new Date(ManagementFactory.getRuntimeMXBean().getStartTime()).toString(); }
From source file:org.alfresco.reporting.cron.HarvestingJob.java
public void executeImpl(AtomicBoolean running, JobExecutionContext context) throws JobExecutionException { // actually do what needs to be done final JobDataMap jobData = context.getJobDetail().getJobDataMap(); final String frequency = jobData.getString("frequency"); int startupDelayMillis = 0; startupDelayMillis = Integer.parseInt(jobData.getString("startDelayMinutes")) * 60000; // wait system i starting RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); logger.info("Uptime: " + rb.getUptime() + ", wait for: " + startupDelayMillis + ", lets go=" + (startupDelayMillis < rb.getUptime())); if (startupDelayMillis < rb.getUptime()) { logger.info("--> Go!"); // we are x minutes after startup of the repository, lets roll! AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>() { public Void doWork() { try { if (frequency != null) { Action action = actionService.createAction(HarvestingExecuter.NAME); if (frequency != null) { action.setParameterValue(HarvestingExecuter.PARAM_FREQUENCY, frequency); } // end if frequency!=null actionService.executeAction(action, null); } // end if frequency!=null } catch (Exception e) { // do nothing }//w w w .jav a 2s.c om return null; } // end doWork }, AuthenticationUtil.getSystemUserName()); } else { logger.info( "Hey relax! Its too early to work... Let the repository get up first... Aborting this run."); } }
From source file:org.nuxeo.ecm.admin.SystemInfoManager.java
public String getUptime() { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); long ut = bean.getUptime(); long uts = ut / 1000; StringBuffer sb = new StringBuffer("Nuxeo Server UpTime : "); long nbDays = uts / (24 * 3600); if (nbDays > 0) { sb.append(nbDays + " days, "); uts = uts % (24 * 3600);/*w w w. j av a2 s .c om*/ } long nbHours = uts / 3600; sb.append(nbHours + " h "); uts = uts % 3600; long nbMin = uts / 60; sb.append(nbMin + " m "); uts = uts % 60; sb.append(uts + " s "); return sb.toString(); }
From source file:com.alibaba.wasp.zookeeper.RecoverableZooKeeper.java
public RecoverableZooKeeper(String quorumServers, int sessionTimeout, Watcher watcher, int maxRetries, int retryIntervalMillis) throws IOException { this.zk = new ZooKeeper(quorumServers, sessionTimeout, watcher); this.retryCounterFactory = new RetryCounterFactory(maxRetries, retryIntervalMillis); // the identifier = processID@hostName this.identifier = ManagementFactory.getRuntimeMXBean().getName(); LOG.info("The identifier of this process is " + identifier); this.id = Bytes.toBytes(identifier); this.watcher = watcher; this.sessionTimeout = sessionTimeout; this.quorumServers = quorumServers; salter = new SecureRandom(); }
From source file:org.pepstock.jem.node.affinity.SystemInfo.java
/** * Returns a properties object with network information.<br> * Keys are:<br>// w ww. java 2 s . co m * <ul> * <li><code>ipaddresses</code>: list of ipaddresses of system</li> * <li><code>hostnames</code>: list of hostnames of system</li> * </ul> * * @return a mapping of environment variables to their value. */ public Properties getNetworkProperties() { // if the instance is null, // creates a new instance // otherwise it returns the previous instance if (network == null) { network = new Properties(); try { List<InetAddress> list = loadInetAddress(); // gets hostname from management String hostname = StringUtils.substringAfter(ManagementFactory.getRuntimeMXBean().getName(), "@"); // adds all ip addresses, formatting them network.setProperty("ipaddresses", formatAddresses(list)); network.setProperty("hostnames", hostname); } catch (Exception e) { // debug LogAppl.getInstance().debug(e.getMessage(), e); } } return network; }
From source file:org.opendaylight.md.controller.topology.lldp.utils.LLDPDiscoveryUtils.java
/** * @param nodeConnectorId/*from ww w. j a va 2s. c o m*/ * @return extra authenticator for lldp security * @throws NoSuchAlgorithmException */ public static byte[] getValueForLLDPPacketIntegrityEnsuring(final NodeConnectorId nodeConnectorId) throws NoSuchAlgorithmException { final String pureValue = nodeConnectorId + ManagementFactory.getRuntimeMXBean().getName(); final byte[] pureBytes = pureValue.getBytes(); HashFunction hashFunction = Hashing.md5(); Hasher hasher = hashFunction.newHasher(); HashCode hashedValue = hasher.putBytes(pureBytes).hash(); return hashedValue.asBytes(); }
From source file:hudson.util.DoubleLaunchChecker.java
/** * Figures out a string that identifies this instance of Hudson. *//*from www. ja v a 2 s . c o m*/ public String getId() { Hudson h = Hudson.getInstance(); // in servlet 2.5, we can get the context path String contextPath = ""; try { Method m = ServletContext.class.getMethod("getContextPath"); contextPath = (String) m.invoke(h.servletContext); } catch (Exception e) { // maybe running with Servlet 2.4 } return h.hashCode() + contextPath + " at " + ManagementFactory.getRuntimeMXBean().getName(); }
From source file:org.nebula.framework.core.HeartbeatWorker.java
private void acquireProcessId() { try {//w w w. j a v a2 s. c o m processId = ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; } catch (Exception e) { // ignore } }
From source file:org.pepstock.jem.ant.tasks.StepListener.java
/** * Called by ANT engine when job is started.<br> * Notifies to JEM the job is starting, passing process id and receiving the * authorizations of job user instance.//from w w w. j a v a 2 s. co m * * @param event ANT event */ @Override public void buildStarted(BuildEvent event) { if (door == null) { // get port number from env var // AntTask has passed and set this information (MUST) String port = System.getProperty(RmiKeys.JEM_RMI_PORT); try { // creates RMI connection with localhost (default) and using // port number. // if port is null or not a number, -1 is return and a RMI // Exception will occur RegistryLocator locator = new RegistryLocator(Parser.parseInt(port, -1)); // check the taskdoor object is binded, if not, a exception // occurs if (locator.hasRmiObject(TasksDoor.NAME)) { // gets remote object door = (TasksDoor) locator.getRmiObject(TasksDoor.NAME); // send to JEM node the current process id. // uses JMX implementation of JDK. // BE CAREFUL! Not all JVM returns the value in same format // receives all roles for job user and stores in a static // reference // of realm JobStartedObjects objects = door.setJobStarted(JobId.VALUE, ManagementFactory.getRuntimeMXBean().getName()); // PAY attention: after creating data paths container // calls a getabsolutepath method to load all necessary classes in classloader. // This is MANDATORY to avoid StackOverFlow in the SecurityManager // during the CheckRead on files. DataPathsContainer.createInstance(objects.getStorageGroupsManager()); DataPathsContainer.getInstance().getAbsoluteDataPath(JobId.VALUE); // loads data paths as properties int index = 0; for (String dataName : DataPathsContainer.getInstance().getDataPathsNames()) { String path = DataPathsContainer.getInstance().getDataPaths().get(index); String property = ConfigKeys.JEM_DATA_PATH_NAME + "." + dataName; System.setProperty(property, path); index++; } Collection<Role> myroles = objects.getRoles(); // check if is already instantiated. If yes, does nothing if (System.getSecurityManager() == null) { System.setSecurityManager(new AntBatchSecurityManager(myroles)); } else { throw new BuildException(AntMessage.JEMA039E.toMessage().getMessage()); } } else { throw new BuildException(AntMessage.JEMA038E.toMessage().getFormattedMessage(TasksDoor.NAME)); } // sets the SM for internal actions AntBatchSecurityManager batchSM = (AntBatchSecurityManager) System.getSecurityManager(); // sets internal action to true so it can perform same authorized action batchSM.setInternalAction(true); // creates the locker to lock resources locker = new Locker(); // sets internal action to false batchSM.setInternalAction(false); } catch (AntException e) { throw new BuildException(AntMessage.JEMA040E.toMessage().getFormattedMessage(e.getMessage()), e); } catch (RemoteException e) { throw new BuildException(AntMessage.JEMA040E.toMessage().getFormattedMessage(e.getMessage()), e); } catch (UnknownHostException e) { throw new BuildException(AntMessage.JEMA040E.toMessage().getFormattedMessage(e.getMessage()), e); } } }