Esempio n. 1
0
  protected void sendDiscoveryResponse(
      Address logical_addr,
      List<PhysicalAddress> physical_addrs,
      boolean is_server,
      boolean return_view_only,
      String logical_name,
      final Address sender) {
    PingData data;
    if (return_view_only) {
      data = new PingData(logical_addr, view, is_server, null, null);
    } else {
      ViewId view_id = view != null ? view.getViewId() : null;
      data = new PingData(logical_addr, null, view_id, is_server, logical_name, physical_addrs);
    }

    final Message rsp_msg = new Message(sender, null, null);
    rsp_msg.setFlag(Message.OOB);
    final PingHeader rsp_hdr = new PingHeader(PingHeader.GET_MBRS_RSP, data);
    rsp_msg.putHeader(this.id, rsp_hdr);

    if (stagger_timeout > 0) {
      int view_size = view != null ? view.size() : 10;
      int rank = Util.getRank(view, local_addr); // returns 0 if view or local_addr are null
      long sleep_time =
          rank == 0
              ? Util.random(stagger_timeout)
              : stagger_timeout * rank / view_size - (stagger_timeout / view_size);
      timer.schedule(
          new Runnable() {
            public void run() {
              if (log.isTraceEnabled())
                log.trace(
                    local_addr
                        + ": received GET_MBRS_REQ from "
                        + sender
                        + ", sending staggered response "
                        + rsp_hdr);
              down_prot.down(new Event(Event.MSG, rsp_msg));
            }
          },
          sleep_time,
          TimeUnit.MILLISECONDS);
      return;
    }

    if (log.isTraceEnabled())
      log.trace("received GET_MBRS_REQ from " + sender + ", sending response " + rsp_hdr);
    down_prot.down(new Event(Event.MSG, rsp_msg));
  }
Esempio n. 2
0
  protected void sendDiscoveryResponse(
      Address logical_addr,
      PhysicalAddress physical_addr,
      String logical_name,
      final Address sender,
      boolean coord) {
    final PingData data =
        new PingData(logical_addr, is_server, logical_name, physical_addr).coord(coord);
    final Message rsp_msg =
        new Message(sender)
            .setFlag(Message.Flag.INTERNAL, Message.Flag.OOB, Message.Flag.DONT_BUNDLE)
            .putHeader(this.id, new PingHeader(PingHeader.GET_MBRS_RSP))
            .setBuffer(marshal(data));

    if (stagger_timeout > 0) {
      int view_size = view != null ? view.size() : 10;
      int rank = Util.getRank(view, local_addr); // returns 0 if view or local_addr are null
      long sleep_time =
          rank == 0
              ? Util.random(stagger_timeout)
              : stagger_timeout * rank / view_size - (stagger_timeout / view_size);
      timer.schedule(
          (Runnable)
              () -> {
                log.trace(
                    "%s: received GET_MBRS_REQ from %s, sending staggered response %s",
                    local_addr, sender, data);
                down_prot.down(new Event(Event.MSG, rsp_msg));
              },
          sleep_time,
          TimeUnit.MILLISECONDS);
      return;
    }

    log.trace("%s: received GET_MBRS_REQ from %s, sending response %s", local_addr, sender, data);
    down_prot.down(new Event(Event.MSG, rsp_msg));
  }