Пример #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));
  }
Пример #2
0
  /**
   * Creates a list of randomly generated partitions, each having a max size of max_partition_size
   */
  protected List<View> createPartitions(int max_partition_size, JChannel... channels) {
    long view_id = 1;
    for (JChannel ch : channels) view_id = Math.max(view_id, ch.getView().getViewId().getId());
    List<View> partitions = new ArrayList<>();
    List<Address> tmp = new ArrayList<>();
    for (JChannel ch : channels) tmp.add(ch.getAddress());

    while (!tmp.isEmpty()) {
      int num_to_remove = (int) Util.random(max_partition_size);
      List<Address> part = new ArrayList<>(max_partition_size);
      for (int x = 0; x < num_to_remove && !tmp.isEmpty(); x++) part.add(tmp.remove(0));
      partitions.add(new View(part.get(0), view_id + 1, part));
    }
    return partitions;
  }
Пример #3
0
  public static void testLargeRange() {
    SeqnoRange range = new SeqnoRange(0, 1500);

    Set<Integer> sorted_set = new TreeSet<>();
    for (int i = 0; i < 500; i++) {
      int num = (int) Util.random(1499);
      sorted_set.add(num);
    }

    for (int num : sorted_set) range.set(num);

    int num_set = sorted_set.size();
    System.out.println("set " + num_set + " bits");
    assert range.getNumberOfReceivedMessages() == num_set;
    Collection<Range> missing = range.getMessagesToRetransmit();
    System.out.println("missing = " + missing);
  }
Пример #4
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));
  }