public interface

AsyncProxy

com.google.gwt.user.client.AsyncProxy<T>
Known Indirect Subclasses

Class Overview

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");
   }
 }
 

Summary

Nested Classes
@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. 
@interface AsyncProxy.ConcreteType This interface should be applied to the AsyncProxy subtype in order to specify the Class literal that will be passed to create(Class)
@interface AsyncProxy.DefaultValue This annotation specifies the return value for primitive methods when the AsyncProxy.AllowNonVoid annotation has been applied to an AsyncProxy. 
class AsyncProxy.ProxyCallback<T> The callback used by setProxyCallback(ProxyCallback)
Public Methods
abstract T getProxiedInstance()
Returns the underlying proxied object if it has been instantiated or null.
abstract void setProxyCallback(ProxyCallback<T> callback)
Sets a callback that can be used to influence the initialization process.

Public Methods

public abstract T getProxiedInstance ()

Returns the underlying proxied object if it has been instantiated or null.

public abstract void setProxyCallback (ProxyCallback<T> callback)

Sets a callback that can be used to influence the initialization process.