Search in sources :

Example 76 with Request

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

the class TimeOutWatcher method removeRequest.

/**
 * Removes a request from being watched for timeouts.
 *
 * @param request the request to remove
 */
public void removeRequest(Request request) {
    // just ignore the request
    if (!mIsRunning)
        return;
    synchronized (QueueManager.getInstance().lock) {
        if ((request != null) && (request.getExpiryDate() >= 0) && mRequests != null) {
            int index = -1;
            for (int i = 0; i < mRequests.size(); i++) {
                final Request currentRequest = mRequests.get(i);
                if (currentRequest == request) {
                    index = i;
                    mRequests.remove(i);
                    break;
                }
            }
            // notify, we can still sleep!
            if (index == 0) {
                LogUtils.logV("TimeOutWatcher.removeRequest(): wake up the thread");
                QueueManager.getInstance().lock.notify();
            }
        }
    }
}
Also used : Request(com.vodafone360.people.service.io.Request)

Example 77 with Request

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

the class HessianDecoder method decodeHessianByteArray.

/**
 * Parse Hessian encoded byte array placing parsed contents into List.
 *
 * @param requestId The request ID that the response was received for.
 * @param data byte array containing Hessian encoded data
 * @param type Event type Shows whether we have a push or common message type.
 * @param isZipped True if the response is gzipped, otherwise false.
 * @param engineId The engine ID the response should be reported back to.
 *
 * @return The response containing the decoded objects.
 *
 * @throws IOException Thrown if there is something wrong with reading the (gzipped) hessian encoded input stream.
 */
public DecodedResponse decodeHessianByteArray(int requestId, byte[] data, Request.Type type, boolean isZipped, EngineId engineId) throws IOException {
    InputStream is = null;
    InputStream bis = null;
    if (isZipped == true) {
        LogUtils.logV("HessianDecoder.decodeHessianByteArray() Handle zipped data");
        bis = new ByteArrayInputStream(data);
        is = new GZIPInputStream(bis, data.length);
    } else {
        LogUtils.logV("HessianDecoder.decodeHessianByteArray() Handle non-zipped data");
        is = new ByteArrayInputStream(data);
    }
    DecodedResponse response = null;
    mMicroHessianInput.init(is);
    LogUtils.logV("HessianDecoder.decodeHessianByteArray() Begin Hessian decode");
    try {
        response = decodeResponse(is, requestId, type, isZipped, engineId);
    } catch (IOException e) {
        LogUtils.logE("HessianDecoder.decodeHessianByteArray() " + "IOException during decodeResponse", e);
    }
    CloseUtils.close(bis);
    CloseUtils.close(is);
    return response;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 78 with Request

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

the class UploadServerContacts method sendNextAddGroupRelationsPage.

/**
 * Sends next add contact/group relation request to the server. Many
 * contacts can be added by a single request.
 */
private void sendNextAddGroupRelationsPage() {
    ContactChangeInfo info = null;
    mActiveGroupId = null;
    mContactIdList.clear();
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> groupInfoList = new ArrayList<ContactChangeInfo>();
    long startTime = System.nanoTime();
    if (!ContactChangeLogTable.fetchContactChangeLog(groupInfoList, ContactChangeType.ADD_GROUP_REL, 0, MAX_UP_PAGE_SIZE, mDb.getReadableDatabase())) {
        LogUtils.logE("UploadServerContacts." + "sendNextAddGroupRelationsPage() Unable to fetch add " + "group relations from database");
        complete(ServiceStatus.ERROR_DATABASE_CORRUPT);
        return;
    }
    mDbSyncTime += (System.nanoTime() - startTime);
    if (groupInfoList.size() == 0) {
        moveToNextState();
        return;
    }
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> deleteInfoList = new ArrayList<ContactChangeInfo>();
    for (int i = 0; i < groupInfoList.size(); i++) {
        info = groupInfoList.get(i);
        if (info.mServerContactId == null) {
            info.mServerContactId = mDb.fetchServerId(info.mLocalContactId);
        }
        if (info.mServerContactId != null && info.mGroupOrRelId != null) {
            if (mActiveGroupId == null) {
                mActiveGroupId = info.mGroupOrRelId;
            }
            if (info.mGroupOrRelId.equals(mActiveGroupId)) {
                mContactIdList.add(info.mServerContactId);
                mContactChangeInfoList.add(info);
            }
            continue;
        }
        LogUtils.logE("UploadServerContact.sendNextAddGroupRelationsPage() " + "Invalid add group change: SID = " + info.mServerContactId + ", gid=" + info.mGroupOrRelId);
        deleteInfoList.add(info);
    }
    mDb.deleteContactChanges(deleteInfoList);
    if (mActiveGroupId == null) {
        moveToNextState();
        return;
    }
    mGroupList.clear();
    GroupItem group = new GroupItem();
    group.mId = mActiveGroupId;
    mGroupList.add(group);
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        complete(NetworkAgent.getServiceStatusfromDisconnectReason());
        return;
    }
    mNoOfItemsSent = mGroupList.size();
    setReqId(GroupPrivacy.addContactGroupRelations(getEngine(), mContactIdList, mGroupList));
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem)

