@Override
  protected void doShutdown() {

    if (!this.isRunning()) {
      return;
    }

    try {
      synchronized (consumersMonitor) {
        if (this.consumers != null) {
          for (BlockingQueueConsumer consumer : this.consumers.keySet()) {
            consumer.setQuiesce(this.shutdownTimeout);
          }
        }
      }
      logger.info("Waiting for workers to finish.");
      boolean finished = cancellationLock.await(shutdownTimeout, TimeUnit.MILLISECONDS);
      if (finished) {
        logger.info("Successfully waited for workers to finish.");
      } else {
        logger.info("Workers not finished.  Forcing connections to close.");
      }
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      logger.warn("Interrupted waiting for workers.  Continuing with shutdown.");
    }

    synchronized (this.consumersMonitor) {
      this.consumers = null;
    }
  }
 protected void initializeConsumers() {
   synchronized (this.consumersMonitor) {
     if (this.consumers == null) {
       cancellationLock.reset();
       this.consumers = new HashSet<BlockingQueueConsumer>(this.concurrentConsumers);
       for (int i = 0; i < this.concurrentConsumers; i++) {
         BlockingQueueConsumer consumer = createBlockingQueueConsumer();
         this.consumers.add(consumer);
       }
     }
   }
 }
 protected int initializeConsumers() {
   int count = 0;
   synchronized (this.consumersMonitor) {
     if (this.consumers == null) {
       cancellationLock.reset();
       this.consumers = new HashMap<BlockingQueueConsumer, Boolean>(this.concurrentConsumers);
       for (int i = 0; i < this.concurrentConsumers; i++) {
         BlockingQueueConsumer consumer = createBlockingQueueConsumer();
         this.consumers.put(consumer, true);
         count++;
       }
     }
   }
   return count;
 }
 @ManagedMetric(metricType = MetricType.GAUGE)
 public int getActiveConsumerCount() {
   return cancellationLock.getCount();
 }