public T getResultWithTimeout(long timeout, boolean reset) throws TimeoutException { if(!reset) return _getResultWithTimeout(timeout); // the lock is acquired because we want to get the result and reset the promise in the same lock scope; if we had // to re-acquire the lock for reset(), some other thread could possibly set a new result before reset() is called ! lock.lock(); try { return _getResultWithTimeout(timeout); } finally { reset(); lock.unlock(); } }
/** * Sends a leave request to coord and blocks until a leave response has been received, or the leave timeout has elapsed */ protected void sendLeaveReqTo(Address coord) { leave_promise.reset(); leaving=true; log.trace("%s: sending LEAVE request to %s", gms.local_addr, coord); long start=System.currentTimeMillis(); sendLeaveMessage(coord, gms.local_addr); Boolean result=leave_promise.getResult(gms.leave_timeout); long time=System.currentTimeMillis()-start; if(result != null) log.trace("%s: got LEAVE response from %s in %d ms", gms.local_addr, coord, time); else log.trace("%s: timed out waiting for LEAVE response from %s (after %d ms)", gms.local_addr, coord, time); }
private void waitForUnblock() { try { flush_unblock_promise.reset(); flush_unblock_promise.getResultWithTimeout(end_flush_timeout); } catch (TimeoutException t) { if (log.isWarnEnabled()) log.warn(localAddress + ": waiting for UNBLOCK timed out after " + end_flush_timeout + " ms"); } }
public void handleJoinResponse(JoinRsp join_rsp) { join_promise.setResult(join_rsp); // will wake up join() method }
local_addr=(Address)local_addr_promise.getResult(LOCAL_ADDR_TIMEOUT); if(local_addr == null) { log.fatal("local_addr is null; cannot connect"); flush_unblock_promise.reset(); boolean shouldWaitForUnblock = flush_supported && receive_blocks && !singletonMember && !flush_unblock_promise.hasResult(); if(shouldWaitForUnblock){ try{ flush_unblock_promise.getResultWithTimeout(FLUSH_UNBLOCK_TIMEOUT);
public Counter getOrCreateCounter(String name, long initial_value) { if(local_addr == null) throw new IllegalArgumentException("the channel needs to be connected before creating or getting a counter"); Owner owner=getOwner(); GetOrCreateRequest req=new GetOrCreateRequest(owner, name, initial_value); Promise<long[]> promise=new Promise<>(); pending_requests.put(owner, new Tuple<>(req, promise)); sendRequest(coord, req); long[] result=new long[0]; try { result=promise.getResultWithTimeout(timeout); long value=result[0], version=result[1]; if(!coord.equals(local_addr)) counters.put(name, new VersionedValue(value, version)); return new CounterImpl(name); } catch(TimeoutException e) { throw new RuntimeException(e); } }
flush_unblock_promise.reset(); state_promise.reset(); down(evt); Boolean state_transfer_successfull=(Boolean)state_promise.getResult(info.timeout); if(shouldWaitForUnblock){ try{ flush_unblock_promise.getResultWithTimeout(FLUSH_UNBLOCK_TIMEOUT);
/** * Causes all waiting threads to return */ public void reset() { reset(true); }
public T getResult(long timeout, boolean reset) { try { return getResultWithTimeout(timeout, reset); } catch(TimeoutException e) { return null; } }
protected boolean installViewIfValidJoinRsp(final Promise<JoinRsp> join_promise, boolean block_for_rsp) { boolean success=false; JoinRsp rsp=null; try { if(join_promise.hasResult()) rsp=join_promise.getResult(1, true); else if(block_for_rsp) rsp=join_promise.getResult(gms.join_timeout, true); return success=rsp != null && isJoinResponseValid(rsp) && installView(rsp.getView(), rsp.getDigest()); } finally { if(success) gms.sendViewAck(rsp.getView().getCreator()); } }
/** * Returns the result, but never throws a TimeoutException; returns null instead. * @param timeout in ms * @return T */ public T getResult(long timeout) { return getResult(timeout, false); }
/** * Blocks until a result is available, or timeout milliseconds have elapsed * @param timeout in ms * @return An object * @throws TimeoutException If a timeout occurred (implies that timeout > 0) */ public T getResultWithTimeout(long timeout) throws TimeoutException { return _getResultWithTimeout(timeout); }
public void handleLeaveResponse() { leave_promise.setResult(true); // unblocks thread waiting in leave() }
Promise<long[]> promise=new Promise<>(); pending_requests.put(owner, new Tuple<>(req, promise)); sendRequest(coord, req); Object obj=null; try { obj=promise.getResultWithTimeout(timeout); if(obj instanceof Throwable) throw new IllegalStateException((Throwable)obj);
private boolean startFlush(Event evt, int numberOfAttempts, boolean isRetry) { boolean successfulFlush = false; if (!flushPhase.isFlushInProgress() || isRetry) { flush_promise.reset(); Map atts = (Map) evt.getArg(); long timeout = ((Long)atts.get("timeout")).longValue(); Boolean r = (Boolean) flush_promise.getResultWithTimeout(timeout); successfulFlush = r.booleanValue(); } catch (TimeoutException e) { Boolean succeededWhileWeSlept = (Boolean)flush_promise.getResult(1); boolean shouldRetry = !(succeededWhileWeSlept !=null && succeededWhileWeSlept.booleanValue()); if(shouldRetry)
public synchronized AckCollector reset(Collection<Address> expected_acks, Address ... exclude) { suspected_mbrs.clear(); missing_acks.clear(); addAll(expected_acks, exclude); all_acks_received.reset(); return this; }
public T getResult() { try { return getResultWithTimeout(0); } catch(TimeoutException e) { return null; } }
protected boolean installViewIfValidJoinRsp(final Promise<JoinRsp> join_promise, boolean block_for_rsp) { boolean success=false; JoinRsp rsp=null; try { if(join_promise.hasResult()) rsp=join_promise.getResult(1, true); else if(block_for_rsp) rsp=join_promise.getResult(gms.join_timeout, true); return success=rsp != null && isJoinResponseValid(rsp) && installView(rsp.getView(), rsp.getDigest()); } finally { if(success) gms.sendViewAck(rsp.getView().getCreator()); } }
public boolean waitForAllAcks() { if(missing_acks.isEmpty()) return true; Boolean result=all_acks_received.getResult(); return result != null && result; }