Search in sources :

Example 1 with LifecycleMBean

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
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) LifecycleMBean(org.bboxdb.jmx.LifecycleMBean) HashMap(java.util.HashMap) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Aggregations

HashMap (java.util.HashMap)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 ObjectName (javax.management.ObjectName)1 JMXConnector (javax.management.remote.JMXConnector)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1 LifecycleMBean (org.bboxdb.jmx.LifecycleMBean)1