use of org.bboxdb.jmx.LifecycleMBean in project bboxdb by jnidzwetzki.
the class Shutdown method main.
/**
* Call the JMX service to shutdown the application
*
* @param args
*/
public static void main(final String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: Shutdown <Port> <Password>");
System.exit(-1);
}
final int jmxPort = MathUtil.tryParseIntOrExit(args[0], () -> args[0] + " is not a valid port");
final String password = args[1];
// Set username and password
final Map<String, String[]> env = new HashMap<>();
final String[] credentials = { "controlRoleUser", password };
env.put(JMXConnector.CREDENTIALS, credentials);
// Connect to JMX
System.out.println("Connecting to JMX shutdown service.");
final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + jmxPort + "/jmxrmi");
final JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
final ObjectName mbeanName = new ObjectName(JMXService.MBEAN_LIFECYCLE);
final LifecycleMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, LifecycleMBean.class, true);
try {
mbeanProxy.shutdown();
jmxc.close();
} catch (Exception e) {
// Server performs shutdown, JMX connection will be terminated
// So, ignore exception
}
}
Aggregations