Search in sources :

Example 1 with PushEvent

use of com.vodafone360.people.datatypes.PushEvent in project 360-Engine-for-Android by 360.

the class ActivitiesEngine method processCommsResponse.

/**
 * Handle response received from transport layer (via EngineManager)
 *
 * @param resp Received Response item either a Status/Timeline related push
 *            message or a response to a get activities request.
 */
@Override
protected void processCommsResponse(DecodedResponse resp) {
    LogUtils.logD("ActivitiesEngine processCommsResponse");
    // handle push response
    if (resp.mReqId == 0 && resp.mDataTypes.size() > 0) {
        PushEvent evt = (PushEvent) resp.mDataTypes.get(0);
        handlePushRequest(evt.mMessageType);
    } else {
        dequeueRequest(resp.mReqId);
        handleGetActivitiesResponse(resp.mDataTypes);
    }
}
Also used : PushEvent(com.vodafone360.people.datatypes.PushEvent)

Example 2 with PushEvent

use of com.vodafone360.people.datatypes.PushEvent in project 360-Engine-for-Android by 360.

the class ContactSyncEngine method processPushEvent.

/**
 * Determines if a given response is a push message and processes in this
 * case TODO: we need the check for Me Profile be migrated to he new engine
 *
 * @param resp Response to check and process
 * @return true if the response was processed
 */
private boolean processPushEvent(DecodedResponse resp) {
    if (resp.mDataTypes == null || resp.mDataTypes.size() == 0) {
        return false;
    }
    BaseDataType dataType = resp.mDataTypes.get(0);
    if ((dataType == null) || dataType.getType() != BaseDataType.PUSH_EVENT_DATA_TYPE) {
        return false;
    }
    PushEvent pushEvent = (PushEvent) dataType;
    LogUtils.logV("Push Event Type = " + pushEvent.mMessageType);
    switch(pushEvent.mMessageType) {
        case CONTACTS_CHANGE:
            LogUtils.logI("ContactSyncEngine.processCommsResponse - Contacts changed push message received");
            mServerSyncRequired = true;
            // fetch the newest groups
            EngineManager.getInstance().getGroupsEngine().addUiGetGroupsRequest();
            mEventCallback.kickWorkerThread();
            break;
        case SYSTEM_NOTIFICATION:
            LogUtils.logI("ContactSyncEngine.processCommsResponse - System notification push message received");
            break;
        default:
            // do nothing.
            break;
    }
    return true;
}
Also used : PushEvent(com.vodafone360.people.datatypes.PushEvent) BaseDataType(com.vodafone360.people.datatypes.BaseDataType)

Example 3 with PushEvent

use of com.vodafone360.people.datatypes.PushEvent in project 360-Engine-for-Android by 360.

the class PresenceEngine method handlePushEvent.

private void handlePushEvent(PushEvent event) {
    switch(event.mMessageType) {
        case AVAILABILITY_STATE_CHANGE:
            PushAvailabilityEvent pa = (PushAvailabilityEvent) event;
            updatePresenceDatabase(pa.mChanges);
            break;
        case CHAT_MESSAGE:
            PushChatMessageEvent pc = (PushChatMessageEvent) event;
            // update the DB with an incoming message
            updateChatDatabase(pc.getChatMsg(), TimelineSummaryItem.Type.INCOMING);
            break;
        case CLOSED_CONVERSATION:
            PushClosedConversationEvent pcc = (PushClosedConversationEvent) event;
            // delete the conversation in DB
            if (pcc.getConversation() != null) {
                ChatDbUtils.deleteConversationById(pcc.getConversation(), mDbHelper);
            }
            break;
        default:
            LogUtils.logE("PresenceEngine.handleServerResponse():" + " push message type was not recognized:" + event.getType());
    }
}
Also used : PushAvailabilityEvent(com.vodafone360.people.datatypes.PushAvailabilityEvent) PushClosedConversationEvent(com.vodafone360.people.datatypes.PushClosedConversationEvent) PushChatMessageEvent(com.vodafone360.people.datatypes.PushChatMessageEvent)

Example 4 with PushEvent

use of com.vodafone360.people.datatypes.PushEvent in project 360-Engine-for-Android by 360.

