protected synchronized void stopDispatching(boolean checkQueue) {
    if (isStopped()) {
      return;
    }

    if (logger.isDebugEnabled()) {
      logger.debug("{}: Stopping dispatching", this);
    }
    if (!checkQueue) {
      basicStopDispatching();
      return;
    }

    // Stay alive until the queue is empty or a number of peeks is reached.
    try {
      for (int numberOfPeeks =
          0; numberOfPeeks < CacheClientProxy.MAXIMUM_SHUTDOWN_PEEKS; ++numberOfPeeks) {
        boolean interrupted = Thread.interrupted();
        try {
          List<?> events = _messageQueue.peek(1, -1);
          if (events == null || events.size() == 0) {
            break;
          }
          if (logger.isDebugEnabled()) {
            logger.debug("Waiting for client to drain queue: {}", _proxy.proxyID);
          }
          Thread.sleep(500);
        } catch (InterruptedException e) {
          interrupted = true;
        } catch (CancelException e) {
          break;
        } catch (CacheException e) {
          if (logger.isDebugEnabled()) {
            logger.debug("{}: Exception occurred while trying to stop dispatching", this, e);
          }
        } finally {
          if (interrupted) {
            Thread.currentThread().interrupt();
          }
        }
      } // for
    } finally {
      basicStopDispatching();
    }
  }
Notifies the dispatcher to stop dispatching.

@param checkQueue Whether to check the message queue for any unprocessed messages and process
       them for MAXIMUM_SHUTDOWN_PEEKS.

@see CacheClientProxy#MAXIMUM_SHUTDOWN_PEEKS
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/MessageDispatcher.java