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(); } }