// @NOTE keep flush private the preQ is not threadsafe
  private void flush(SessionWrapper sessW) {
    // disconnected drop any session messages
    // optionally keep any other messages or reject back  upstream

    final Session session = sessW._session;
    final MessageQueue queue = sessW._queue;
    final MessageQueue preQ = sessW._preQueue;
    final MessageQueue syncQ = sessW._syncQueue;

    while (!syncQ.isEmpty()) {
      syncQ.next(); // DISCARD
    }

    Message head = null;
    Message tail = null;

    while (!queue.isEmpty()) {
      Message msg = queue.next();
      if (msg.getReusableType() == CoreReusableType.NullMessage) break;

      if (session.discardOnDisconnect(msg) == false) {
        if (session.rejectMessageUpstream(msg, DISCONNECTED)) {
          // message recycled by successful reject processing
        } else {
          if (tail == null) {
            head = msg;
            tail = msg;
          } else {
            tail.attachQueue(msg);
            tail = msg;
          }
        }
      } else {
        _logMsg.copy(DROP_MSG).append(msg.getReusableType().toString());
        _log.info(_logMsg);
        session.outboundRecycle(msg);
      }
    }

    // move remaining messages to the preQ

    if (head != null) {
      Message tmp = head;

      while (tmp != null) {
        Message next = tmp.getNextQueueEntry();
        tmp.detachQueue();
        preQ.add(tmp);
        tmp = next;
      }
    }
  }
  @Override
  public void handlerStatusChange(MessageHandler handler, boolean connected) {
    final int numSessions = _sessions.length;

    boolean allDisconnected = true;

    for (int i = 0; i < numSessions; i++) {
      SessionWrapper sessW = _sessions[i];

      if (sessW._session == handler) {
        if (connected != sessW._connected) {
          final NonBlockingSession sess = sessW._session;

          _log.info(
              "MultiSession OutDispatcher "
                  + getComponentId()
                  + " : "
                  + ((connected) ? "CONNECTED" : "DISCONNECTED")
                  + " with "
                  + sess.getComponentId()
                  + ", canHandle="
                  + sess.canHandle()
                  + ", isLoggedIn="
                  + sess.isLoggedIn());

          sessW._connected = connected;
        }
      }

      if (sessW._connected) {
        allDisconnected = false;
      }
    }

    _fullyFlushed = false;

    synchronized (_disconnectLock) { // force mem barrier
      _allDisconnected = allDisconnected;
    }

    _ctl.statusChange();
  }