GWT 2.3.0

com.google.gwt.user.client
Interface AsyncProxy<T>

Type Parameters:
T - the type of interface that must be implemented by the derivative class.

@AsyncProxy.DefaultValue
public interface AsyncProxy<T>

The AsyncProxy type is used to provide a reachability barrier between classes intended to be used with runAsync while maintaining a simple, deferred-synchronous API. The first invocation of an instance method on the AsyncProxy will trigger the instantiation of a concrete object via runAsync. All method invocations on the proxy will be recorded and played back on the newly-instantiated object after the call to runAsync returns.

Once method playback has finished, the proxy will continue to forward invocations onto the instantiated object.

Example use:

 interface IFoo {
   void doSomething(int a, int b);
   void anotherMethad(Object o);
 }
 class FooImpl implements IFoo { .... }
 
 @ConcreteType(FooImpl.class)
 interface FooProxy extends AsyncProxy<IFoo>, IFoo {}
 
 class UserOfIFoo {
   private IFoo foo = GWT.create(FooProxy.class);
   
   void makeTrouble() {
     // This first call triggers a runAsync load
     foo.doSomething(1, 2);
     
     // and this second will replayed after the call to doSomething()
     foo.anotherMethod("A string");
   }
 }
 
For cases where dispatch speed is critical, a ProxyCallback can be installed in order to reassign the field containing the AsyncProxy instance with the backing object:
 class UserOfIFoo {
   private IFoo fooOrProxy = GWT.create(FooProxy.class);

   public UserOfIFoo() {
     // When the load, initialization, and playback are done, get rid of the proxy.
     ((AsyncProxy<IFoo>) fooOrProxy).setProxyCallback(new ProxyCallback<IFoo>() {
       public void onComplete(IFoo instance) {
         fooOrProxy = instance;
       }
     });
   }
   
   void makeTrouble() {
     // This first call triggers a runAsync load
     fooOrProxy.doSomething(1, 2);
     
     // and this second will also be replayed before the above onComplete is called
     fooOrProxy.anotherMethod("A string");
   }
 }
 


Nested Class Summary
static interface AsyncProxy.AllowNonVoid
          If this annotation is applied to an AsyncProxy type, it will be legal for the parameterized type T to declare non-void methods.
static interface AsyncProxy.ConcreteType
          This interface should be applied to the AsyncProxy subtype in order to specify the Class literal that will be passed to GWT.create(Class).
static interface AsyncProxy.DefaultValue
          This annotation specifies the return value for primitive methods when the AsyncProxy.AllowNonVoid annotation has been applied to an AsyncProxy.
static class AsyncProxy.ProxyCallback<T>
          The callback used by setProxyCallback(ProxyCallback).
 
Method Summary
 T getProxiedInstance()
          Returns the underlying proxied object if it has been instantiated or null.
 void setProxyCallback(AsyncProxy.ProxyCallback<T> callback)
          Sets a callback that can be used to influence the initialization process.
 

Method Detail

getProxiedInstance

T getProxiedInstance()
Returns the underlying proxied object if it has been instantiated or null.


setProxyCallback

void setProxyCallback(AsyncProxy.ProxyCallback<T> callback)
Sets a callback that can be used to influence the initialization process.


GWT 2.3.0