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
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
cancel(boolean mayInterruptIfRunning)
get()
boolean
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.
-
Field Details
-
raw
Wrap the raw Future>
-
-
Constructor Details
-
TriggerFuture
Wrap a normal Future>
-
-
Method Details
-
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
- 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
-