public CountDownLatch removeDestination(final String name) {
CountDownLatch latch = null;
final ServiceName serviceName = this.destinations.get(name);
if (serviceName != null) {
ServiceRegistry registry = getUnit().getServiceRegistry();
ServiceController dest = registry.getService(serviceName);
ServiceName globalName = QueueInstaller.queueServiceName(name);
if (dest != null) {
ServiceController globalDest = registry.getService(globalName);
if (globalDest == null) {
globalName = TopicInstaller.topicServiceName(name);
globalDest = registry.getService(globalName);
}
if (globalDest == null) {
//should never happen, but...
throw new IllegalStateException("Failed to find global dest for " + name);
}
Object service = globalDest.getService();
//force it to destroy, even if it's durable
if (service instanceof Destroyable) {
((Destroyable) service).setShouldDestroy(true);
}