the class IdentityEngine method processCommsResponse.

/**
 * Process a response received from Server. The response is handled
 * according to the current IdentityEngine state.
 *
 * @param resp The decoded response.
 */
@Override
protected void processCommsResponse(DecodedResponse resp) {
    LogUtils.logD("IdentityEngine.processCommsResponse() - resp = " + resp);
    if ((null == resp) || (null == resp.mDataTypes)) {
        LogUtils.logE("Response objects or its contents were null. Aborting...");
        return;
    }
    // TODO replace this whole block with the response type in the DecodedResponse class in the future!
    if (resp.mReqId == 0 && resp.mDataTypes.size() > 0) {
        // push msg
        PushEvent evt = (PushEvent) resp.mDataTypes.get(0);
        handlePushResponse(evt.mMessageType);
    } else if (resp.mDataTypes.size() > 0) {
        // regular response
        switch(resp.mDataTypes.get(0).getType()) {
            case BaseDataType.MY_IDENTITY_DATA_TYPE:
                handleGetMyIdentitiesResponse(resp.mDataTypes);
                break;
            case BaseDataType.AVAILABLE_IDENTITY_DATA_TYPE:
                handleGetAvailableIdentitiesResponse(resp.mDataTypes);
                break;
            case BaseDataType.IDENTITY_CAPABILITY_DATA_TYPE:
                handleSetIdentityStatus(resp.mDataTypes);
                break;
            case BaseDataType.STATUS_MSG_DATA_TYPE:
                handleValidateIdentityCredentials(resp.mDataTypes);
                break;
            case BaseDataType.IDENTITY_DELETION_DATA_TYPE:
                handleDeleteIdentity(resp.mDataTypes);
                break;
            default:
                LogUtils.logW("IdentityEngine.processCommsResponse DEFAULT should never happened.");
                break;
        }
    } else {
        // responses data list is 0, that means e.g. no identities in an identities response
        LogUtils.logW("IdentityEngine.processCommsResponse List was empty!");
        if (resp.getResponseType() == DecodedResponse.ResponseType.GET_MY_IDENTITIES_RESPONSE.ordinal()) {
            pushIdentitiesToUi(ServiceUiRequest.GET_MY_IDENTITIES);
        } else if (resp.getResponseType() == DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()) {
            pushIdentitiesToUi(ServiceUiRequest.GET_AVAILABLE_IDENTITIES);
        }
    }
// end: replace this whole block with the response type in the DecodedResponse class in the future!
}
Also used : PushEvent(com.vodafone360.people.datatypes.PushEvent)

Example 5 with PushEvent

use of com.vodafone360.people.datatypes.PushEvent in project 360-Engine-for-Android by 360.

the class DecoderThread method run.

/**
 * Thread's run function If the decoding queue contains any entries we
 * decode the first response and add the decoded data to the response queue.
 * If the decode queue is empty, the thread will become inactive. It is
 * resumed when a raw data entry is added to the decode queue.
 */
