GWTP Dispatch client 0.7-redhat-1

com.gwtplatform.dispatch.client.actionhandler.caching
Class AbstractCachingClientActionHandler<A extends Action<R>,R extends Result>

java.lang.Object
  extended by com.gwtplatform.dispatch.client.actionhandler.AbstractClientActionHandler<A,R>
      extended by com.gwtplatform.dispatch.client.actionhandler.caching.AbstractCachingClientActionHandler<A,R>
Type Parameters:
A - The type of the action extending Action.
R - The type of the result extending Result.
All Implemented Interfaces:
ClientActionHandler<A,R>
Direct Known Subclasses:
ActionCachingHandler

public abstract class AbstractCachingClientActionHandler<A extends Action<R>,R extends Result>
extends AbstractClientActionHandler<A,R>

Abstract base class for client-side action handlers with caching support.

Supported features include:

1. prefetch(A)/postfetch(A, R) perform the cache lookup and the cache store. You can use this to customize the caching logic.

2. Automatic action queuing so that calls in quick succession result in a single trip to the server.

3. Flexibility of cache implementation to support custom caching

Author:
Sunny Gupta, David M. Chandler, Christian Goudreau

Constructor Summary
AbstractCachingClientActionHandler(Class<A> actionType, Cache cache)
           
 
Method Summary
 DispatchRequest execute(A action, com.google.gwt.user.client.rpc.AsyncCallback<R> resultCallback, ExecuteCommand<A,R> executeCommand)
          Handles the specified action.
protected  Cache getCache()
           
protected abstract  void postfetch(A action, R result)
          Override this method to perform an action after the call to the server returns successfully or not.
protected abstract  R prefetch(A action)
          Override this method to perform an action before the call is sent to the server.
 DispatchRequest undo(A action, R result, com.google.gwt.user.client.rpc.AsyncCallback<Void> callback, UndoCommand<A,R> undoCommand)
          Undoes the specified action.
 
Methods inherited from class com.gwtplatform.dispatch.client.actionhandler.AbstractClientActionHandler
getActionType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCachingClientActionHandler

public AbstractCachingClientActionHandler(Class<A> actionType,
                                          Cache cache)
Method Detail

execute

public DispatchRequest execute(A action,
                               com.google.gwt.user.client.rpc.AsyncCallback<R> resultCallback,
                               ExecuteCommand<A,R> executeCommand)
Description copied from interface: ClientActionHandler
Handles the specified action. If the handler makes asynchronous calls, it is recommended that you confirm that this request has not been cancelled after returning by calling DelegatingDispatchRequest#isCancelled() against the request parameter.

Parameters:
action - The Action to execute.
resultCallback - The callback to use to communicate the result of the action. Unless the request is cancelled, you must invoke AsyncCallback.onSuccess(T) on this callback once you have obtained the result. If any failure occurs call AsyncCallback.onFailure(java.lang.Throwable).
executeCommand - Call ExecuteCommand.execute(Action, com.google.gwt.user.client.rpc.AsyncCallback) on this object to send the action over to the server via gwt-rpc. As a parameter you can pass resultCallback or your custom AsyncCallback if you want to process the result.
Returns:
A DispatchRequest object. Never return null, instead return a new CompletedDispatchRequest if you executed, cancelled or ignored the action.

undo

public DispatchRequest undo(A action,
                            R result,
                            com.google.gwt.user.client.rpc.AsyncCallback<Void> callback,
                            UndoCommand<A,R> undoCommand)
Description copied from interface: ClientActionHandler
Undoes the specified action. If the handler makes asynchronous calls, it is recommended that you confirm that this request has not been cancelled after returning by calling DelegatingDispatchRequest#isCancelled() against the request parameter.

Parameters:
action - The Action to undo.
result - The Result to undo.
callback - The callback to use to indicate when the action has been undone. Unless the request is cancelled, you must invoke AsyncCallback.onSuccess(T) on this callback when you have successfully undone the action. If any failure occurs call AsyncCallback.onFailure(java.lang.Throwable).
undoCommand - Call UndoCommand.undo(Action, Result, com.google.gwt.user.client.rpc.AsyncCallback) on this object to send the action over to the server via gwt-rpc. As a parameter you can pass callback or your custom AsyncCallback if you want to perform any processing following the undo.
Returns:
A DispatchRequest object. Never return null, instead return a new CompletedDispatchRequest if you executed, cancelled or ignored the action.

prefetch

protected abstract R prefetch(A action)
Override this method to perform an action before the call is sent to the server. If the call returns a non-null result then the action is never executed on the server and the returned value is used. If the call returns null then the action is executed on the server.

You can use this method to fetch the action from the cache.

Parameters:
action - The action to be prefetched
Returns:
The prefetched result. If not found, return null.

postfetch

protected abstract void postfetch(A action,
                                  R result)
Override this method to perform an action after the call to the server returns successfully or not. If the call succeeded, the result will be passed, if it failed null will be passed in the result parameter.

You can use this method to add the result to cache, if it is null you should remove the action from the cache.

Parameters:
action - The action that just finished execution on the server.
result - The result after the server call, or null if the server call failed.

getCache

protected Cache getCache()
Returns:
the cache

GWTP Dispatch client 0.7-redhat-1

Copyright © 2010-2013 JBoss by Red Hat. All Rights Reserved.