Пример #1
0
  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();
    }
  }
Пример #2
0
 public BrokerHost getHostForChannel(Channel channel) {
   BrokerHost registeredHost = null;
   lock.lock();
   try {
     if (channel.getDirection() == Direction.OUT) {
       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();
             break;
           }
         }
         if (registeredHost != null) {
           break;
         }
       }
     } else if (channel.getDirection() == Direction.IN) {
       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();
             break;
           }
         }
         if (registeredHost != null) {
           break;
         }
       }
     }
   } finally {
     lock.unlock();
   }
   return registeredHost;
 }