@Override public T get( long timeout, TimeUnit unit ) throws InterruptedException, TimeoutException { if ( !guardedByLatch.await( timeout, unit ) ) { throw new TimeoutException( jobDescription + " didn't complete within " + timeout + " " + unit ); } return supplier.get(); } };
R await(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { long startMs = System.currentTimeMillis(); long waitTimeMs = unit.toMillis(timeout); long delta = 0; synchronized (this) { while (true) { if (exception != null) wrapAndThrow(exception); if (done) return value; if (delta >= waitTimeMs) { throw new TimeoutException(); } this.wait(waitTimeMs - delta); delta = System.currentTimeMillis() - startMs; } } } }
@Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (latch.await(timeout, unit)) { if (error != null) { throw new ExecutionException(error); } return result; } else { throw new TimeoutException(); } }
@Override public byte[] get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (hasResult) { return result; } try { result = waitForProcedureToComplete(procExec, proc, unit.toMillis(timeout)); hasResult = true; return result; } catch (TimeoutIOException e) { throw new TimeoutException(e.getMessage()); } catch (Exception e) { throw new ExecutionException(e); } } }
@Override public BrokerInfo get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { try { if (info == null) { long deadline = System.currentTimeMillis() + unit.toMillis(timeout); while (!disposed.get() || System.currentTimeMillis() - deadline < 0) { if (slot.await(1, TimeUnit.MILLISECONDS)) { break; } } if (info == null) { throw new TimeoutException(); } } return info; } catch (InterruptedException e) { throw new InterruptedException("Interrupted."); } }
private synchronized T doGet(Long timeoutMs) throws InterruptedException, ExecutionException, TimeoutException { if (mException != null) { throw new ExecutionException(mException); } if (mResultReceived) { return mResult; } if (timeoutMs == null) { wait(0); } else if (timeoutMs > 0) { wait(timeoutMs); } if (mException != null) { throw new ExecutionException(mException); } if (!mResultReceived) { throw new TimeoutException(); } return mResult; }
/** * Blocks the current thread until the action schedule finished. This does not release the test * runner and the test must still call {@link #blockUntilEnded(long)}. * * @param timeoutMs The maximum time to wait for the action schedule to finish. * @return This test runner. * @throws TimeoutException If the action schedule did not finish within the specified timeout. * @throws InterruptedException If the test thread gets interrupted while waiting. */ public ExoPlayerTestRunner blockUntilActionScheduleFinished(long timeoutMs) throws TimeoutException, InterruptedException { if (!actionScheduleFinishedCountDownLatch.await(timeoutMs, TimeUnit.MILLISECONDS)) { throw new TimeoutException("Test playback timed out waiting for action schedule to finish."); } return this; }
@Override public Integer get( long timeout, TimeUnit unit ) throws InterruptedException, TimeoutException { long end = System.currentTimeMillis() + unit.toMillis( timeout ); while ( System.currentTimeMillis() < end ) { Integer result = tryGetExitValue( process ); if ( result != null ) { return result; } Thread.sleep( 10 ); } throw new TimeoutException( "Process '" + process + "' didn't exit within " + timeout + " " + unit ); } };
/** {@inheritDoc} */ @Override public T get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException { A.ensure(timeout >= 0, "timeout >= 0"); A.notNull(unit, "unit != null"); try { T res = fut.get(unit.toMillis(timeout)); if (fut.isCancelled()) throw new CancellationException("Task was cancelled: " + fut); return res; } catch (IgniteFutureTimeoutCheckedException e) { TimeoutException e2 = new TimeoutException(); e2.initCause(e); throw e2; } catch (ComputeTaskTimeoutCheckedException e) { throw new ExecutionException("Task execution timed out during waiting for task result: " + fut, e); } catch (IgniteCheckedException e) { // Task cancellation may cause throwing exception. if (fut.isCancelled()) { RuntimeException ex = new CancellationException("Task was cancelled: " + fut); ex.initCause(e); throw ex; } throw new ExecutionException("Failed to get task result.", e); } } }
public V get(long timeout, TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException { // Wait for a put, fail or cancel if (!dataGate.await(timeout, unit)) { throw new TimeoutException(); } // Now a put, fail or cancel has occurred, state does not change; we // don't need even a read lock. if (throwable != null) { throw new ExecutionException(throwable); } return value; }
@Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (finished.await(timeout, unit)) { return getValue(); } else { throw new TimeoutException("Timed out after " + unit.toMillis(timeout) + "ms waiting for underlying Observable."); } }
private synchronized T doGet(Long timeoutMs) throws InterruptedException, ExecutionException, TimeoutException { if (mException != null) { throw new ExecutionException(mException); } if (mResultReceived) { return mResult; } if (timeoutMs == null) { wait(0); } else if (timeoutMs > 0) { wait(timeoutMs); } if (mException != null) { throw new ExecutionException(mException); } if (!mResultReceived) { throw new TimeoutException(); } return mResult; }
@Override public E get(long l, TimeUnit tu) throws InterruptedException, ExecutionException, TimeoutException { if (innerFuture != null) { return (E) innerFuture.get(l, tu); } boolean isSuccessful = latch.await(l, tu); if (!isSuccessful) { throw new TimeoutException(); } return msg; } }
@Override public synchronized T get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Validate.notNull(unit, "Time unit"); final long msecs = unit.toMillis(timeout); final long startTime = (msecs <= 0) ? 0 : System.currentTimeMillis(); long waitTime = msecs; if (this.completed) { return getResult(); } else if (waitTime <= 0) { throw new TimeoutException(); } else { for (;;) { wait(waitTime); if (this.completed) { return getResult(); } else { waitTime = msecs - (System.currentTimeMillis() - startTime); if (waitTime <= 0) { throw new TimeoutException(); } } } } }
if ((ms = TimeUnit.NANOSECONDS.toMillis(ns)) > 0L && U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) { synchronized (this) { throw new CancellationException(); if (s != EXCEPTIONAL) throw new TimeoutException(); if ((ex = getThrowableException()) != null) throw new ExecutionException(ex);
@Override public C get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (!_latch.await(timeout,unit)) throw new TimeoutException(); if (_cause==COMPLETED) return _result; if (_cause instanceof TimeoutException) throw (TimeoutException)_cause; if (_cause instanceof CancellationException) throw (CancellationException) new CancellationException().initCause(_cause); throw new ExecutionException(_cause); }
private synchronized T doGet(Long timeoutMs) throws InterruptedException, ExecutionException, TimeoutException { if (mException != null) { throw new ExecutionException(mException); } if (mResultReceived) { return mResult; } if (timeoutMs == null) { wait(0); } else if (timeoutMs > 0) { wait(timeoutMs); } if (mException != null) { throw new ExecutionException(mException); } if (!mResultReceived) { throw new TimeoutException(); } return mResult; }
/** * Waits for the CallFuture to complete without returning the result. * @param timeout the maximum time to wait. * @param unit the time unit of the timeout argument. * @throws InterruptedException if interrupted. * @throws TimeoutException if the wait timed out. */ public void await(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException { if (!latch.await(timeout, unit)) { throw new TimeoutException(); } }
@Override public synchronized T get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Validate.notNull(unit, "Time unit"); final long msecs = unit.toMillis(timeout); final long startTime = (msecs <= 0) ? 0 : System.currentTimeMillis(); long waitTime = msecs; if (this.completed) { return getResult(); } else if (waitTime <= 0) { throw new TimeoutException(); } else { for (;;) { wait(waitTime); if (this.completed) { return getResult(); } else { waitTime = msecs - (System.currentTimeMillis() - startTime); if (waitTime <= 0) { throw new TimeoutException(); } } } } }
if ((ms = TimeUnit.NANOSECONDS.toMillis(ns)) > 0L && U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) { synchronized (this) { throw new CancellationException(); if (s != EXCEPTIONAL) throw new TimeoutException(); if ((ex = getThrowableException()) != null) throw new ExecutionException(ex);