/**
   * Distribute the message. If the dest is local, it blocks until its passed to the target
   * ClientConnectionRunner (which then fires it into a MessageReceivedJob). If the dest is remote,
   * it blocks until it is added into the ClientMessagePool
   */
  MessageId distributeMessage(SendMessageMessage message) {
    Payload payload = message.getPayload();
    Destination dest = message.getDestination();
    MessageId id = new MessageId();
    id.setMessageId(getNextMessageId());
    long expiration = 0;
    int flags = 0;
    if (message.getType() == SendMessageExpiresMessage.MESSAGE_TYPE) {
      SendMessageExpiresMessage msg = (SendMessageExpiresMessage) message;
      expiration = msg.getExpirationTime();
      flags = msg.getFlags();
    }
    if (message.getNonce() != 0 && !_dontSendMSM) _acceptedPending.add(id);

    if (_log.shouldLog(Log.DEBUG))
      _log.debug(
          "** Receiving message "
              + id.getMessageId()
              + " with payload of size "
              + payload.getSize()
              + " for session "
              + _sessionId.getSessionId());
    // long beforeDistribute = _context.clock().now();
    // the following blocks as described above
    SessionConfig cfg = _config;
    if (cfg != null)
      _manager.distributeMessage(cfg.getDestination(), dest, payload, id, expiration, flags);
    // else log error?
    // long timeToDistribute = _context.clock().now() - beforeDistribute;
    // if (_log.shouldLog(Log.DEBUG))
    //    _log.warn("Time to distribute in the manager to "
    //              + dest.calculateHash().toBase64() + ": "
    //              + timeToDistribute);
    return id;
  }