com.stackmob.sdk.callback
Class StackMobRawCallback

java.lang.Object
  extended by com.stackmob.sdk.callback.StackMobRawCallback
Direct Known Subclasses:
StackMobCallback

public abstract class StackMobRawCallback
extends Object

The most basic callback you can supply to StackMob methods. This is a specialized method, StackMobCallback should be used in most cases. This callback receives every detail of the request and response, for cases when you want to check header values or get other information.


Field Summary
protected  String requestBody
           
protected  List<Map.Entry<String,String>> requestHeaders
           
protected  String requestURL
           
protected  com.stackmob.sdk.net.HttpVerb requestVerb
           
protected  byte[] responseBody
           
protected  List<Map.Entry<String,String>> responseHeaders
           
protected  Integer responseStatusCode
           
protected  int retriesRemaining
           
 
Constructor Summary
StackMobRawCallback()
           
 
Method Summary
abstract  void done(com.stackmob.sdk.net.HttpVerb requestVerb, String requestURL, List<Map.Entry<String,String>> requestHeaders, String requestBody, Integer responseStatusCode, List<Map.Entry<String,String>> responseHeaders, byte[] responseBody)
          the method that will be called when the call to StackMob is complete.
 int getRetriesRemaining()
          get the number of times the request will be automatically retried if necessary
static Integer getTotalNumberOfItemsFromContentRange(List<Map.Entry<String,String>> responseHeaders)
          get the total number of items from the Content-Range header
 int getTotalObjectCountFromPagination()
          get the total number of items from the Content-Range header
 boolean retry(int afterMilliseconds)
          The method that will be called when a retry is possible.
 void setDone(com.stackmob.sdk.net.HttpVerb requestVerb, String requestURL, List<Map.Entry<String,String>> requestHeaders, String requestBody, Integer responseStatusCode, List<Map.Entry<String,String>> responseHeaders, byte[] responseBody)
          the method that will be called when the call to StackMob is complete.
 void setRetriesRemaining(int remaining)
          override the number of times the request should be retried
abstract  void temporaryPasswordResetRequired(StackMobException e)
          the method that will be called in the very specific case where a user has done a login with a temporary password, and now they need to reset their password to continue.
abstract  void unsent(StackMobException e)
          the method that will be called when a call to StackMob cannot even be sent for some reason
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestVerb

protected com.stackmob.sdk.net.HttpVerb requestVerb

requestURL

protected String requestURL

requestHeaders

protected List<Map.Entry<String,String>> requestHeaders

requestBody

protected String requestBody

responseStatusCode

protected Integer responseStatusCode

responseHeaders

protected List<Map.Entry<String,String>> responseHeaders

responseBody

protected byte[] responseBody

retriesRemaining

protected int retriesRemaining
Constructor Detail

StackMobRawCallback

public StackMobRawCallback()
Method Detail

unsent

public abstract void unsent(StackMobException e)
the method that will be called when a call to StackMob cannot even be sent for some reason

Parameters:
e - an error with the reason why

temporaryPasswordResetRequired

public abstract void temporaryPasswordResetRequired(StackMobException e)
the method that will be called in the very specific case where a user has done a login with a temporary password, and now they need to reset their password to continue. Respond to this by putting up a reset password screen and then calling StackMobUser.loginResettingTemporaryPassword(String, StackMobCallback) with the new password

Parameters:
e - an error with the reason why

setDone

public void setDone(com.stackmob.sdk.net.HttpVerb requestVerb,
                    String requestURL,
                    List<Map.Entry<String,String>> requestHeaders,
                    String requestBody,
                    Integer responseStatusCode,
                    List<Map.Entry<String,String>> responseHeaders,
                    byte[] responseBody)
the method that will be called when the call to StackMob is complete. may be executed in a background thread

Parameters:
requestVerb - the HTTP verb that was requested
requestURL - the URL that was requested
requestHeaders - the headers in the request
requestBody - the body of the request. will be an empty string for GET, DELETE, etc...
responseStatusCode - the status code of the HTTP response from StackMob
responseHeaders - the response headers from StackMob
responseBody - the response body from StackMob

done

public abstract void done(com.stackmob.sdk.net.HttpVerb requestVerb,
                          String requestURL,
                          List<Map.Entry<String,String>> requestHeaders,
                          String requestBody,
                          Integer responseStatusCode,
                          List<Map.Entry<String,String>> responseHeaders,
                          byte[] responseBody)
the method that will be called when the call to StackMob is complete. may be executed in a background thread

Parameters:
requestVerb - the HTTP verb that was requested
requestURL - the URL that was requested
requestHeaders - the headers in the request
requestBody - the body of the request. will be an empty string for GET, DELETE, etc...
responseStatusCode - the status code of the HTTP response from StackMob
responseHeaders - the response headers from StackMob
responseBody - the response body from StackMob

retry

public boolean retry(int afterMilliseconds)
The method that will be called when a retry is possible. This is triggered when there is a distinct and short term reason your request failed, and it should be successful on retry after the specified interval. By default at most three attempts are made before failing. Override to implement your own logic on retry, and return false to stop the request from being automatically retried.

Parameters:
afterMilliseconds - the number of milliseconds to wait until retrying the request.
Returns:
whether or not to automatically retry

getRetriesRemaining

public int getRetriesRemaining()
get the number of times the request will be automatically retried if necessary

Returns:
remaining triest

setRetriesRemaining

public void setRetriesRemaining(int remaining)
override the number of times the request should be retried

Parameters:
remaining - the number of times the request should be retried

getTotalObjectCountFromPagination

public int getTotalObjectCountFromPagination()
get the total number of items from the Content-Range header

Returns:
the total number of items returned in the Content-Range header, -1 if there was no Content-Range header or it was malformed, -2 if the Content-Length header was present and well formed but the instance length was "*"

getTotalNumberOfItemsFromContentRange

public static Integer getTotalNumberOfItemsFromContentRange(List<Map.Entry<String,String>> responseHeaders)
get the total number of items from the Content-Range header

Parameters:
responseHeaders - the headers that were returned in the response
Returns:
the total number of items returned in the Content-Range header, -1 if there was no Content-Range header or it was malformed, -2 if the Content-Length header was present and well formed but the instance length was "*"


Copyright © 2012 StackMob. All Rights Reserved.