use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.
the class RequestQueue method clearAllRequests.
/**
* Clears all requests from the queue and puts null responses on the
* response queue to tell the engines that they have been cleared. This
* should be called from the connection thread as soon as it is stopped.
*/
protected void clearAllRequests() {
synchronized (QueueManager.getInstance().lock) {
ResponseQueue responseQueue = ResponseQueue.getInstance();
for (int i = 0; i < mRequests.size(); i++) {
Request request = mRequests.get(i);
LogUtils.logE("RequestQueue.clearActiveRequests() Deleting request " + request.getRequestId());
mRequests.remove(i--);
// necessarily times out before)
if (request.getExpiryDate() > 0) {
mTimeOutWatcher.removeRequest(request);
}
responseQueue.addToResponseQueue(new DecodedResponse(request.getRequestId(), null, request.mEngineId, DecodedResponse.ResponseType.TIMED_OUT_RESPONSE.ordinal()));
}
}
}
use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.
the class SyncMeEngine method processGetMyChangesResponse.
/**
* Processes the response from a GetMyChanges request. The me profile data
* will be merged in the local database if the response is successful.
* Otherwise the processor will complete with a suitable error.
* @param resp Response from server.
*/
private void processGetMyChangesResponse(final DecodedResponse resp) {
LogUtils.logD("SyncMeEngine processGetMyChangesResponse()");
ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
if (status == ServiceStatus.SUCCESS) {
ContactChanges changes = (ContactChanges) resp.mDataTypes.get(0);
Contact currentMeProfile = new Contact();
status = SyncMeDbUtils.fetchMeProfile(mDbHelper, currentMeProfile);
switch(status) {
case SUCCESS:
SyncMeDbUtils.updateMeProfile(mDbHelper, currentMeProfile, changes.mUserProfile);
break;
case // this is the 1st time sync
ERROR_NOT_FOUND:
currentMeProfile.copy(changes.mUserProfile);
status = SyncMeDbUtils.setMeProfile(mDbHelper, currentMeProfile);
setFirstTimeMeSyncComplete(true);
break;
default:
completeUiRequest(status);
return;
}
final String url = fetchThumbnailUrlFromProfile(changes.mUserProfile);
if (url != null) {
downloadMeProfileThumbnail(url, currentMeProfile.localContactID);
} else {
completeUiRequest(status);
}
storeMeProfileRevisionInDb(changes.mCurrentServerVersion);
} else {
completeUiRequest(status);
}
}
use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.
the class HttpConnectionThread method addErrorToResponseQueue.
/**
* Adds errors to the response queue whenever there is an HTTP error on the
* backend.
*
* @param reqIds The request IDs the error happened for.
*/
public void addErrorToResponseQueue(List<Integer> reqIds) {
EngineId source = null;
QueueManager requestQueue = QueueManager.getInstance();
ResponseQueue responseQueue = ResponseQueue.getInstance();
for (Integer reqId : reqIds) {
// attempt to get type from request
Request req = requestQueue.getRequest(reqId);
if (req != null)
source = req.mEngineId;
responseQueue.addToResponseQueue(new DecodedResponse(reqId, null, source, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
}
}
use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse 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;
}
use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.
the class DownloadServerContacts method processCommsResponse.
/**
* Called by framework when a response is received from the server. In case
* of the first page this will only be called if the request ID matches.
* Processes the page and if the page is the last one in the batch, sends a
* new batch of requests to the server.
*
* @param response from server
*/
@Override
public void processCommsResponse(DecodedResponse resp) {
Integer pageNo = 0;
if (mInternalState == InternalState.FETCHING_NEXT_BATCH) {
pageNo = mPageReqIds.remove(resp.mReqId);
if (pageNo == null) {
LogUtils.logD("DownloadServerContacts.processCommsResponse: Req ID not known");
return;
}
}
LogUtils.logD("DownloadServerContacts.processCommsResponse() - Page " + pageNo);
ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
if (status == ServiceStatus.SUCCESS) {
ContactChanges contactChanges = (ContactChanges) resp.mDataTypes.get(0);
LogUtils.logI("DownloadServerContacts.processCommsResponse - No of contacts = " + contactChanges.mContacts.size());
if (contactChanges.mContacts.size() == 0 && pageNo > 0) {
LogUtils.logW("DownloadServerContacts.processCommsResponse - " + "Error a page with 0 contacts was received");
LogUtils.logW("DownloadServerContacts.processCommsResponse - Changes = " + contactChanges);
}
mBatchPageReceivedCount++;
if (mBatchPageReceivedCount == mBatchNoOfPages) {
mLastPageSize = contactChanges.mContacts.size();
// Page batch is now complete
if (mInternalState == InternalState.FETCHING_FIRST_PAGE) {
mTotalNoOfPages = contactChanges.mNumberOfPages;
mToRevision = contactChanges.mVersionAnchor;
mInternalState = InternalState.FETCHING_NEXT_BATCH;
}
mBatchFirstPageNo += mBatchNoOfPages;
if (mTotalNoOfPages == null || mToRevision == null) {
complete(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
return;
}
if (mBatchFirstPageNo < mTotalNoOfPages.intValue()) {
status = fetchNextBatch();
if (ServiceStatus.SUCCESS != status) {
complete(status);
return;
}
} else {
mIsComplete = true;
}
}
status = syncContactChangesPage(contactChanges);
mNoOfPagesDone++;
LogUtils.logI("DownloadServerContacts.processCommsResponse() - Contact changes page " + mNoOfPagesDone + "/" + mTotalNoOfPages + " received, no of contacts = " + contactChanges.mContacts.size());
if (ServiceStatus.SUCCESS != status) {
LogUtils.logE("DownloadServerContacts.processCommsResponse() - Error syncing page: " + status);
complete(status);
return;
}
if (mIsComplete && mContactsChangedList.size() == 0 && !mSyncDataPending) {
downloadSyncSuccessful();
}
return;
}
complete(status);
}
Aggregations