@Override public void close() throws IOException { underlyingFuture.onSourceConsumed(underlyingInputStream); }
@Override public boolean isDone() { return getPendingCondition().getCount() == 0L; }
@Override public boolean isCancelled() { return isDone() && underlyingFuture.isCancelled(); }
T source = fetchSource(); logger.trace("Source fetched: {}", source); S conversionContext; return; conversionContext = startConversion(source); logger.trace("Context fetched for source {}: {}", source, conversionContext); underlyingFuture = conversionFuture = conversionContext.asFuture(); onSourceConsumed(source); onConversionFinished(conversionContext); } catch (Exception exception) { RuntimeException runtimeException = processException(exception); } finally { try { onConversionFailed(runtimeException); } catch (RuntimeException e) { logger.error("Callback for failed conversion caused an exception", e); getPendingCondition().countDown(); logger.trace("Locks for {} are released", underlyingFuture);
onConversionCancelled(); } catch (RuntimeException e) { logger.error("Callback for failed conversion caused an exception", e); } finally { logger.trace("Threads waiting for the conversion to finish are released"); getPendingCondition().countDown();
@Override public int compareTo(Runnable other) { // Note: The PriorityBlockingQueue expects an implementation of Comparable<Runnable>. // Therefore we cast the compared instance explicitly, relying on no other types // are inserted into the PriorityBlockingQueue. This exception is wanted since this // scenario should never occur. return priority.compareTo(((AbstractFutureWrappingPriorityFuture) other).getPriority()); }
private RuntimeException processException(Exception e) { if (e instanceof ExecutionException) { return processException((Exception) e.getCause()); } else if (e instanceof InterruptedException) { return new ConverterException("The conversion did not complete in time", e); } else if (e instanceof RuntimeException) { return (RuntimeException) e; } else { return new ConverterException("The conversion failed for an unexpected reason", e); } }
@Override public Boolean get() throws InterruptedException, ExecutionException { getPendingCondition().await(); return underlyingFuture.get(); }
@Override public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (getPendingCondition().await(timeout, unit)) { return underlyingFuture.get(); } else { throw new TimeoutException("Timed out while waiting for " + underlyingFuture); } } }