示例#1
0
  /**
   * Send a message to the peer which is represented by the current PeerViewElement.
   *
   * @param msg the message to send
   * @param serviceName the service name on the destination peer to which the message will be
   *     demultiplexed
   * @param serviceParam the service param on the destination peer to which the message will be
   *     demultiplexed
   * @return true if the message was successfully handed off to the endpoint for delivery, false
   *     otherwise
   */
  public boolean sendMessage(Message msg, String serviceName, String serviceParam) {

    if (throttling) {
      if (LOG.isEnabledFor(Level.WARN)) {
        LOG.warn("Declining to send -- throttling on " + this);
      }
      return false;
    }

    Messenger sendVia = getCachedMessenger();

    if (null == sendVia) {
      // There is nothing really we can do.
      if (LOG.isEnabledFor(Level.WARN)) {
        LOG.warn("Could not get messenger for " + getDestAddress());
      }

      OutgoingMessageEvent event =
          new OutgoingMessageEvent(
              msg, new IOException("Couldn't get messenger for " + getDestAddress()));

      messageSendFailed(event);
      return false;
    }

    sendVia.sendMessage(msg, serviceName, serviceParam, this);

    return true;
  }