public void run() {
    LogUtils.logI("DecoderThread.run() [Start thread]");
    while (mRunning) {
        EngineId engineId = EngineId.UNDEFINED;
        Type type = Type.PUSH_MSG;
        int reqId = -1;
        try {
            if (mResponses.size() > 0) {
                LogUtils.logI("DecoderThread.run() Decoding [" + mResponses.size() + "x] responses");
                // Decode first entry in queue
                RawResponse decode = mResponses.get(0);
                reqId = decode.mReqId;
                if (!decode.mIsPushMessage) {
                    // Attempt to get type from request
                    Request request = QueueManager.getInstance().getRequest(reqId);
                    if (request != null) {
                        type = request.mType;
                        engineId = request.mEngineId;
                        long backendResponseTime = decode.mTimeStamp - request.getAuthTimestamp();
                        LogUtils.logD("Backend response time was " + backendResponseTime + "ms");
                    } else {
                        type = Type.COMMON;
                    }
                }
                DecodedResponse response = mHessianDecoder.decodeHessianByteArray(reqId, decode.mData, type, decode.mIsCompressed, engineId);
                // if we have a push message let's try to find out to which engine it should be routed
                if ((response.getResponseType() == DecodedResponse.ResponseType.PUSH_MESSAGE.ordinal()) && (response.mDataTypes.get(0) != null)) {
                    // for push messages we have to override the engine id as it is parsed inside the hessian decoder
                    engineId = ((PushEvent) response.mDataTypes.get(0)).mEngineId;
                    response.mSource = engineId;
                // TODO mSource should get the engineId inside the decoder once types for mDataTypes is out. see PAND-1805.
                }
                // the request ID.
                if (type == Type.PUSH_MSG && reqId != 0 && engineId == EngineId.UNDEFINED) {
                    Request request = QueueManager.getInstance().getRequest(reqId);
                    if (request != null) {
                        engineId = request.mEngineId;
                    }
                }
                if (engineId == EngineId.UNDEFINED) {
                    LogUtils.logE("DecoderThread.run() Unknown engine for message with type[" + type.name() + "]");
                // TODO: Throw Exception for undefined messages, as
                // otherwise they might always remain on the Queue?
                }
                // Add data to response queue
                HttpConnectionThread.logV("DecoderThread.run()", "Add message[" + decode.mReqId + "] to ResponseQueue for engine[" + engineId + "] with data [" + response.mDataTypes + "]");
                mRespQueue.addToResponseQueue(response);
                // Remove item from our list of responses.
                mResponses.remove(0);
                // be nice to the other threads
                Thread.sleep(THREAD_SLEEP_TIME);
            } else {
                synchronized (this) {
                    // No waiting responses, so the thread should sleep.
                    try {
                        LogUtils.logV("DecoderThread.run() [Waiting for more responses]");
                        wait();
                    } catch (InterruptedException ie) {
                    // Do nothing
                    }
                }
            }
        } catch (Throwable t) {
            /*
                 * Keep thread running regardless of error. When something goes
                 * wrong we should remove response from queue and report error
                 * back to engine.
                 */
            if (mResponses.size() > 0) {
                mResponses.remove(0);
            }
            if (type != Type.PUSH_MSG && engineId != EngineId.UNDEFINED) {
                List<BaseDataType> list = new ArrayList<BaseDataType>();
                // this error type was chosen to make engines remove request
                // or retry
                // we may consider using other error code later
                ServerError error = new ServerError(ServerError.ErrorType.INTERNALERROR);
                error.errorDescription = "Decoder thread was unable to decode server message";
                list.add(error);
                mRespQueue.addToResponseQueue(new DecodedResponse(reqId, list, engineId, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            }
            LogUtils.logE("DecoderThread.run() Throwable on reqId[" + reqId + "]", t);
        }
    }
    LogUtils.logI("DecoderThread.run() [End thread]");
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) EngineId(com.vodafone360.people.engine.EngineManager.EngineId) ServerError(com.vodafone360.people.datatypes.ServerError) Request(com.vodafone360.people.service.io.Request) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) Type(com.vodafone360.people.service.io.Request.Type) ArrayList(java.util.ArrayList) List(java.util.List) BaseDataType(com.vodafone360.people.datatypes.BaseDataType)

Aggregations

PushEvent (com.vodafone360.people.datatypes.PushEvent)8 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)6 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)4 ArrayList (java.util.ArrayList)4 MediumTest (android.test.suitebuilder.annotation.MediumTest)3 Suppress (android.test.suitebuilder.annotation.Suppress)2 EngineId (com.vodafone360.people.engine.EngineManager.EngineId)2 PushAvailabilityEvent (com.vodafone360.people.datatypes.PushAvailabilityEvent)1 PushChatMessageEvent (com.vodafone360.people.datatypes.PushChatMessageEvent)1 PushClosedConversationEvent (com.vodafone360.people.datatypes.PushClosedConversationEvent)1 ServerError (com.vodafone360.people.datatypes.ServerError)1 SystemNotification (com.vodafone360.people.datatypes.SystemNotification)1 Request (com.vodafone360.people.service.io.Request)1 Type (com.vodafone360.people.service.io.Request.Type)1 RpgPushMessage (com.vodafone360.people.service.io.rpg.RpgPushMessage)1 HessianDecoder (com.vodafone360.people.service.utils.hessian.HessianDecoder)1 IOException (java.io.IOException)1 List (java.util.List)1