Search in sources :

Example 1 with EngineId

use of com.vodafone360.people.engine.EngineManager.EngineId in project 360-Engine-for-Android by 360.

the class EngineManager method onCommsInMessage.

/**
 * Respond to incoming message received from Comms layer. If this message
 * has a valid engine id it is routed to that engine, otherwise The
 * {@link EngineManager} will try to get the next response.
 *
 * @param source EngineId associated with incoming message.
 */
public void onCommsInMessage(EngineId source) {
    BaseEngine engine = null;
    if (source != null) {
        engine = mEngineList.get(source.ordinal());
    }
    if (engine != null) {
        engine.onCommsInMessage();
    } else {
        LogUtils.logE("EngineManager.onCommsInMessage - " + "Cannot dispatch message, unknown source " + source);
        final ResponseQueue queue = ResponseQueue.getInstance();
        queue.getNextResponse(source);
    }
}
Also used : ResponseQueue(com.vodafone360.people.service.io.ResponseQueue)

Example 2 with EngineId

use of com.vodafone360.people.engine.EngineManager.EngineId in project 360-Engine-for-Android by 360.

the class ContentEngine method run.

/**
 * run method of this engine iterates over the downloadqueue, makes requests
 * out of ContentObjects and puts them into QueueManager queue.
 */
@Override
public final void run() {
    // set it to true so at least one response is treated per call to run()
    boolean carryOn = true;
    final long runStartTime = System.currentTimeMillis();
    while (isCommsResponseOutstanding() && carryOn) {
        // process as many responses as we can during the allowed time slot
        processCommsInQueue();
        carryOn = System.currentTimeMillis() - runStartTime < ALLOWED_RUNNING_TIME_MS;
    }
    // outstanding responses
    if (isCommsResponseOutstanding())
        return;
    ContentObject co;
    boolean queueChanged = false;
    while ((co = mDownloadQueue.poll()) != null) {
        queueChanged = true;
        // set the status of this contentobject to transferring
        co.setTransferStatus(ContentObject.TransferStatus.TRANSFERRING);
        Request request = new Request(co.getUrl().toString(), co.getUrlParams(), engineId());
        QueueManager.getInstance().addRequest(request);
        // important: later we will match done requests back to the
        // contentobject using this map
        requestContentObjectMatchTable.put(request.getRequestId(), co);
    }
    if (queueChanged) {
        QueueManager.getInstance().fireQueueStateChanged();
    }
}
Also used : ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) Request(com.vodafone360.people.service.io.Request)

Example 3 with EngineId

use of com.vodafone360.people.engine.EngineManager.EngineId in project 360-Engine-for-Android by 360.

the class SyncMeEngine method downloadMeProfileThumbnail.

/**
 * The call to download the thumbnail picture for the me profile.
 * @param url String - picture url of Me Profile (comes with getMyChanges())
 * @param localContactId long - local contact id of Me Profile
 */
private void downloadMeProfileThumbnail(final String url, final long localContactId) {
    if (NetworkAgent.getAgentState() == NetworkAgent.AgentState.CONNECTED) {
        Request request = new Request(url, ThumbnailUtils.REQUEST_THUMBNAIL_URI, engineId());
        newState(State.FETCHING_ME_PROFILE_THUMBNAIL);
        setReqId(QueueManager.getInstance().addRequestAndNotify(request));
    }
}
Also used : ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) Request(com.vodafone360.people.service.io.Request)

Example 4 with EngineId

use of com.vodafone360.people.engine.EngineManager.EngineId 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)

Example 5 with EngineId

use of com.vodafone360.people.engine.EngineManager.EngineId in project 360-Engine-for-Android by 360.

the class Presence method getPresenceList.

// function?
/**
 * Retrieve current presence list
 *
 * @param engineId ID for Presence engine.
 * @param recipientUserIdList List of user IDs.
 */
public static void getPresenceList(EngineId engineId, Map<String, List<String>> recipientUserIdList) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Presence.getPresenceList() No session, return");
        return;
    }
    Request request = new Request(EMPTY, Request.Type.PRESENCE_LIST, engineId, false, Settings.API_REQUESTS_TIMEOUT_PRESENCE_LIST);
    if (recipientUserIdList != null) {
        // If not specified, then all presence information will be returned
        request.addData("tos", ApiUtils.createHashTable(recipientUserIdList));
    }
    QueueManager.getInstance().addRequest(request);
    QueueManager.getInstance().fireQueueStateChanged();
}
Also used : Request(com.vodafone360.people.service.io.Request)

Aggregations

DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)11 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)9 ServerError (com.vodafone360.people.datatypes.ServerError)9 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)9 ArrayList (java.util.ArrayList)9 Request (com.vodafone360.people.service.io.Request)5 EngineId (com.vodafone360.people.engine.EngineManager.EngineId)4 Identity (com.vodafone360.people.datatypes.Identity)3 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)3 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)2 ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)2 QueueManager (com.vodafone360.people.service.io.QueueManager)2 IOException (java.io.IOException)2 ActivityContact (com.vodafone360.people.datatypes.ActivityContact)1 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)1 ExternalResponseObject (com.vodafone360.people.datatypes.ExternalResponseObject)1 IdentityCapability (com.vodafone360.people.datatypes.IdentityCapability)1 PushChatConversationEvent (com.vodafone360.people.datatypes.PushChatConversationEvent)1 PushChatMessageEvent (com.vodafone360.people.datatypes.PushChatMessageEvent)1 PushClosedConversationEvent (com.vodafone360.people.datatypes.PushClosedConversationEvent)1