@Override
 public Response processRemoveSession(SessionId id, long lastDeliveredSequenceId)
     throws Exception {
   SessionState session = state.getSessionState(id);
   if (session == null) {
     throw new IllegalStateException("Cannot remove session that had not been registered: " + id);
   }
   // Don't let new consumers or producers get added while we are closing
   // this down.
   session.shutdown();
   // Cascade the connection stop to the consumers and producers.
   for (ConsumerId consumerId : session.getConsumerIds()) {
     try {
       processRemoveConsumer(consumerId, lastDeliveredSequenceId);
     } catch (Throwable e) {
       // LOG.warn("Failed to remove consumer: {}", consumerId, e);
     }
   }
   for (ProducerId producerId : session.getProducerIds()) {
     try {
       processRemoveProducer(producerId);
     } catch (Throwable e) {
       // LOG.warn("Failed to remove producer: {}", producerId, e);
     }
   }
   state.removeSession(id);
   protocolManager.removeSession(context, session.getInfo());
   return null;
 }
 public int getConsumerCount() {
   int result = 0;
   for (SessionId sessionId : state.getSessionIds()) {
     SessionState sessionState = state.getSessionState(sessionId);
     if (sessionState != null) {
       result += sessionState.getConsumerIds().size();
     }
   }
   return result;
 }