Exemplo n.º 1
0
  /*
   * push all srdi entries to the rednezvous SRDI cache (new connection)
   *@param all if true push all entries, otherwise just deltas
   */
  protected void pushSrdi(String peer, boolean all) {

    SrdiMessage srdiMsg;
    Vector routeIx = new Vector();

    // 10182002tra:Route info don't expire unless the peer disappears
    // This approach is used to limit the SRDI traffic. The key
    // point here is that SRDI is used to tell a peer that another
    // has a route to the destination it is looking for. The information
    // that SRDI cache is not so much the specific route info but rather
    // the fact that a peer has knowledge of a route to another peer
    // We don't want to update the SRDI cache on every route update.
    // The SRDI cache will be flushed when the peer disconnect from
    // the rendezvous.

    // We cannot support concurrent modification of the map while we
    // do that: we must synchronize...
    for (Iterator each = router.getAllRoutedRouteAddresses(); each.hasNext(); ) {
      PeerID pid = router.addr2pid((EndpointAddress) each.next());
      SrdiMessage.Entry entry = new SrdiMessage.Entry(pid.toString(), "", Long.MAX_VALUE);

      routeIx.addElement(entry);
    }

    try {

      // check if we have anything to send
      if (routeIx.size() == 0) {
        return;
      }

      srdiMsg =
          new SrdiMessageImpl(
              group.getPeerID(),
              1, // one hop
              "route",
              routeIx);

      if (LOG.isEnabledFor(Level.DEBUG)) {
        LOG.debug("Sending a SRDI messsage of [All=" + all + "] routes");
      }
      // this will replicate entry to the  SRDI replica peers
      srdi.replicateEntries(srdiMsg);

    } catch (Exception e) {
      if (LOG.isEnabledFor(Level.WARN)) {
        LOG.warn("SRDI Push failed", e);
      }
    }
  }