Example usage for org.apache.zookeeper.jmx MBeanRegistry getInstance

List of usage examples for org.apache.zookeeper.jmx MBeanRegistry getInstance

Introduction

In this page you can find the example usage for org.apache.zookeeper.jmx MBeanRegistry getInstance.

Prototype

public static MBeanRegistry getInstance() 

Source Link

Usage

From source file:org.apache.twill.yarn.SessionExpireTestRun.java

License:Apache License

private boolean expireAppMasterZKSession(TwillController controller, long timeout, TimeUnit timeoutUnit) {
    MBeanServer mbeanServer = MBeanRegistry.getInstance().getPlatformMBeanServer();
    QueryExp query = Query.isInstanceOf(new StringValueExp(ConnectionMXBean.class.getName()));

    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();//from w  w  w.  j  av a  2 s.c  om
    do {
        // Find the AM session and expire it
        Set<ObjectName> connectionBeans = mbeanServer.queryNames(ObjectName.WILDCARD, query);
        for (ObjectName objectName : connectionBeans) {

            ConnectionMXBean connectionBean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
                    objectName, ConnectionMXBean.class, false);
            for (String node : connectionBean.getEphemeralNodes()) {
                if (node.endsWith("/instances/" + controller.getRunId().getId())) {
                    // This is the AM, expire the session.
                    LOG.info("Kill AM session {}", connectionBean.getSessionId());
                    connectionBean.terminateSession();
                    return true;
                }
            }
        }
        Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
    } while (stopwatch.elapsedTime(timeoutUnit) < timeout);

    return false;
}