Search in sources :

Example 31 with Request

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

the class SyncMeEngine method uploadMeProfile.

/**
     * * Sends a SetMe request to the server in the case that the me profile has
     * been changed locally. If the me profile thumbnail has always been changed
     * it will also be uploaded to the server.
     */
private void uploadMeProfile() {
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        return;
    }
    newState(State.UPDATING_ME_PROFILE);
    Contact meProfile = new Contact();
    mDbHelper.fetchContact(SyncMeDbUtils.getMeProfileLocalContactId(mDbHelper), meProfile);
    mUploadedMeDetails = SyncMeDbUtils.saveContactDetailChanges(mDbHelper, meProfile);
    setReqId(Contacts.setMe(this, mUploadedMeDetails, meProfile.aboutMe, meProfile.gender));
}
Also used : Contact(com.vodafone360.people.datatypes.Contact)

Example 32 with Request

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

the class UpdateNativeContacts method onTimeoutEvent.

/**
     * @see BaseSyncProcessor#onTimeoutEvent()
     */
@Override
public void onTimeoutEvent() {
    LogUtils.logD("UpdateNativeContacts.onTimeoutEvent()");
    // call the tick method of the NativeExporter
    final boolean isDone = mNativeExporter.tick();
    // get the index of the last processed id
    final int position = mNativeExporter.getPosition();
    // get the total count of ids to process
    final int total = mNativeExporter.getCount();
    // get the percentage out of position and total count
    final int percentage = (total != 0) ? ((position * 100) / total) : 100;
    LogUtils.logD("UpdateNativeContacts.onTimeoutEvent() - pos=" + position + ", total=" + total + ", percentage=" + percentage);
    // check the NativeExporter progress
    if (!isDone) {
        // yield some time to the other engines and request to be called back immediately
        setTimeout(0);
    } else {
        // FIXME: More useful error reporting beyond just ERROR_UNKNOWN
        final ServiceStatus status = mNativeExporter.getResult() == NativeImporter.RESULT_OK ? ServiceStatus.SUCCESS : ServiceStatus.ERROR_UNKNOWN;
        LogUtils.logD("FetchNativeContacts.onTimeoutEvent() - complete(" + status + ")");
        complete(status);
    }
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 33 with Request

use of com.vodafone360.people.service.io.Request 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 34 with Request

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

the class SyncMeEngine method processSetMeResponse.

/**
     * Processes the response from a SetMe request. If successful, the server
     * IDs will be stored in the local database if they have changed. Otherwise
     * the processor will complete with a suitable error.
     * @param resp Response from server.
     */
private void processSetMeResponse(final DecodedResponse resp) {
    LogUtils.logD("SyncMeProfile.processMeProfileUpdateResponse()");
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactChanges result = (ContactChanges) resp.mDataTypes.get(0);
        SyncMeDbUtils.updateMeProfileDbDetailIds(mDbHelper, mUploadedMeDetails, result);
        if (updateRevisionPostUpdate(result.mServerRevisionBefore, result.mServerRevisionAfter, mFromRevision, mDbHelper)) {
            mFromRevision = result.mServerRevisionAfter;
        }
    }
    completeUiRequest(status);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ContactChanges(com.vodafone360.people.datatypes.ContactChanges)

Example 35 with Request

use of com.vodafone360.people.service.io.Request 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)

Aggregations

Request (com.vodafone360.people.service.io.Request)43 QueueManager (com.vodafone360.people.service.io.QueueManager)27 ServiceStatus (com.vodafone360.people.service.ServiceStatus)16 ArrayList (java.util.ArrayList)16 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)12 ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)12 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)11 Suppress (android.test.suitebuilder.annotation.Suppress)10 DatabaseHelper (com.vodafone360.people.database.DatabaseHelper)9 IEngineEventCallback (com.vodafone360.people.engine.IEngineEventCallback)9 IContactSyncCallback (com.vodafone360.people.engine.contactsync.IContactSyncCallback)9 ProcessorFactory (com.vodafone360.people.engine.contactsync.ProcessorFactory)9 ServerError (com.vodafone360.people.datatypes.ServerError)6 IOException (java.io.IOException)6 Identity (com.vodafone360.people.datatypes.Identity)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Bundle (android.os.Bundle)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)4 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)4 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)4