GWT 2.7.0

com.google.web.bindery.requestfactory.gwt.client
Class RequestBatcher<F extends RequestFactory,C extends RequestContext>

java.lang.Object
  extended by com.google.web.bindery.requestfactory.gwt.client.RequestBatcher<F,C>
Type Parameters:
F - the type of RequestFactory
C - any RequestContext type

public abstract class RequestBatcher<F extends RequestFactory,C extends RequestContext>
extends java.lang.Object

A RequestBatcher is a convenience class that allows RequestFactory operations to be aggregated over a single tick of the event loop and sent as one HTTP request. Instances of RequestBatcher are reusable, so they may be used as application-wide singleton objects or within a particular subsystem or UI.

Subclasses need only to provide the instance of the RequestFactory used by the application and a method to provide a "default" RequestContext from the RequestFactory.

 public class MyRequestBatcher extends RequestBatcher {
   public MyRequestBatcher() {
     // MyRequestFactory could also be injected
     super(GWT.create(MyRequestFactory.class));
   }
   
   protected MyRequestContext createContext(MyRequestFactory factory) {
     return factory.myRequestContext();
   }
 }
 
A singleton or otherwise scoped instance of RequestBatcher should be injected into consuming classes. The RequestContext.fire() and Request.fire() methods reachable from the RequestContext returned from get() will not trigger an HTTP request. The RequestContext.fire(Receiver) and Request.fire(Receiver) methods will register their associated Receivers as usual. This allows consuming code to be written that can be used with or without a RequestBatcher.

When an application uses multiple RequestContext types, the RequestContext.append(RequestContext) method can be used to chain multiple RequestContext objects together:

 class MyRequestBatcher {
   public OtherRequestContext otherContext() {
     return get().append(getFactory().otherContext());
   }
 }
 

See Also:
Scheduler.scheduleFinally(ScheduledCommand)

Constructor Summary
protected RequestBatcher(F requestFactory)
           
 
Method Summary
protected abstract  C createContext(F requestFactory)
          Subclasses must implement this method to return an instance of a RequestContext.
 C get()
          Returns a mutable RequestContext.
 C get(Receiver<java.lang.Void> receiver)
          Returns a mutable RequestContext and enqueues the given receiver to be called as though it had been passed directly to RequestContext.fire(Receiver).
 F getRequestFactory()
          Convenience access to the RequestFactory instance to aid developers using multiple RequestContext types.
protected  Scheduler getScheduler()
          Returns Scheduler.get(), but may be overridden for testing purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestBatcher

protected RequestBatcher(F requestFactory)
Method Detail

get

public C get()
Returns a mutable RequestContext.


get

public C get(Receiver<java.lang.Void> receiver)
Returns a mutable RequestContext and enqueues the given receiver to be called as though it had been passed directly to RequestContext.fire(Receiver).


getRequestFactory

public F getRequestFactory()
Convenience access to the RequestFactory instance to aid developers using multiple RequestContext types.
 RequestBatcher<MyRequestFactory, MyRequestContext> batcher;
 
 public void useOtherRequestContext() {
   OtherRequestContext ctx = batcher.get().append(batcher.getFactory().otherContext());
   ctx.someOtherMethod().to(someReceiver);
 }
 


createContext

protected abstract C createContext(F requestFactory)
Subclasses must implement this method to return an instance of a RequestContext.


getScheduler

protected Scheduler getScheduler()
Returns Scheduler.get(), but may be overridden for testing purposes.


GWT 2.7.0