use of java.lang.management.RuntimeMXBean in project tdi-studio-se by Talend.
the class Agent method getAgentJar.
/**
* Gets the agent jar file from input arguments.
*
* @return The agent jar file
*/
private static String getAgentJar() {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMXBean.getInputArguments();
for (String argument : arguments) {
if (argument.contains(Constants.JAVA_AGENT_OPTION)) {
return argument.replace(Constants.JAVA_AGENT_OPTION, "");
}
}
throw new IllegalStateException();
}
use of java.lang.management.RuntimeMXBean in project voltdb by VoltDB.
the class DirectMemoryUtils method getDirectMemorySize.
/**
* @return the setting of -XX:MaxDirectMemorySize as a long. Returns 0 if
* -XX:MaxDirectMemorySize is not set.
*/
public static long getDirectMemorySize() {
RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = RuntimemxBean.getInputArguments();
//for the byte case.
long multiplier = 1;
for (String s : arguments) {
if (s.contains("-XX:MaxDirectMemorySize=")) {
String memSize = s.toLowerCase().replace("-xx:maxdirectmemorysize=", "").trim();
if (memSize.contains("k")) {
multiplier = 1024;
} else if (memSize.contains("m")) {
multiplier = 1048576;
} else if (memSize.contains("g")) {
multiplier = 1073741824;
}
memSize = memSize.replaceAll("[^\\d]", "");
long retValue = Long.parseLong(memSize);
return retValue * multiplier;
}
}
return 0;
}
use of java.lang.management.RuntimeMXBean in project jdk8u_jdk by JetBrains.
the class TestManager method connect.
private static void connect(String pid, String address) throws Exception {
if (address == null) {
throw new RuntimeException("Local connector address for " + pid + " is null");
}
System.out.println("Connect to process " + pid + " via: " + address);
JMXServiceURL url = new JMXServiceURL(address);
JMXConnector c = JMXConnectorFactory.connect(url);
MBeanServerConnection server = c.getMBeanServerConnection();
System.out.println("Connected.");
RuntimeMXBean rt = newPlatformMXBeanProxy(server, RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
System.out.println(rt.getName());
// close the connection
c.close();
}
use of java.lang.management.RuntimeMXBean in project jdk8u_jdk by JetBrains.
the class MXBeanProxyTest method main.
public static void main(String[] argv) throws Exception {
boolean iae = false;
try {
// Get a MXBean proxy with invalid name
newPlatformMXBeanProxy(server, "Invalid ObjectName", RuntimeMXBean.class);
} catch (IllegalArgumentException e) {
// Expected exception
System.out.println("EXPECTED: " + e);
iae = true;
}
if (!iae) {
throw new RuntimeException("Invalid ObjectName " + " was not detected");
}
try {
// Get a MXBean proxy with non existent MXBean
newPlatformMXBeanProxy(server, "java.lang:type=Foo", RuntimeMXBean.class);
iae = false;
} catch (IllegalArgumentException e) {
// Expected exception
System.out.println("EXPECTED: " + e);
iae = true;
}
if (!iae) {
throw new RuntimeException("Non existent MXBean " + " was not detected");
}
try {
// Mismatch MXBean interface
newPlatformMXBeanProxy(server, RUNTIME_MXBEAN_NAME, ClassLoadingMXBean.class);
iae = false;
} catch (IllegalArgumentException e) {
// Expected exception
System.out.println("EXPECTED: " + e);
iae = true;
}
if (!iae) {
throw new RuntimeException("Mismatched MXBean interface " + " was not detected");
}
final FooMBean foo = new Foo();
final ObjectName objName = new ObjectName("java.lang:type=Foo");
server.registerMBean(foo, objName);
try {
// non-platform MXBean
newPlatformMXBeanProxy(server, "java.lang:type=Foo", FooMBean.class);
iae = false;
} catch (IllegalArgumentException e) {
// Expected exception
System.out.println("EXPECTED: " + e);
iae = true;
}
if (!iae) {
throw new RuntimeException("Non-platform MXBean " + " was not detected");
}
// Successfully get MXBean
RuntimeMXBean rm = newPlatformMXBeanProxy(server, RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
System.out.println("VM uptime = " + rm.getUptime());
System.out.println("Test passed.");
}
use of java.lang.management.RuntimeMXBean in project jdk8u_jdk by JetBrains.
the class ProcessTools method getProcessId.
/**
* Get the process id of the current running Java process
*
* @return Process id
*/
public static int getProcessId() throws Exception {
// Get the current process id using a reflection hack
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
Field jvm = runtime.getClass().getDeclaredField("jvm");
jvm.setAccessible(true);
VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);
Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");
pid_method.setAccessible(true);
int pid = (Integer) pid_method.invoke(mgmt);
return pid;
}
Aggregations