return expected.cast(o);
}
private MBeanServerConnection getMBeanServerConnection(ServerIdentity server) throws Exception {
// Poke the running server directly for its binding config
final ModelNode address = new ModelNode();
address.add("host", server.getHostName());
address.add("server", server.getServerName());
address.add("socket-binding-group", "*");
final ModelNode operation = new ModelNode();
operation.get(OP).set(READ_RESOURCE_OPERATION);
operation.get(OP_ADDR).set(address);
operation.get(RECURSIVE).set(true);
final ModelNode result = executeForResult(operation);
final int portOffset = result.get("step-1", RESULT, PORT_OFFSET).asInt(0);
final int port = result.get("step-1", RESULT, SOCKET_BINDING, "jmx-connector-registry", PORT).asInt() + portOffset;
final String addr = "localhost"; // TODO determine the interface binding
String url = String.format("service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi", addr, port);
return JMXConnectorFactory.connect(new JMXServiceURL(url),