
com.sirolf2009.util.jmx.JMXUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of util Show documentation
Show all versions of util Show documentation
A collection of my common utilities
The newest version!
package com.sirolf2009.util.jmx;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.rmi.registry.LocateRegistry;
import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Exceptions;
@SuppressWarnings("all")
public class JMXUtil {
public static ObjectInstance registerObject(final Object object, final String name) {
try {
MBeanServer _platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName _objectName = new ObjectName(name);
return _platformMBeanServer.registerMBean(object, _objectName);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
public static void startJMX(final int port) throws IOException {
LocateRegistry.createRegistry(port);
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXConnectorServerFactory.newJMXConnectorServer(JMXUtil.getURLForPort(port), null, mbs).start();
}
public static JMXServiceURL getURLForPort(final int port) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("service:jmx:rmi://localhost/jndi/rmi://localhost:");
_builder.append(port);
_builder.append("/jmxrmi");
return new JMXServiceURL(_builder.toString());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy