com.googlecode.objectify.cache
Class TriggerFuture<T>

java.lang.Object
  extended by com.googlecode.objectify.cache.TriggerFuture<T>
All Implemented Interfaces:
java.util.concurrent.Future<T>
Direct Known Subclasses:
TriggerSuccessFuture

public abstract class TriggerFuture<T>
extends java.lang.Object
implements java.util.concurrent.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 is made in a timely manner by hooking into the ApiProxy delegate system. Notification will happen ONCE:

To work, this future relies on the TriggerFutureHook. It must be installed on a per-thread basis at the beginning of a request and uninstalled at the end of a request. Typically this is done by the AsyncCacheFilter.

Author:
Jeff Schnitzer

Field Summary
protected  java.util.concurrent.Future<T> raw
          Wrap the raw Future
 
Constructor Summary
TriggerFuture(java.util.concurrent.Future<T> raw)
          Wrap a normal Future
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
           
 T get()
           
 T get(long timeout, java.util.concurrent.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

raw

protected java.util.concurrent.Future<T> raw
Wrap the raw Future

Constructor Detail

TriggerFuture

public TriggerFuture(java.util.concurrent.Future<T> raw)
Wrap a normal Future

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)
Specified by:
cancel in interface java.util.concurrent.Future<T>

isCancelled

public boolean isCancelled()
Specified by:
isCancelled in interface java.util.concurrent.Future<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 interface java.util.concurrent.Future<T>
See Also:
Future.isDone()

get

public T get()
      throws java.lang.InterruptedException,
             java.util.concurrent.ExecutionException
Specified by:
get in interface java.util.concurrent.Future<T>
Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException

get

public T get(long timeout,
             java.util.concurrent.TimeUnit unit)
      throws java.lang.InterruptedException,
             java.util.concurrent.ExecutionException,
             java.util.concurrent.TimeoutException
Specified by:
get in interface java.util.concurrent.Future<T>
Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException


Copyright © 2011 Jeff Schnitzer and a gang of pirates. All Rights Reserved. Build version: 3.1