@Override public Object get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException { if (Thread.interrupted()) throw new InterruptedException(); // check in case latch is null if (this.isCancelled) { throw new CancellationException( "Future was cancelled"); } if (this.latch != null) { if (!this.latch.await(unit.toMillis(timeout))) { throw new TimeoutException(); } } return this.value; }
private static CancellationException cancellationExceptionWithCause( @Nullable String message, @Nullable Throwable cause) { CancellationException exception = new CancellationException(message); exception.initCause(cause); return exception; } }
@Override public C get() throws InterruptedException, ExecutionException { _latch.await(); if (_cause==COMPLETED) return _result; if (_cause instanceof CancellationException) throw (CancellationException) new CancellationException().initCause(_cause); throw new ExecutionException(_cause); }
if ((s = status) >= 0 && (ns = unit.toNanos(timeout)) > 0L) { long deadline = System.nanoTime() + ns; ForkJoinPool p = null; if ((ms = TimeUnit.NANOSECONDS.toMillis(ns)) > 0L && U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) { synchronized (this) { Throwable ex; if (s == CANCELLED) throw new CancellationException(); if (s != EXCEPTIONAL) throw new TimeoutException(); if ((ex = getThrowableException()) != null) throw new ExecutionException(ex);
boolean status = latch.await(to, unit); status = latch.await(to, unit); if (log.isDebugEnabled()) log.debug("Retry status : " + status); if (log.isDebugEnabled()) log.debug("Total duration due to gc event = " + (System.currentTimeMillis() - startTime) + " msec."); if (throwException) throw new ExecutionException(new CancellationException("Cancelled")); throw new ExecutionException(op.getException());
V innerGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException { if (!tryAcquireSharedNanos(0, nanosTimeout)) throw new TimeoutException(); if (getState() == CANCELLED) throw new CancellationException(); if (exception != null) throw new ExecutionException(exception); return result; }
@Override public boolean cancel(boolean mayInterruptIfRunning) { if (_done.compareAndSet(false,true)) { _cause=new CancellationException(); _latch.countDown(); return true; } return false; }
public static void on(CountDownLatch latch, long timeout, TimeUnit unit) { try { latch.await(timeout, unit); } catch (InterruptedException e) { throw new CancellationException(); } }
/** {@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 synchronized T get(long timeout, TimeUnit unit) throws InterruptedException { if (cancelled) { throw new CancellationException(); } else { while (!hasRun) this.wait(unit.toMillis(timeout)); return result; } }
/** * {@inheritDoc} */ @Override @SuppressWarnings({ "unchecked" }) public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { LOG.trace("Entering wait"); if (!latch.await(timeout, unit)) { throw new TimeoutException(); } LOG.trace("Wait completed"); if (isCancelled()) { throw new CancellationException(); } Object object = result.get(); if (object instanceof ExecutionException) { throw (ExecutionException) object; } else { return (V) object; } }
@Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (isCancelled()) { throw new CancellationException(task.getClass().getCanonicalName() + " has been cancelled"); } doWait(unit.toMillis(timeout)); if (exception != null) { throw new ExecutionException(exception); } return ret; }
/** * {@inheritDoc} */ public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { long startTime = System.currentTimeMillis(); long timeoutMillis = TimeUnit.MILLISECONDS.convert(timeout, unit); synchronized (this.sync) { for (;;) { if (this.isDone) { if (this.isCancelled) { throw new CancellationException(); } else if (this.failure != null) { throw new ExecutionException(this.failure); } else if (this.result != null) { return this.result; } } else if (System.currentTimeMillis() - startTime > timeoutMillis) { throw new TimeoutException(); } this.sync.wait(timeoutMillis); } } }
private T getResult() throws ExecutionException { if (this.ex != null) { throw new ExecutionException(this.ex); } if (cancelled) { throw new CancellationException(); } return this.result; }
LOG.debug("Scan with primary region returns " + e.getCause()); throw new InterruptedIOException(e.getMessage()); } catch (InterruptedException e) { throw new InterruptedIOException(e.getMessage()); RpcRetryingCallerWithReadReplicas.throwEnrichedException(e, retries); } catch (CancellationException e) { throw new InterruptedIOException(e.getMessage()); } catch (InterruptedException e) { throw new InterruptedIOException(e.getMessage());
@Test public void testErrorCode() { Assert.assertEquals( "Query cancelled", new QueryInterruptedException(new QueryInterruptedException(new CancellationException())).getErrorCode() ); Assert.assertEquals("Query cancelled", new QueryInterruptedException(new CancellationException()).getErrorCode()); Assert.assertEquals("Query interrupted", new QueryInterruptedException(new InterruptedException()).getErrorCode()); Assert.assertEquals("Query timeout", new QueryInterruptedException(new TimeoutException()).getErrorCode()); Assert.assertEquals("Unknown exception", new QueryInterruptedException(null).getErrorCode()); Assert.assertEquals("Unknown exception", new QueryInterruptedException(new ISE("Something bad!")).getErrorCode()); Assert.assertEquals( "Resource limit exceeded", new QueryInterruptedException(new ResourceLimitExceededException("too many!")).getErrorCode() ); Assert.assertEquals( "Unknown exception", new QueryInterruptedException(new QueryInterruptedException(new ISE("Something bad!"))).getErrorCode() ); }
@Override public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (cancelled.get()) { throw new CancellationException(); } long millis = TimeUnit.MILLISECONDS.convert(timeout, unit); t.waitFinished(millis); if (cancelled.get()) { throw new CancellationException(); } return null; } }
public void testImmediateFailedFuture_cancellationException() throws Exception { CancellationException exception = new CancellationException(); ListenableFuture<String> future = immediateFailedFuture(exception); assertFalse(future.isCancelled()); assertThat(future.toString()).endsWith("[status=FAILURE, cause=[" + exception + "]]"); try { getDone(future); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } try { getDoneFromTimeoutOverload(future); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } }
@Override public Object get(long timeout, @Nonnull TimeUnit unit) throws InterruptedException, TimeoutException { synchronized (lock) { while (!canceled) { unit.timedWait(lock, timeout); } if (canceled) { throw new CancellationException(); } else { throw new TimeoutException(); } } } }
@Override public void run() { MapMakerInternalMap<?, ?, ?, ?> map = mapReference.get(); if (map == null) { throw new CancellationException(); } for (Segment<?, ?, ?, ?> segment : map.segments) { segment.runCleanup(); } } }