Class TimeoutFuture<V>
- java.lang.Object
-
- com.google.common.util.concurrent.GwtFluentFutureCatchingSpecialization<V>
-
- com.google.common.util.concurrent.FluentFuture<V>
-
- com.google.common.util.concurrent.AbstractFuture<V>
-
- com.google.common.util.concurrent.AbstractFuture.TrustedFuture<V>
-
- com.google.common.util.concurrent.TimeoutFuture<V>
-
- All Implemented Interfaces:
ListenableFuture<V>
,java.util.concurrent.Future<V>
@GwtIncompatible final class TimeoutFuture<V> extends AbstractFuture.TrustedFuture<V>
Implementation ofFutures#withTimeout
.Future that delegates to another but will finish early (via a
TimeoutException
wrapped in anExecutionException
) if the specified duration expires. The delegate future is interrupted and cancelled if it times out.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TimeoutFuture.Fire<V>
A runnable that is called when the delegate or the timer completes.-
Nested classes/interfaces inherited from class com.google.common.util.concurrent.AbstractFuture
AbstractFuture.TrustedFuture<V>
-
-
Field Summary
Fields Modifier and Type Field Description private ListenableFuture<V>
delegateRef
private java.util.concurrent.Future<?>
timer
-
Constructor Summary
Constructors Modifier Constructor Description private
TimeoutFuture(ListenableFuture<V> delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterDone()
Callback method that is called exactly once after the future is completed.(package private) static <V> ListenableFuture<V>
create(ListenableFuture<V> delegate, long time, java.util.concurrent.TimeUnit unit, java.util.concurrent.ScheduledExecutorService scheduledExecutor)
protected java.lang.String
pendingToString()
Provide a human-readable explanation of why this future has not yet completed.-
Methods inherited from class com.google.common.util.concurrent.AbstractFuture.TrustedFuture
addListener, cancel, get, get, isCancelled, isDone
-
Methods inherited from class com.google.common.util.concurrent.AbstractFuture
interruptTask, maybePropagateCancellationTo, set, setException, setFuture, toString, trustedGetException, wasInterrupted
-
Methods inherited from class com.google.common.util.concurrent.FluentFuture
addCallback, catching, catchingAsync, from, transform, transformAsync, withTimeout
-
-
-
-
Field Detail
-
delegateRef
private ListenableFuture<V> delegateRef
-
timer
private java.util.concurrent.Future<?> timer
-
-
Constructor Detail
-
TimeoutFuture
private TimeoutFuture(ListenableFuture<V> delegate)
-
-
Method Detail
-
create
static <V> ListenableFuture<V> create(ListenableFuture<V> delegate, long time, java.util.concurrent.TimeUnit unit, java.util.concurrent.ScheduledExecutorService scheduledExecutor)
-
pendingToString
protected java.lang.String pendingToString()
Description copied from class:AbstractFuture
Provide a human-readable explanation of why this future has not yet completed.- Overrides:
pendingToString
in classAbstractFuture<V>
- Returns:
- null if an explanation cannot be provided because the future is done.
-
afterDone
protected void afterDone()
Description copied from class:AbstractFuture
Callback method that is called exactly once after the future is completed.If
AbstractFuture.interruptTask()
is also run during completion,AbstractFuture.afterDone()
runs after it.The default implementation of this method in
AbstractFuture
does nothing. This is intended for very lightweight cleanup work, for example, timing statistics or clearing fields. If your task does anything heavier consider, just using a listener with an executor.- Overrides:
afterDone
in classAbstractFuture<V>
-
-