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;
}
}
}
} while (stopwatch.elapsedTime(timeoutUnit) < timeout);