Search in sources :

Example 11 with ResponseQueue

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()));
        }
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)

Example 12 with ResponseQueue

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()));
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) EngineId(com.vodafone360.people.engine.EngineManager.EngineId) Request(com.vodafone360.people.service.io.Request) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue) QueueManager(com.vodafone360.people.service.io.QueueManager)

Example 13 with ResponseQueue

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");
    }
}
Also used : ResponseQueue(com.vodafone360.people.service.io.ResponseQueue)

Aggregations

DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)11 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)10 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)8 ServerError (com.vodafone360.people.datatypes.ServerError)8 ArrayList (java.util.ArrayList)8 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)3 Identity (com.vodafone360.people.datatypes.Identity)2 EngineId (com.vodafone360.people.engine.EngineManager.EngineId)2 QueueManager (com.vodafone360.people.service.io.QueueManager)2 Request (com.vodafone360.people.service.io.Request)2 ActivityContact (com.vodafone360.people.datatypes.ActivityContact)1 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)1 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)1 IdentityCapability (com.vodafone360.people.datatypes.IdentityCapability)1 SimpleText (com.vodafone360.people.datatypes.SimpleText)1 Type (com.vodafone360.people.service.io.Request.Type)1 URL (java.net.URL)1 List (java.util.List)1