ObjectName objectName = OBJECT_NAME;
MBeanServerConnection mbeanServer = getMBeanServerConnection();
ServiceContainerMXBean proxy = MBeanProxy.get(mbeanServer, objectName, ServiceContainerMXBean.class);
State currentState = State.valueOf(proxy.getServiceStatus(serviceName.getCanonicalName()).getStateName());
while (timeout > 0 && currentState != expectedState) {
// TODO: Change this to use mbean notifications
Thread.sleep(100);
timeout -= 100;
currentState = State.valueOf(proxy.getServiceStatus(serviceName.getCanonicalName()).getStateName());