use of com.vodafone360.people.service.io.ResponseQueue in project 360-Engine-for-Android by 360.
the class RequestQueue method clearAllRequests.
/**
* Clears all requests from the queue and puts null responses on the
* response queue to tell the engines that they have been cleared. This
* should be called from the connection thread as soon as it is stopped.
*/
protected void clearAllRequests() {
synchronized (QueueManager.getInstance().lock) {
ResponseQueue responseQueue = ResponseQueue.getInstance();
for (int i = 0; i < mRequests.size(); i++) {
Request request = mRequests.get(i);
LogUtils.logE("RequestQueue.clearActiveRequests() Deleting request " + request.getRequestId());
mRequests.remove(i--);
// necessarily times out before)
if (request.getExpiryDate() > 0) {
mTimeOutWatcher.removeRequest(request);
}
responseQueue.addToResponseQueue(new DecodedResponse(request.getRequestId(), null, request.mEngineId, DecodedResponse.ResponseType.TIMED_OUT_RESPONSE.ordinal()));
}
}
}
use of com.vodafone360.people.service.io.ResponseQueue in project 360-Engine-for-Android by 360.
the class HttpConnectionThread method addErrorToResponseQueue.
/**
* Adds errors to the response queue whenever there is an HTTP error on the
* backend.
*
* @param reqIds The request IDs the error happened for.
*/
public void addErrorToResponseQueue(List<Integer> reqIds) {
EngineId source = null;
QueueManager requestQueue = QueueManager.getInstance();
ResponseQueue responseQueue = ResponseQueue.getInstance();
for (Integer reqId : reqIds) {
// attempt to get type from request
Request req = requestQueue.getRequest(reqId);
if (req != null)
source = req.mEngineId;
responseQueue.addToResponseQueue(new DecodedResponse(reqId, null, source, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
}
}
use of com.vodafone360.people.service.io.ResponseQueue in project 360-Engine-for-Android by 360.
the class BaseEngine method processCommsInQueue.
/**
* Should be called by the run() function to process the comms in queue.
* Calling this function will result in the processCommsResponse function
* being called once. The derived engine implementation should do its
* processing of each response in that function. If the engine set the
* request ID using the setReqId function then messages which don't match
* will be taken off the queue and deleted.
*
* @return true if a response was taken from the queue and processed.
*/
protected boolean processCommsInQueue() {
final ResponseQueue queue = ResponseQueue.getInstance();
if (queue != null) {
final ResponseQueue.DecodedResponse resp = queue.getNextResponse(mEngineId);
if (resp == null) {
mCommsResponseOutstanding = false;
return false;
}
boolean processResponse = false;
if (resp.mReqId == null || mActiveRequestId == null) {
processResponse = true;
} else if (mActiveRequestId.equals(resp.mReqId)) {
mActiveRequestId = null;
processResponse = true;
}
if (processResponse) {
processCommsResponse(resp);
}
return processResponse;
} else {
throw new RuntimeException("BaseEngine.processCommsInQueue - ResponseQueue cannot be null");
}
}
Aggregations