public abstract class Processor
extends java.lang.Object
HttpRequestHandler
. It manages pre-process and post-process logic . Pre-process and post-process are defined as hooks in order to defined specific logics for you're applicationModifier and Type | Class and Description |
---|---|
static interface |
Processor.RESTServiceCallback
Binder callback for
RestService |
Modifier and Type | Field and Description |
---|---|
protected HttpRequestHandler |
mHttpRequestHandler
Instance of
HttpRequestHandler |
protected ParserFactory |
mParserFactory
Instance of
ParserFactory |
protected PersistableFactory |
mPersistableFactory
Instance of
PersistableFactory |
protected Processor.RESTServiceCallback |
mRESTServiceCallback
Instance of
Processor.RESTServiceCallback |
Constructor and Description |
---|
Processor()
Constructor
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkRequest(RESTRequest<? extends Resource> request)
Handles caching logic.
|
PersistableFactory |
getPersistableFactory()
Getter for
mPersistableFactory |
protected Persistable<Resource> |
getResourcePersistable(Resource resource)
Shortcut to retrieve Persistable class from Processor via
PersistableFactory |
protected void |
handleHttpRequestHandlerCallback(int statusCode,
RESTRequest<? extends Resource> request)
Handles the binder callback from
HttpRequestHandler by updating status code calling postRequestProcess(int, RESTRequest, InputStream) hook, set the result stream in RESTRequest and fires Processor.RESTServiceCallback |
protected java.lang.String |
inputStreamToString(java.io.InputStream is) |
static boolean |
isRemotelySync(ResourceRepresentation<?> r)
Provides a way to know if a specific
ResourceRepresentation is remotely sync or not. |
protected void |
mirrorServerState(RESTRequest<? extends Resource> r)
Mirrors the server state before the request is executed.
|
protected void |
mirrorServerStateRoutine(HTTPVerb verb,
ResourceRepresentation<?> resource) |
protected void |
onFailedRequest(WebService context,
int statusCode,
RESTRequest<? extends Resource> request)
Hook to execute actions on failed request.
|
protected void |
onSucceededRequest(WebService context,
int statusCode,
RESTRequest<? extends Resource> request)
Hook to execute actions on succeed request.
|
protected <R extends Resource> |
parseToInputStream(R resource)
Shortcut to parse an instance of
ResourceRepresentation to InputStream from Processor via retrieving the Parser thanks to ParserFactory |
protected <R extends Resource> |
parseToObject(java.io.InputStream content,
java.lang.Class<R> clazz)
Shortcut to parse an InputStream to object from Processor via retrieving the
Parser thanks to ParserFactory |
protected abstract int |
postRequestProcess(int statusCode,
RESTRequest<? extends Resource> r,
java.io.InputStream resultStream)
Hook for logic just after the request is executed (regardless of the request's HTTP verb)
|
protected abstract void |
preDeleteRequest(RESTRequest<? extends Resource> r)
Hook for logic just before a DELETE request
|
protected abstract void |
preGetRequest(RESTRequest<? extends Resource> r)
Hook for logic just before a GET request
|
protected abstract java.io.InputStream |
prePostRequest(RESTRequest<? extends Resource> r)
Hook for logic just before a POST request
|
protected abstract java.io.InputStream |
prePutRequest(RESTRequest<? extends Resource> r)
Hook for logic just before a PUT request
|
protected void |
preRequestProcess(RESTRequest<? extends Resource> r)
Hook for logic just before the request is executed (regardless of the request's HTTP verb).
|
protected void |
process(RESTRequest<? extends Resource> r)
|
protected void |
processRequest(RESTRequest<? extends Resource> r)
|
void |
setParserFactory(ParserFactory p)
Set the
ParserFactory |
void |
setPersistableFactory(PersistableFactory d)
Set the
PersistableFactory |
void |
setRESTServiceCallback(Processor.RESTServiceCallback callback)
Set the
Processor.RESTServiceCallback |
protected int |
updateLocalResource(int statusCode,
RESTRequest<? extends Resource> r,
java.io.InputStream resultStream)
Updates the local resource to mirror the server state after the request is executed.
|
protected void |
updateLocalResourceRoutine(int statusCode,
ResourceRepresentation<?> resource) |
protected HttpRequestHandler mHttpRequestHandler
HttpRequestHandler
protected Processor.RESTServiceCallback mRESTServiceCallback
Processor.RESTServiceCallback
protected PersistableFactory mPersistableFactory
PersistableFactory
protected ParserFactory mParserFactory
ParserFactory
protected void preRequestProcess(RESTRequest<? extends Resource> r) throws java.lang.Exception
PersistableFactory
r
- The RESTRequest
instancejava.lang.Exception
protected abstract void preGetRequest(RESTRequest<? extends Resource> r)
r
- The RESTRequest
instanceprotected abstract void preDeleteRequest(RESTRequest<? extends Resource> r)
r
- The RESTRequest
instanceprotected abstract java.io.InputStream prePostRequest(RESTRequest<? extends Resource> r)
r
- The RESTRequest
instanceResourceRepresentation
parsing. See Parser
)protected abstract java.io.InputStream prePutRequest(RESTRequest<? extends Resource> r)
r
- The RESTRequest
instanceResourceRepresentation
parsing. See Parser
)protected abstract int postRequestProcess(int statusCode, RESTRequest<? extends Resource> r, java.io.InputStream resultStream)
statusCode
- The request status coder
- The actual ResourceRepresentation
resultStream
- The server responseprotected void process(RESTRequest<? extends Resource> r) throws java.lang.Exception
r
- The actual RESTRequest
java.lang.Exception
protected void processRequest(RESTRequest<? extends Resource> r)
r
- The actual ResourceRepresentation
preGetRequest(RESTRequest)
,
prePostRequest(RESTRequest)
,
prePutRequest(RESTRequest)
,
preDeleteRequest(RESTRequest)
,
HttpRequestHandler.ProcessorCallback
protected void handleHttpRequestHandlerCallback(int statusCode, RESTRequest<? extends Resource> request)
HttpRequestHandler
by updating status code calling postRequestProcess(int, RESTRequest, InputStream)
hook, set the result stream in RESTRequest
and fires Processor.RESTServiceCallback
statusCode
- Status code returned by HttpRequestHandler
request
- The actual ResourceRepresentation
protected void onFailedRequest(WebService context, int statusCode, RESTRequest<? extends Resource> request)
DefaultRetryAtDelayedTimeFailBehavior
so don't forget to call super.onFailedRequest on your custom Processor classcontext
- Instance of WebService
within which the specified request is runningstatusCode
- Status code of failed requestrequest
- The request which has just failedprotected void onSucceededRequest(WebService context, int statusCode, RESTRequest<? extends Resource> request)
RetryWhenOtherSucceededFailBehavior
so don't forget to call super.onFailedRequest on your custom Processor classcontext
- Instance of WebService
within which the specified request is runningstatusCode
- Status code of succeed requestrequest
- The request which has just succeedprotected java.lang.String inputStreamToString(java.io.InputStream is)
public void setRESTServiceCallback(Processor.RESTServiceCallback callback)
Processor.RESTServiceCallback
callback
- Instance of Processor.RESTServiceCallback
mRESTServiceCallback
public void setPersistableFactory(PersistableFactory d)
PersistableFactory
d
- Instance of PersistableFactory
mPersistableFactory
public void setParserFactory(ParserFactory p)
ParserFactory
p
- Instance of ParserFactory
mParserFactory
protected void mirrorServerState(RESTRequest<? extends Resource> r)
ResourceRepresentation
to true and the RequestState
based on HTTPVerb
:
r
- The actual RESTRequest
protected void mirrorServerStateRoutine(HTTPVerb verb, ResourceRepresentation<?> resource) throws java.lang.Exception
java.lang.Exception
protected int updateLocalResource(int statusCode, RESTRequest<? extends Resource> r, java.io.InputStream resultStream)
statusCode
- The status code resulting of requestr
- The actual RESTRequest
resultStream
- The server's responseprotected void updateLocalResourceRoutine(int statusCode, ResourceRepresentation<?> resource) throws java.lang.Exception
java.lang.Exception
protected Persistable<Resource> getResourcePersistable(Resource resource)
PersistableFactory
resource
- The ResourceRepresentation
you want the Persistable classPersistable
public static boolean isRemotelySync(ResourceRepresentation<?> r)
ResourceRepresentation
is remotely sync or not.r
- The ResourceRepresentation
you wan to know if it's remotely synchronizedpublic boolean checkRequest(RESTRequest<? extends Resource> request)
request
- The actual ResourceRepresentation
protected <R extends Resource> R parseToObject(java.io.InputStream content, java.lang.Class<R> clazz) throws ParsingException
Parser
thanks to ParserFactory
content
- The data you want to parseclazz
- The Class object of the ResourceRepresentation
you want to be mappedResourceRepresentation
ParsingException
protected <R extends Resource> java.io.InputStream parseToInputStream(R resource) throws ParsingException
ResourceRepresentation
to InputStream from Processor via retrieving the Parser
thanks to ParserFactory
resource
- Instance of ResourceRepresentation
you want to parseResourceRepresentation
ParsingException
public PersistableFactory getPersistableFactory()
mPersistableFactory
PersistableFactory