Example 79 with Request

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

the class UploadServerContacts method sendNextDelGroupRelationsPage.

/**
 * Sends next delete contact/group relation request to the server.
 */
private void sendNextDelGroupRelationsPage() {
    ContactChangeInfo info = null;
    mActiveGroupId = null;
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> groupInfoList = new ArrayList<ContactChangeInfo>();
    long startTime = System.nanoTime();
    if (!ContactChangeLogTable.fetchContactChangeLog(groupInfoList, ContactChangeType.DELETE_GROUP_REL, 0, MAX_UP_PAGE_SIZE, mDb.getReadableDatabase())) {
        LogUtils.logE("UploadServerContacts." + "sendNextDelGroupRelationsPage() Unable to fetch delete " + "group relations from database");
        complete(ServiceStatus.ERROR_DATABASE_CORRUPT);
        return;
    }
    mDbSyncTime += (System.nanoTime() - startTime);
    if (groupInfoList.size() == 0) {
        moveToNextState();
        return;
    }
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> deleteInfoList = new ArrayList<ContactChangeInfo>();
    for (int i = 0; i < groupInfoList.size(); i++) {
        info = groupInfoList.get(i);
        if (info.mServerContactId == null) {
            info.mServerContactId = mDb.fetchServerId(info.mLocalContactId);
        }
        if (info.mServerContactId != null && info.mGroupOrRelId != null) {
            if (mActiveGroupId == null) {
                mActiveGroupId = info.mGroupOrRelId;
            }
            if (mActiveGroupId.equals(info.mGroupOrRelId)) {
                mContactIdList.add(info.mServerContactId);
                mContactChangeInfoList.add(info);
            }
            continue;
        }
        LogUtils.logE("UploadServerContact.sendNextDelGroupRelationsPage() " + "Invalid delete group change: SID = " + info.mServerContactId + ", gid=" + info.mGroupOrRelId);
        deleteInfoList.add(info);
    }
    mDb.deleteContactChanges(deleteInfoList);
    if (mActiveGroupId == null) {
        moveToNextState();
        return;
    }
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        complete(NetworkAgent.getServiceStatusfromDisconnectReason());
        return;
    }
    mNoOfItemsSent = mContactIdList.size();
    setReqId(GroupPrivacy.deleteContactGroupRelationsExt(getEngine(), mActiveGroupId, mContactIdList));
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList)

Example 80 with Request

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

the class IdentityEngine method handleGetAvailableIdentitiesResponse.

/**
 * Handle Server response to request for available Identities. The response
 * should be a list of Identity items. The request is completed with
 * ServiceStatus.SUCCESS or ERROR_UNEXPECTED_RESPONSE if the data-type
 * retrieved are not Identity items.
 *
 * @param data List of BaseDataTypes generated from Server response.
 */
private void handleGetAvailableIdentitiesResponse(List<BaseDataType> data) {
    LogUtils.logD("IdentityEngine: handleServerGetAvailableIdentitiesResponse");
    ServiceStatus errorStatus = getResponseStatus(BaseDataType.AVAILABLE_IDENTITY_DATA_TYPE, data);
    if (errorStatus == ServiceStatus.SUCCESS) {
        synchronized (mAvailableIdentityList) {
            mAvailableIdentityList.clear();
            for (BaseDataType item : data) {
                Identity identity = (Identity) item;
                if (!identity.isIdentityFieldBlankorNull()) {
                    mAvailableIdentityList.add(identity);
                }
            }
        }
    }
    pushIdentitiesToUi(ServiceUiRequest.GET_AVAILABLE_IDENTITIES);
    LogUtils.logD("IdentityEngine: handleGetAvailableIdentitiesResponse complete request.");
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) Identity(com.vodafone360.people.datatypes.Identity)

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