ResponseHandlersManager is a core class of Joty 2.0 Mobile:
with the
org.joty.mobile.web.WebConn.Connector
it helps the developer to assemble
the code for long running operations that must be performed over the network.
All the typical accesses to the Joty Server, either they be disposing or only querying the
database, pass through the use of an instance of this class.
The class allows the definition of what is to be forwarded to the server and collects a stack
of
org.joty.mobile.app.JotyApp.ResponseHandler
abstract class implementations that
represent, in their entirety, the chain of processing of the response got from the server.
The WebConn.Connector object, on its asynch branch, starts the response handling process, driving
the manager to peek the handler at the top of the stack, to execute its handler method implementation
and then, to check if another handler does exist down along the stack and so on ...until the stack is empty.
The instance of the manager, before being passed to synchro part of the WebConn.Connector object,
can collect many ResponseHandler objects;
The
m_params
member hosts possible named object values to allow communications either in
the forward or backward processing. Each manager instance, since the backward processing flow is
completely independent from the forwarding flow, must be referenced properly and, indeed, is
stored in the
JotyApp.m_respManagerCatalog
member and is referenced by its name that may
be composed by the name of the response handling context plus the counting of the instance of it.
The instance count of the backward processing context (typically an Activity), needs to be hosted
inside for proper referencing of the embedded ResponseHandlersManager; the counting is made in
the
JotyApp.m_respManagerCounters
member.
The class can be used also to send many commands to the server and to configure a one only (overall) handling action,
that "waits" for the arrival of all the responses from the server: this is obtained by storing a
"count down" counter in the ResponseHandler object that is set in the configuration section of
the manager, when the ResponseHandler object is pushed into the stack: in the response handling
phase the manager will check this counter : if greater than zero the counter will be decreased else
the handling will take place; see the
checkToExecute
method.
Thanks to its structure and behavior the class can be used also in any "callback" scenario that,
even without involving the communication with the Joty Server, requires the decoupling of the executor
from the code that uses the result of the execution: for an example of such a usage see the
tryChangePassword
method.