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));
}
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);
}
}
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();
}
}
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);
}
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()));
}
}
}
}
}
Aggregations