Package com.googlecode.objectify.cache
Class TriggerFuture<T>
- java.lang.Object
-
- com.googlecode.objectify.cache.TriggerFuture<T>
-
- All Implemented Interfaces:
Future<T>
- Direct Known Subclasses:
TriggerSuccessFuture
public abstract class TriggerFuture<T> extends Object implements Future<T>
A Future> wrapper that executes an abstract method with the result at some point after the data becomes available. A "best effort" is made to ensure execution, but it may be left untriggered until the end of a request.
Notification will happen ONCE:
- After get() is called
- When the future is done and isDone() is called
- At the end of a request that has the AsyncCacheFilter enabled.
Use the AsyncCacheFilter for normal requests. For situations where a filter is not appropriate (ie, the remote api) be sure to call PendingFutures.completeAllPendingFutures() manually.
Note that if you are using this with Objectify, you probably want to use ObjectifyFilter.complete() rather than PendingFutures or AsyncCacheFilter static methods.
- Author:
- Jeff Schnitzer
-
-
Constructor Summary
Constructors Constructor Description TriggerFuture(Future<T> raw)
Wrap a normal Future>
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
cancel(boolean mayInterruptIfRunning)
T
get()
T
get(long timeout, TimeUnit unit)
boolean
isCancelled()
boolean
isDone()
This version also checks to see if we are done and we still need to call the trigger.protected abstract void
trigger()
This method will be called ONCE upon completion of the future, successful or not.
-
-
-
Method Detail
-
trigger
protected abstract void trigger()
This method will be called ONCE upon completion of the future, successful or not. Beware that this.get() may throw an exception.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceFuture<T>
-
isDone
public boolean isDone()
This version also checks to see if we are done and we still need to call the trigger. If so, it calls it.- Specified by:
isDone
in interfaceFuture<T>
- See Also:
Future.isDone()
-
get
public T get() throws InterruptedException, ExecutionException
- Specified by:
get
in interfaceFuture<T>
- Throws:
InterruptedException
ExecutionException
-
get
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
get
in interfaceFuture<T>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
-