public void stop() { for (Manageable manageable : consumers.values()) { manageable.stop(); } for (Manageable manageable : producers.values()) { manageable.stop(); } }
public void removeChannel(Channel channel) { lock.lock(); try { if (channel.getDirection() == Direction.OUT) { BrokerHost registeredHost = null; for (Map.Entry<BrokerHost, List<Channel>> e : brokerHostToProducerChannelMap.entrySet()) { List<Channel> channels = e.getValue(); Iterator<Channel> channelIterator = channels.iterator(); while (channelIterator.hasNext()) { Channel c = channelIterator.next(); if (c.equals(channel)) { registeredHost = e.getKey(); channelIterator.remove(); // if there are no more channels remove the producer if (channels.size() == 0) { Manageable producer = producers.remove(registeredHost); producer.stop(); } break; } } if (registeredHost != null) { break; } } } else if (channel.getDirection() == Direction.IN) { BrokerHost registeredHost = null; for (Map.Entry<BrokerHost, List<Channel>> e : brokerHostToConsumerChannelMap.entrySet()) { List<Channel> channels = e.getValue(); Iterator<Channel> channelIterator = channels.iterator(); while (channelIterator.hasNext()) { Channel c = channelIterator.next(); if (c.equals(channel)) { registeredHost = e.getKey(); channelIterator.remove(); // if there are no more channels remove the producer if (channels.size() == 0) { ConsumingWorker worker = consumingWorkers.remove(registeredHost); worker.stop(); Manageable consumer = consumers.remove(registeredHost); consumer.stop(); } break; } } if (registeredHost != null) { break; } } } } finally { lock.unlock(); } }