Exemplo n.º 1
0
  /** initialize routeResolver */
  public void init(PeerGroup group, ID assignedID, Advertisement impl, EndpointRouter router)
      throws PeerGroupException {

    // extract Router service configuration properties
    PlatformConfig confAdv = (PlatformConfig) group.getConfigAdvertisement();
    Element paramBlock = null;

    if (confAdv != null) {
      paramBlock = confAdv.getServiceParam(assignedID);
    }

    if (paramBlock != null) {
      // get our tunable router parameter
      Enumeration param;

      param = paramBlock.getChildren("useRouteResolver");
      if (param.hasMoreElements()) {
        useRouteResolver = Boolean.getBoolean(((TextElement) param.nextElement()).getTextValue());
      }
    }

    this.group = group;
    this.router = router;

    localPeerId = group.getPeerID();
    localPeerAddr =
        new EndpointAddress("jxta", localPeerId.getUniqueValue().toString(), null, null);
  }
Exemplo n.º 2
0
  /**
   * remove a SRDI cache entry
   *
   * @param peer peer id we send the request, null for sending to all
   * @param id peer id of the SRDI route that we want to remove from the cache
   */
  protected void removeSrdi(String peer, PeerID id) {

    SrdiMessage srdiMsg;

    try {
      srdiMsg =
          new SrdiMessageImpl(
              group.getPeerID(),
              1, // only one hop
              "route",
              id.toString(),
              null, // 0 means remove
              new Long(0).longValue());
      if (LOG.isEnabledFor(Level.DEBUG)) {
        LOG.debug("sending a router SRDI message delete route " + id);
      }
      if (peer == null) {
        PeerID destPeer = srdi.getReplicaPeer(id.toString());

        // don't push anywhere if we do not have replica
        // or we are trying to push to ouself
        if (destPeer != null && (!destPeer.equals(localPeerId))) {
          srdi.pushSrdi(destPeer, srdiMsg);
        }
      }
    } catch (Exception e) {
      if (LOG.isEnabledFor(Level.DEBUG)) {
        LOG.debug("Removing srdi entry failed", e);
      }
    }
  }
Exemplo n.º 3
0
  /** {@inheritDoc} */
  public boolean send(Message message) throws IOException {
    if (closed) {
      throw new IOException("Pipe closed");
    }
    Message msg = message.clone();

    WireHeader header = new WireHeader();

    header.setPipeID(getPipeID());
    header.setSrcPeer(group.getPeerID());
    header.setTTL(1);
    header.setMsgId(WirePipe.createMsgId());

    XMLDocument asDoc = (XMLDocument) header.getDocument(MimeMediaType.XMLUTF8);
    MessageElement elem =
        new TextDocumentMessageElement(WirePipeImpl.WIRE_HEADER_ELEMENT_NAME, asDoc, null);
    msg.replaceMessageElement(WirePipeImpl.WIRE_HEADER_ELEMENT_NAMESPACE, elem);

    checkMessenger();
    try {
      destMessenger.sendMessageB(msg, null, null);
    } catch (IOException io) {
      checkMessenger();
      destMessenger.sendMessageB(msg, null, null);
    }
    return true;
  }
Exemplo n.º 4
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);
      }
    }
  }
Exemplo n.º 5
0
  /*
   * push srdi entries to the SRDI rendezvous cache
   * @param all if true push all entries, otherwise just deltas
   */
  protected void pushSrdi(ID peer, PeerID id) {

    SrdiMessage srdiMsg;

    try {
      srdiMsg =
          new SrdiMessageImpl(
              group.getPeerID(),
              1, // only one hop
              "route",
              id.toString(),
              null,
              new Long(Long.MAX_VALUE).longValue()); // maximum expiration
      // 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.
      if (LOG.isEnabledFor(Level.DEBUG)) {
        LOG.debug("sending a router SRDI message add route " + id);
      }
      if (peer == null) {
        PeerID destPeer = srdi.getReplicaPeer(id.toString());

        peer = destPeer;
      }
      // don't push anywhere if we do not have a replica
      // or we are trying to send the query to ourself
      if (!localPeerId.equals(peer)) {
        srdi.pushSrdi(peer, srdiMsg);
      }
    } catch (Exception e) {
      if (LOG.isEnabledFor(Level.WARN)) {
        LOG.warn("SRDI push failed", e);
      }
    }
  }
Exemplo n.º 6
0
 /** {@inheritDoc} */
 public ID getPeerID() {
   return peergroup.getPeerID();
 }