removeShutdownHook();
if (this.scheduler != null) {
this.scheduler.stop();
this.scheduler = null;
}
ServiceStopper stopper = new ServiceStopper();
if (services != null) {
for (Service service : services) {
stopper.stop(service);
}
}
stopAllConnectors(stopper);
// remove any VMTransports connected
// this has to be done after services are stopped,
// to avoid timing issue with discovery (spinning up a new instance)
BrokerRegistry.getInstance().unbind(getBrokerName());
VMTransportFactory.stopped(getBrokerName());
if (broker != null) {
stopper.stop(broker);
broker = null;
}
if (jobSchedulerStore != null) {
jobSchedulerStore.stop();
jobSchedulerStore = null;
}
if (tempDataStore != null) {
tempDataStore.stop();
tempDataStore = null;
}
try {
stopper.stop(persistenceAdapter);
persistenceAdapter = null;
if (isUseJmx()) {
stopper.stop(getManagementContext());
managementContext = null;
}
// Clear SelectorParser cache to free memory
SelectorParser.clearCache();
} finally {
started.set(false);
stopped.set(true);
stoppedLatch.countDown();
}
if (this.taskRunnerFactory != null) {
this.taskRunnerFactory.shutdown();
this.taskRunnerFactory = null;
}
if (this.executor != null) {
ThreadPoolUtils.shutdownNow(executor);
this.executor = null;
}
this.destinationInterceptors = null;
this.destinationFactory = null;
if (LOG.isInfoEnabled()) {
if (startDate != null) {
LOG.info("Apache ActiveMQ " + getBrokerVersion() + " ("
+ getBrokerName() + ", " + brokerId + ") uptime " + getUptime());
}
LOG.info("Apache ActiveMQ " + getBrokerVersion() + " ("
+ getBrokerName() + ", " + brokerId + ") is shutdown");
}
synchronized (shutdownHooks) {
for (Runnable hook : shutdownHooks) {
try {
hook.run();
} catch (Throwable e) {
stopper.onException(hook, e);
}
}
}
MDC.remove("activemq.broker");
// and clear start date
startDate = null;
stopper.throwFirstException();
}