Exemplo n.º 1
0
  /**
   * Check the messenger to the remote peer and attempt to re-create the messenger if necessary.
   *
   * @return {@code true} if the current messenger is adequate.
   * @throws IOException is thrown for errors in creating a new messenger.
   */
  private synchronized boolean checkMessenger() throws IOException {
    if ((destMessenger != null) && ((destMessenger.getState() & Messenger.USABLE) != 0)) {
      // Everything fine!
      return true;
    }

    // Try making a direct messenger first.
    if (route != null) {
      destMessenger = endpoint.getDirectMessenger(destination, route, true);
    }

    // Try making a regular messenger if that didn't work.
    if ((destMessenger == null) || ((destMessenger.getState() & Messenger.TERMINAL) != 0)) {
      destMessenger = null;
      destMessenger = endpoint.getMessenger(destination, route);
    }

    // Dismal failure
    if ((destMessenger == null) || ((destMessenger.getState() & Messenger.TERMINAL) != 0)) {
      destMessenger = null;
      throw new IOException("Unable to create a messenger to " + destination.toString());
    }

    return true;
  }
Exemplo n.º 2
0
  /**
   * Return a messenger suitable for sending to this peer.
   *
   * @return a messenger to this PVE peer or if <code>null</code> if peer is unreachable.
   */
  private Messenger getCachedMessenger() {

    boolean updateAlive = false;

    synchronized (this) {
      if ((null == cachedMessenger) || cachedMessenger.isClosed()) {
        cachedMessenger = null;

        if (LOG.isEnabledFor(Level.DEBUG)) {
          LOG.debug("Getting cached Messenger for " + radv.getName());
        }

        updateAlive = true;
        cachedMessenger = endpoint.getMessenger(getDestAddress(), radv.getRouteAdv());
      }
    }

    if (updateAlive) {
      setAlive(null != cachedMessenger);
    }

    return cachedMessenger;
  }