Beispiel #1
0
    public List<PingData> get(long timeout) throws InterruptedException {
      long start_time = System.currentTimeMillis(), time_to_wait = timeout;

      promise.getLock().lock();
      try {
        while (time_to_wait > 0 && !promise.hasResult()) {
          // if num_expected_srv_rsps > 0, then it overrides num_expected_rsps
          if (num_expected_srv_rsps > 0) {
            int received_srv_rsps = getNumServerResponses(ping_rsps);
            if (received_srv_rsps >= num_expected_srv_rsps)
              return new LinkedList<PingData>(ping_rsps);
          } else if (ping_rsps.size() >= num_expected_rsps) {
            return new LinkedList<PingData>(ping_rsps);
          }

          if (break_on_coord_rsp && containsCoordinatorResponse(ping_rsps))
            return new LinkedList<PingData>(ping_rsps);

          promise.getCond().await(time_to_wait, TimeUnit.MILLISECONDS);
          time_to_wait = timeout - (System.currentTimeMillis() - start_time);
        }
        return new LinkedList<PingData>(ping_rsps);
      } finally {
        promise.getLock().unlock();
      }
    }
Beispiel #2
0
    public void addResponse(PingData rsp, boolean overwrite) {
      if (rsp == null) return;
      promise.getLock().lock();
      try {
        if (overwrite) ping_rsps.remove(rsp);

        // https://jira.jboss.org/jira/browse/JGRP-1179
        int index = ping_rsps.indexOf(rsp);
        if (index == -1) {
          ping_rsps.add(rsp);
          promise.getCond().signalAll();
        } else if (rsp.isCoord()) {
          PingData pr = ping_rsps.get(index);

          // Check if the already existing element is not server
          if (!pr.isCoord()) {
            ping_rsps.set(index, rsp);
            promise.getCond().signalAll();
          }
        }
      } finally {
        promise.getLock().unlock();
      }
    }