Пример #1
0
 protected synchronized void startConnectionReaper() {
   if (connection_reaper == null || connection_reaper.isDone())
     connection_reaper =
         timer.scheduleWithFixedDelay(
             new ConnectionReaper(),
             conn_expiry_timeout,
             conn_expiry_timeout,
             TimeUnit.MILLISECONDS);
 }
Пример #2
0
  public void sendDiscoveryRequest(String cluster_name, Promise promise, ViewId view_id)
      throws Exception {
    PingData data = null;
    PhysicalAddress physical_addr =
        (PhysicalAddress) down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));

    if (view_id == null) {
      List<PhysicalAddress> physical_addrs = Arrays.asList(physical_addr);
      data = new PingData(local_addr, null, false, UUID.get(local_addr), physical_addrs);
    }

    PingHeader hdr = new PingHeader(PingHeader.GET_MBRS_REQ, data, cluster_name);
    hdr.view_id = view_id;

    Collection<PhysicalAddress> cluster_members = fetchClusterMembers(cluster_name);
    if (cluster_members == null) {
      Message msg = new Message(null); // multicast msg
      msg.setFlag(Message.OOB);
      msg.putHeader(getId(), hdr);
      sendMcastDiscoveryRequest(msg);
    } else {
      if (cluster_members.isEmpty()) { // if we don't find any members, return immediately
        if (promise != null) promise.setResult(null);
      } else {
        for (final Address addr : cluster_members) {
          if (addr.equals(physical_addr)) // no need to send the request to myself
          continue;
          final Message msg = new Message(addr, null, null);
          msg.setFlag(Message.OOB);
          msg.putHeader(this.id, hdr);
          if (log.isTraceEnabled())
            log.trace("[FIND_INITIAL_MBRS] sending discovery request to " + msg.getDest());
          if (!sendDiscoveryRequestsInParallel()) {
            down_prot.down(new Event(Event.MSG, msg));
          } else {
            timer.execute(
                new Runnable() {
                  public void run() {
                    try {
                      down_prot.down(new Event(Event.MSG, msg));
                    } catch (Exception ex) {
                      if (log.isErrorEnabled())
                        log.error("failed sending discovery request to " + addr + ": " + ex);
                    }
                  }
                });
          }
        }
      }
    }
  }
Пример #3
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));
  }
Пример #4
0
 public Responses findMembers(
     final List<Address> members, final boolean initial_discovery, boolean async) {
   num_discovery_requests++;
   int num_expected = members != null ? members.size() : 0;
   int capacity = members != null ? members.size() : 16;
   final Responses rsps =
       new Responses(num_expected, initial_discovery && break_on_coord_rsp, capacity);
   synchronized (ping_responses) {
     ping_responses.put(System.nanoTime(), rsps);
   }
   if (async || async_discovery)
     timer.execute(() -> findMembers(members, initial_discovery, rsps));
   else findMembers(members, initial_discovery, rsps);
   weedOutCompletedDiscoveryResponses();
   return rsps;
 }
Пример #5
0
 protected void startStableTask() {
   if (stable_task_future == null || stable_task_future.isDone()) {
     final Runnable stable_task =
         new Runnable() {
           public void run() {
             try {
               sendStableMessages();
             } catch (Throwable t) {
               log.error("sending of STABLE messages failed", t);
             }
           }
         };
     stable_task_future =
         timer.scheduleWithFixedDelay(
             stable_task, stable_interval, stable_interval, TimeUnit.MILLISECONDS);
     if (log.isTraceEnabled()) log.trace("stable task started");
   }
 }
Пример #6
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));
  }
Пример #7
0
 protected void startRetransmitTask() {
   if (xmit_task == null || xmit_task.isDone())
     xmit_task =
         timer.scheduleWithFixedDelay(
             new RetransmitTask(), 0, xmit_interval, TimeUnit.MILLISECONDS);
 }
Пример #8
0
 protected synchronized void startCacheDissemination(
     List<Address> curr_mbrs, List<Address> left_mbrs, List<Address> new_mbrs) {
   timer.execute(new DiscoveryCacheDisseminationTask(curr_mbrs, left_mbrs, new_mbrs));
 }