Android Open Source - libgdx-chat-example Async Callback






From Project

Back to project page libgdx-chat-example.

License

The source code is released under:

Apache License

If you think the Android project libgdx-chat-example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.stofkat.chat.http.dispatch;
/**/*www . j a v a  2  s  .  com*/
 * The primary interface a caller must implement to receive a response from a
 * remote procedure call.
 * 
 * <p>
 * If an RPC is successful, then {@link #onSuccess(Object)} is called, otherwise
 * {@link #onFailure(Throwable)} is called.
 * </p>
 * 
 * <p>
 * Each callable asynchronous method corresponds to a method in the correlated
 * service interface. The asynchronous method always takes an
 * <code>AsyncCallback&lt;T&gt;</code> as its last parameter, where
 * <code>T</code> is the return type of the correlated synchronous method.
 * </p>
 * 
 * <p>
 * As an example, suppose the service interface defines a method called
 * <code>getShapes</code> as follows:
 * 
 * <pre>
 * Shape[] getShapes(String databaseName) throws ShapeException, DbException;
 * </pre>
 * 
 * Its asynchronous counterpart method be declared as:
 * 
 * <pre>
 * void getShapes(String databaseName, AsyncCallback&lt;Shape[]&gt; callback);
 * </pre>
 * 
 * Note that <code>throws</code> declaration is not repeated in the async
 * version.
 * </p>
 * 
 * <p>
 * A call with a typical use of <code>AsyncCallback</code> might look like
 * this:
 * 
 * <pre class="code">
 * service.getShapes(dbName, new AsyncCallback<Shape[]>() {
 * public void onSuccess(Shape[] result) {
 * // It's always safe to downcast to the known return type.
 * controller.processShapes(result);
 * }
 * 
 * public void onFailure(Throwable caught) {
 * // Convenient way to find out which exception was thrown.
 * try {
 * throw caught;
 * } catch (IncompatibleRemoteServiceException e) {
 * // this client is not compatible with the server; cleanup and refresh the
 * // browser
 * } catch (InvocationException e) {
 * // the call didn't complete cleanly
 * } catch (ShapeException e) {
 * // one of the 'throws' from the original method
 * } catch (DbException e) {
 * // one of the 'throws' from the original method
 * } catch (Throwable e) {
 * // last resort -- a very unexpected exception
 * }
 * }
 * });
 * </pre>
 * 
 * </p>
 * 
 * @param <T>
 *            The type of the return value that was declared in the synchronous
 *            version of the method. If the return type is a primitive, use the
 *            boxed version of that primitive (for example, an <code>int</code>
 *            return type becomes an {@link Integer} type argument, and a
 *            <code>void</code> return type becomes a {@link Void} type
 *            argument, which is always <code>null</code>).
 */
public interface AsyncCallback<T> {
  /**
   * Called when an asynchronous call fails to complete normally.
   * {@link IncompatibleRemoteServiceException}s, {@link InvocationException}
   * s,
   * or checked exceptions thrown by the service method are examples of the
   * type
   * of failures that can be passed to this method.
   * 
   * <p>
   * If <code>caught</code> is an instance of an
   * {@link IncompatibleRemoteServiceException} the application should try to
   * get into a state where a browser refresh can be safely done.
   * </p>
   * 
   * @param caught
   *            failure encountered while executing a remote procedure call
   */
  void onFailure(Throwable caught);

  /**
   * Called when an asynchronous call completes successfully.
   * 
   * @param result
   *            the return value of the remote produced call
   */
  void onSuccess(T result);
}




Java Source Code List

org.stofkat.chat.android.AndroidChat.java
org.stofkat.chat.android.AndroidDispatchServiceAsync.java
org.stofkat.chat.android.ChatActivity.java
org.stofkat.chat.common.ChatMessage.java
org.stofkat.chat.common.ClientInterface.java
org.stofkat.chat.common.actions.Action.java
org.stofkat.chat.common.actions.ChatAction.java
org.stofkat.chat.common.actions.UpdateAction.java
org.stofkat.chat.common.exceptions.ActionException.java
org.stofkat.chat.common.exceptions.DispatchException.java
org.stofkat.chat.common.exceptions.ServiceException.java
org.stofkat.chat.common.exceptions.UnsupportedActionException.java
org.stofkat.chat.common.results.ChatResult.java
org.stofkat.chat.common.results.Result.java
org.stofkat.chat.common.util.HashMapToOrderedArray.java
org.stofkat.chat.common.util.LowestIdFinder.java
org.stofkat.chat.core.ChatTextField.java
org.stofkat.chat.core.Chat.java
org.stofkat.chat.core.PickNameStage.java
org.stofkat.chat.core.ServerInterface.java
org.stofkat.chat.core.UpdateTask.java
org.stofkat.chat.html.ChatHtml.java
org.stofkat.chat.html.HtmlChat.java
org.stofkat.chat.html.dispatch.GwtAsyncCallbackHandler.java
org.stofkat.chat.html.dispatch.GwtDispatchServiceAsync.java
org.stofkat.chat.html.dispatch.GwtDispatchService.java
org.stofkat.chat.http.dispatch.AsyncCallbackHandler.java
org.stofkat.chat.http.dispatch.AsyncCallback.java
org.stofkat.chat.http.dispatch.CustomCookieStore.java
org.stofkat.chat.http.dispatch.HttpDispatchServiceAsync.java
org.stofkat.chat.http.dispatch.HttpUtils.java
org.stofkat.chat.java.ChatDesktop.java
org.stofkat.chat.java.DesktopChat.java
org.stofkat.chat.java.DesktopDispatchServiceAsync.java
org.stofkat.chat.server.AbstractDispatch.java
org.stofkat.chat.server.ActionHandlerRegistry.java
org.stofkat.chat.server.ActionHandler.java
org.stofkat.chat.server.ActionResult.java
org.stofkat.chat.server.ChatMessagesDatabase.java
org.stofkat.chat.server.DefaultActionHandlerRegistry.java
org.stofkat.chat.server.Dispatch.java
org.stofkat.chat.server.InstanceActionHandlerRegistry.java
org.stofkat.chat.server.SimpleDispatch.java
org.stofkat.chat.server.actionhandlers.ChatActionHandler.java
org.stofkat.chat.server.actionhandlers.UpdateActionHandler.java
org.stofkat.chat.server.gwt.dispatch.GwtDispatchServlet.java
org.stofkat.chat.server.http.dispatch.HttpDispatchServlet.java