if (!started.compareAndSet(true, false)) {
return;
}
LOG.info("ActiveMQ Message Broker (" + getBrokerName() + ", " + brokerId + ") is shutting down");
removeShutdownHook();
ServiceStopper stopper = new ServiceStopper();
if (services != null) {
for (Service service: services) {
stopper.stop(service);
}
}
stopAllConnectors(stopper);
stopper.stop(persistenceAdapter);
if (broker != null) {
stopper.stop(broker);
}
if (tempDataStore != null) {
tempDataStore.close();
}
if (isUseJmx()) {
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
if (mbeanServer != null) {
for (Iterator<ObjectName> iter = registeredMBeanNames.iterator(); iter.hasNext();) {
ObjectName name = iter.next();
try {
mbeanServer.unregisterMBean(name);
} catch (Exception e) {
stopper.onException(mbeanServer, e);
}
}
}
stopper.stop(getManagementContext());
}
// remove any VMTransports connected
// this has to be done after services are stopped,
// to avoid timimg issue with discovery (spinning up a new instance)
BrokerRegistry.getInstance().unbind(getBrokerName());
VMTransportFactory.stopped(getBrokerName());
stopped.set(true);
stoppedLatch.countDown();
LOG.info("ActiveMQ JMS Message Broker (" + getBrokerName() + ", " + brokerId + ") stopped");
stopper.throwFirstException();
}