List of usage examples for com.google.common.util.concurrent ForwardingFuture ForwardingFuture
protected ForwardingFuture()
From source file:org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.java
public static Future<?> startProcessing(MessageProducer messageProducer, MessageConsumer messageConsumer, ExecutorService executorService) { ConcurrentMessageProcessor reader = new ConcurrentMessageProcessor(messageProducer, messageConsumer); Future<?> result = executorService.submit(reader); return new ForwardingFuture<Object>() { @SuppressWarnings("unchecked") @Override//from w ww. java 2 s .c o m protected Future<Object> delegate() { return (Future<Object>) result; } @Override public boolean cancel(boolean mayInterruptIfRunning) { if (mayInterruptIfRunning && messageProducer instanceof Closeable) { try { ((Closeable) messageProducer).close(); } catch (IOException e) { throw new RuntimeException(e); } } return super.cancel(mayInterruptIfRunning); } }; }
From source file:com.google.cloud.dataflow.sdk.runners.worker.WindmillStateReader.java
private <T> Future<T> wrappedFuture(final Future<T> future) { // If the underlying lookup is already complete, we don't need to create the wrapper. if (future.isDone()) { return future; }//from w w w.j av a 2 s .c o m return new ForwardingFuture<T>() { @Override protected Future<T> delegate() { return future; } @Override public T get() throws InterruptedException, ExecutionException { if (!future.isDone()) { startBatchAndBlock(); } return super.get(); } @Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (!future.isDone()) { startBatchAndBlock(); } return super.get(timeout, unit); } }; }