Search in sources :

Example 16 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.

the class SyncMeEngine method processUpdateStatusResponse.

/**
     * This method processes the response to status update by setMe() method
     * @param resp Response - the expected response datatype is ContactChanges
     */
private void processUpdateStatusResponse(final DecodedResponse resp) {
    LogUtils.logD("SyncMeDbUtils processUpdateStatusResponse()");
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactChanges result = (ContactChanges) resp.mDataTypes.get(0);
        LogUtils.logI("SyncMeProfile.processUpdateStatusResponse() - Me profile userId = " + result.mUserProfile.userID);
        SyncMeDbUtils.savePresenceStatusResponse(mDbHelper, result);
    }
    completeUiRequest(status);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ContactChanges(com.vodafone360.people.datatypes.ContactChanges)

Example 17 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.

the class RequestQueue method clearActiveRequests.

/**
     * Return the current (i.e. most recently generated) request id.
     * 
     * @return the current request id.
     */
/*
     * public synchronized int getCurrentId(){ return mCurrentRequestId; }
     */
/**
     * Clear active requests (i.e add dummy response to response queue).
     * 
     * @param rpgOnly
     */
protected void clearActiveRequests(boolean rpgOnly) {
    synchronized (QueueManager.getInstance().lock) {
        ResponseQueue rQ = ResponseQueue.getInstance();
        for (int i = 0; i < mRequests.size(); i++) {
            Request request = mRequests.get(i);
            if (request.isActive() && (!rQ.responseExists(request.getRequestId()))) {
                if (!rpgOnly || (rpgOnly && ((request.getAuthenticationType() == Request.USE_RPG) || (request.getAuthenticationType() == Request.USE_BOTH)))) {
                    LogUtils.logE("RequestQueue.clearActiveRequests() Deleting request " + request.getRequestId());
                    mRequests.remove(i);
                    // necessarily times out before)
                    if (request.getExpiryDate() > 0) {
                        mTimeOutWatcher.removeRequest(request);
                    }
                    i--;
                    rQ.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 18 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.

the class ResponseQueue method addToResponseQueue.

/**
     * Adds a response item to the queue.
     * 
     * @param reqId The request ID to add the response for.
     * @param data The response data to add to the queue.
     * @param source The corresponding engine that fired off the request for the
     *            response.
     */
public void addToResponseQueue(final DecodedResponse response) {
    synchronized (QueueManager.getInstance().lock) {
        ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.UNKNOWN_DATA_TYPE, response.mDataTypes);
        if (status == ServiceStatus.ERROR_INVALID_SESSION) {
            EngineManager em = EngineManager.getInstance();
            if (em != null) {
                LogUtils.logE("Logging out the current user because of invalide session");
                em.getLoginEngine().logoutAndRemoveUser();
                return;
            }
        }
        synchronized (mResponses) {
            mResponses.add(response);
        }
        Request request = RequestQueue.getInstance().removeRequest(response.mReqId);
        if (request != null) {
            // we suppose the response being handled by the same engine 
            // that issued the request with the given id
            response.mSource = request.mEngineId;
        }
        mEngMgr = EngineManager.getInstance();
        if (mEngMgr != null) {
            mEngMgr.onCommsInMessage(response.mSource);
        }
    }
}
Also used : EngineManager(com.vodafone360.people.engine.EngineManager) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 19 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.

the class UploadServerContactsTest method reportBackToEngine.

@Override
public void reportBackToEngine(int reqId, EngineId engine) {
    Log.d(LOG_TAG, "reportBackToEngine");
    ResponseQueue respQueue = ResponseQueue.getInstance();
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    try {
        assertEquals(mEng.engineId(), engine);
        synchronized (mEng.mWaitForReqIdLock) {
            if (mEng.mActiveReqId == null || mEng.mActiveReqId.intValue() != reqId) {
                try {
                    mEng.mWaitForReqIdLock.wait(MAX_WAIT_FOR_REQ_ID);
                } catch (InterruptedException e) {
                }
                assertEquals(Integer.valueOf(reqId), mEng.mActiveReqId);
            }
        }
        switch(mState) {
            case ADD_CONTACT_LIST:
                reportBackAddContactSuccess(reqId, data);
                break;
            case MODIFY_CONTACT_LIST:
                reportModifyContactSuccess(reqId, data);
                break;
            case DELETE_CONTACT_LIST:
                reportDeleteContactSuccess(reqId, data);
                break;
            case DELETE_CONTACT_DETAIL_LIST:
                reportDeleteContactDetailSuccess(reqId, data);
                break;
            case ADD_NEW_GROUP_LIST:
                reportBackAddGroupSuccess(reqId, data);
                break;
            case DELETE_GROUP_LIST:
                reportDeleteGroupListSuccess(reqId, data);
                break;
            default:
                fail("Unexpected request from processor");
        }
    } catch (Throwable err) {
        ServerError serverError = new ServerError(ServerError.ErrorType.INTERNALERROR);
        serverError.errorDescription = err + "\n";
        for (int i = 0; i < err.getStackTrace().length; i++) {
            StackTraceElement v = err.getStackTrace()[i];
            serverError.errorDescription += "\t" + v + "\n";
        }
        Log.e(LOG_TAG, "Exception:\n" + serverError.errorDescription);
        data.clear();
        data.add(serverError);
    }
    respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
    mEng.onCommsInMessage();
    Log.d(LOG_TAG, "reportBackToEngine - message added to response queue");
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue)

Example 20 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.

the class PeopleServiceTest method reportBackToFramework.

@Override
public void reportBackToFramework(int reqId, EngineId engine) {
    /*
		 * We are not interested in testing specific engines in those tests then for all kind of 
		 * requests we will return error because it is handled by all engines, just to finish flow.
		 */
    ResponseQueue respQueue = ResponseQueue.getInstance();
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    ServerError se1 = new ServerError(ServerError.ErrorType.INTERNALERROR);
    se1.errorDescription = "Test error produced by test framework, ignore it";
    data.add(se1);
    respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue)

Aggregations

DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)26 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)23 ArrayList (java.util.ArrayList)23 ServiceStatus (com.vodafone360.people.service.ServiceStatus)13 ServerError (com.vodafone360.people.datatypes.ServerError)12 IOException (java.io.IOException)10 MediumTest (android.test.suitebuilder.annotation.MediumTest)9 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)8 PushEvent (com.vodafone360.people.datatypes.PushEvent)7 HessianDecoder (com.vodafone360.people.service.utils.hessian.HessianDecoder)7 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)6 Contact (com.vodafone360.people.datatypes.Contact)5 Suppress (android.test.suitebuilder.annotation.Suppress)4 Identity (com.vodafone360.people.datatypes.Identity)4 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)3 ExternalResponseObject (com.vodafone360.people.datatypes.ExternalResponseObject)3 Request (com.vodafone360.people.service.io.Request)3 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)2 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)2