com.googlecode.objectify.cache
Class TriggerFutureHook

java.lang.Object
  extended by com.googlecode.objectify.cache.TriggerFutureHook
All Implemented Interfaces:
com.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>

public class TriggerFutureHook
extends java.lang.Object
implements com.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>

This bit of appengine magic hooks into the ApiProxy and does the heavy lifting of making the TriggerFuture work.

This class maintains a thread local list of all the outstanding Future objects that have pending triggers. When a Future is done and its trigger is executed, it is removed from the list. At various times (anytime an API call is made) the registered futures are checked for doneness and processed.

The AsyncCacheFilter is necessary to guarantee that any pending triggers are processed at the end of the request. A future GAE SDK which allows us to hook into the Future creation process might make this extra Filter unnecessary.

Author:
Jeff Schnitzer

Constructor Summary
TriggerFutureHook(com.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment> parent)
           
 
Method Summary
static void addPending(java.util.concurrent.Future<?> future)
          Register a pending Future that has a callback.
static void completeAllPendingFutures()
          Iterate through all pending futures and get() them, forcing any callbacks to be called.
 void flushLogs(com.google.apphosting.api.ApiProxy.Environment paramE)
           
 java.util.List<java.lang.Thread> getRequestThreads(com.google.apphosting.api.ApiProxy.Environment paramE)
           
static void install()
          Install our hook in the delegate system.
 void log(com.google.apphosting.api.ApiProxy.Environment arg0, com.google.apphosting.api.ApiProxy.LogRecord arg1)
           
 java.util.concurrent.Future<byte[]> makeAsyncCall(com.google.apphosting.api.ApiProxy.Environment arg0, java.lang.String arg1, java.lang.String arg2, byte[] arg3, com.google.apphosting.api.ApiProxy.ApiConfig arg4)
           
 byte[] makeSyncCall(com.google.apphosting.api.ApiProxy.Environment arg0, java.lang.String arg1, java.lang.String arg2, byte[] arg3)
           
static void removePending(java.util.concurrent.Future<?> future)
          Deregister a pending Future that had a callback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TriggerFutureHook

public TriggerFutureHook(com.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment> parent)
Method Detail

install

public static void install()
Install our hook in the delegate system. This happens automatically when this class is loaded, which is typically what you want when working with Objectify. It gets a lot more complicated when you're working with the RemoteApiInstaller.


addPending

public static void addPending(java.util.concurrent.Future<?> future)
Register a pending Future that has a callback.

Parameters:
future - must have at least one callback

removePending

public static void removePending(java.util.concurrent.Future<?> future)
Deregister a pending Future that had a callback.


log

public void log(com.google.apphosting.api.ApiProxy.Environment arg0,
                com.google.apphosting.api.ApiProxy.LogRecord arg1)
Specified by:
log in interface com.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>

makeAsyncCall

public java.util.concurrent.Future<byte[]> makeAsyncCall(com.google.apphosting.api.ApiProxy.Environment arg0,
                                                         java.lang.String arg1,
                                                         java.lang.String arg2,
                                                         byte[] arg3,
                                                         com.google.apphosting.api.ApiProxy.ApiConfig arg4)
Specified by:
makeAsyncCall in interface com.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>

makeSyncCall

public byte[] makeSyncCall(com.google.apphosting.api.ApiProxy.Environment arg0,
                           java.lang.String arg1,
                           java.lang.String arg2,
                           byte[] arg3)
                    throws com.google.apphosting.api.ApiProxy.ApiProxyException
Specified by:
makeSyncCall in interface com.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>
Throws:
com.google.apphosting.api.ApiProxy.ApiProxyException

completeAllPendingFutures

public static void completeAllPendingFutures()
Iterate through all pending futures and get() them, forcing any callbacks to be called. This is used only by the AsyncCacheFilter because we don't have a proper hook otherwise.


flushLogs

public void flushLogs(com.google.apphosting.api.ApiProxy.Environment paramE)
Specified by:
flushLogs in interface com.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>

getRequestThreads

public java.util.List<java.lang.Thread> getRequestThreads(com.google.apphosting.api.ApiProxy.Environment paramE)
Specified by:
getRequestThreads in interface com.google.apphosting.api.ApiProxy.Delegate<com.google.apphosting.api.ApiProxy.Environment>


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