use of com.vodafone360.people.engine.EngineManager.EngineId in project 360-Engine-for-Android by 360.
the class HessianDecoder method decodeResponse.
/**
*
*
*
* @param is
* @param requestId
* @param type
* @param isZipped
* @param engineId
*
* @return
*
* @throws IOException
*/
@SuppressWarnings("unchecked")
private DecodedResponse decodeResponse(InputStream is, int requestId, Request.Type type, boolean isZipped, EngineId engineId) throws IOException {
boolean usesReplyTag = false;
int responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
List<BaseDataType> resultList = new ArrayList<BaseDataType>();
mMicroHessianInput.init(is);
// skip start
// initial map tag or fail
int tag = is.read();
if (tag == 'r') {
// reply / response
// read major and minor
is.read();
is.read();
// read next tag
tag = is.read();
usesReplyTag = true;
}
if (tag == -1) {
return null;
}
// read reason string and throw exception
if (tag == 'f') {
ServerError zybErr = new ServerError(mMicroHessianInput.readFault().errString());
resultList.add(zybErr);
DecodedResponse decodedResponse = new DecodedResponse(requestId, resultList, engineId, DecodedResponse.ResponseType.SERVER_ERROR.ordinal());
return decodedResponse;
}
// this is not wrapped up in a hashtable
if (type == Request.Type.EXTERNAL_RPG_RESPONSE) {
LogUtils.logV("HessianDecoder.decodeResponse() EXTERNAL_RPG_RESPONSE");
if (tag != 'I') {
LogUtils.logE("HessianDecoder.decodeResponse() " + "tag!='I' Unexpected Hessian type:" + tag);
}
parseExternalResponse(resultList, is, tag);
DecodedResponse decodedResponse = new DecodedResponse(requestId, resultList, engineId, DecodedResponse.ResponseType.SERVER_ERROR.ordinal());
return decodedResponse;
}
// internal response: should contain a Map type - i.e. Hashtable
if (tag != 'M') {
LogUtils.logE("HessianDecoder.decodeResponse() tag!='M' Unexpected Hessian type:" + tag);
throw new IOException("Unexpected Hessian type");
} else if (// if we have a common request or sign in request
(type == Request.Type.COMMON) || (type == Request.Type.SIGN_IN) || (type == Request.Type.GET_MY_IDENTITIES) || (type == Request.Type.GET_AVAILABLE_IDENTITIES)) {
Hashtable<String, Object> map = (Hashtable<String, Object>) mMicroHessianInput.readHashMap(tag);
if (null == map) {
return null;
}
if (map.containsKey(KEY_SESSION)) {
AuthSessionHolder auth = new AuthSessionHolder();
Hashtable<String, Object> authHash = (Hashtable<String, Object>) map.get(KEY_SESSION);
resultList.add(auth.createFromHashtable(authHash));
responseType = DecodedResponse.ResponseType.LOGIN_RESPONSE.ordinal();
} else if (map.containsKey(KEY_CONTACT_LIST)) {
// contact list
getContacts(resultList, ((Vector<?>) map.get(KEY_CONTACT_LIST)));
responseType = DecodedResponse.ResponseType.GET_CONTACTCHANGES_RESPONSE.ordinal();
} else if (map.containsKey(KEY_USER_PROFILE_LIST)) {
Vector<Hashtable<String, Object>> upVect = (Vector<Hashtable<String, Object>>) map.get(KEY_USER_PROFILE_LIST);
for (Hashtable<String, Object> obj : upVect) {
resultList.add(UserProfile.createFromHashtable(obj));
}
responseType = DecodedResponse.ResponseType.GETME_RESPONSE.ordinal();
} else if (map.containsKey(KEY_USER_PROFILE)) {
Hashtable<String, Object> userProfileHash = (Hashtable<String, Object>) map.get(KEY_USER_PROFILE);
resultList.add(UserProfile.createFromHashtable(userProfileHash));
responseType = DecodedResponse.ResponseType.GETME_RESPONSE.ordinal();
} else if (// we have identity items in the map which we can parse
(map.containsKey(KEY_IDENTITY_LIST)) || (map.containsKey(KEY_AVAILABLE_IDENTITY_LIST))) {
int identityType = 0;
Vector<Hashtable<String, Object>> idcap = null;
if (map.containsKey(KEY_IDENTITY_LIST)) {
idcap = (Vector<Hashtable<String, Object>>) map.get(KEY_IDENTITY_LIST);
identityType = BaseDataType.MY_IDENTITY_DATA_TYPE;
responseType = DecodedResponse.ResponseType.GET_MY_IDENTITIES_RESPONSE.ordinal();
} else {
idcap = (Vector<Hashtable<String, Object>>) map.get(KEY_AVAILABLE_IDENTITY_LIST);
identityType = BaseDataType.AVAILABLE_IDENTITY_DATA_TYPE;
responseType = DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal();
}
for (Hashtable<String, Object> obj : idcap) {
Identity id = new Identity(identityType);
resultList.add(id.createFromHashtable(obj));
}
} else if (type == Request.Type.GET_AVAILABLE_IDENTITIES) {
// we have an available identities response, but it is empty
responseType = DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal();
} else if (type == Request.Type.GET_MY_IDENTITIES) {
// we have a my identities response, but it is empty
responseType = DecodedResponse.ResponseType.GET_MY_IDENTITIES_RESPONSE.ordinal();
} else if (map.containsKey(KEY_ACTIVITY_LIST)) {
Vector<Hashtable<String, Object>> activityList = (Vector<Hashtable<String, Object>>) map.get(KEY_ACTIVITY_LIST);
for (Hashtable<String, Object> obj : activityList) {
resultList.add(ActivityItem.createFromHashtable(obj));
}
responseType = DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal();
}
} else if ((type != Request.Type.COMMON) && (type != Request.Type.SIGN_IN)) {
// get initial hash table
// TODO: we cast every response to a Map, losing e.g. push event
// "c0" which only contains a string - to fix
Hashtable<String, Object> hash = (Hashtable<String, Object>) mMicroHessianInput.decodeType(tag);
responseType = decodeResponseByRequestType(resultList, hash, type);
}
if (usesReplyTag) {
// read the last 'z'
is.read();
}
DecodedResponse decodedResponse = new DecodedResponse(requestId, resultList, engineId, responseType);
return decodedResponse;
}
use of com.vodafone360.people.engine.EngineManager.EngineId in project 360-Engine-for-Android by 360.
the class HessianDecoder method parsePushPayload.
private void parsePushPayload(RpgPushMessage msg, List<BaseDataType> list) {
// convert push msg type string to PushMsgType
PushMessageTypes type = msg.mType;
EngineId engineId = EngineId.UNDEFINED;
if (type != null) {
switch(type) {
case CHAT_MESSAGE:
LogUtils.logV("Parse incomming chat_message");
engineId = EngineId.PRESENCE_ENGINE;
list.add(new PushChatMessageEvent(msg, engineId));
return;
case AVAILABILITY_STATE_CHANGE:
LogUtils.logV("Parse availability state change:");
engineId = EngineId.PRESENCE_ENGINE;
list.add(PushAvailabilityEvent.createPushEvent(msg, engineId));
return;
case START_CONVERSATION:
LogUtils.logV("Parse new conversation event:");
engineId = EngineId.PRESENCE_ENGINE;
list.add(new PushChatConversationEvent(msg, engineId));
return;
case CLOSED_CONVERSATION:
LogUtils.logV("Parse closed conversation event:");
engineId = EngineId.PRESENCE_ENGINE;
list.add(new PushClosedConversationEvent(msg, engineId));
return;
case CONVERSATION_END:
break;
// API events create push message type
case PROFILE_CHANGE:
engineId = EngineId.SYNCME_ENGINE;
break;
case CONTACTS_CHANGE:
engineId = EngineId.CONTACT_SYNC_ENGINE;
break;
case TIMELINE_ACTIVITY_CHANGE:
case STATUS_ACTIVITY_CHANGE:
engineId = EngineId.ACTIVITIES_ENGINE;
break;
case FRIENDSHIP_REQUEST_RECEIVED:
break;
case IDENTITY_CHANGE:
engineId = EngineId.IDENTITIES_ENGINE;
break;
case IDENTITY_NETWORK_CHANGE:
engineId = EngineId.IDENTITIES_ENGINE;
break;
case SYSTEM_NOTIFICATION:
LogUtils.logE("SYSTEM_NOTIFICATION push msg:" + msg.mHash);
list.add(SystemNotification.createFromHashtable(msg.mHash, engineId));
return;
default:
}
list.add(PushEvent.createPushEvent(msg, 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));
}
}
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();
}
}
use of com.vodafone360.people.engine.EngineManager.EngineId in project 360-Engine-for-Android by 360.
the class UploadServerContactsTest method reportBackToEngine.
@Override
public void reportBackToEngine(int reqId, EngineId engine) {
Log.d(LOG_TAG, "reportBackToEngine");
ResponseQueue respQueue = ResponseQueue.getInstance();
List<BaseDataType> data = new ArrayList<BaseDataType>();
try {
assertEquals(mEng.engineId(), engine);
synchronized (mEng.mWaitForReqIdLock) {
if (mEng.mActiveReqId == null || mEng.mActiveReqId.intValue() != reqId) {
try {
mEng.mWaitForReqIdLock.wait(MAX_WAIT_FOR_REQ_ID);
} catch (InterruptedException e) {
}
assertEquals(Integer.valueOf(reqId), mEng.mActiveReqId);
}
}
switch(mState) {
case ADD_CONTACT_LIST:
reportBackAddContactSuccess(reqId, data);
break;
case MODIFY_CONTACT_LIST:
reportModifyContactSuccess(reqId, data);
break;
case DELETE_CONTACT_LIST:
reportDeleteContactSuccess(reqId, data);
break;
case DELETE_CONTACT_DETAIL_LIST:
reportDeleteContactDetailSuccess(reqId, data);
break;
case ADD_NEW_GROUP_LIST:
reportBackAddGroupSuccess(reqId, data);
break;
case DELETE_GROUP_LIST:
reportDeleteGroupListSuccess(reqId, data);
break;
default:
fail("Unexpected request from processor");
}
} catch (Throwable err) {
ServerError serverError = new ServerError(ServerError.ErrorType.INTERNALERROR);
serverError.errorDescription = err + "\n";
for (int i = 0; i < err.getStackTrace().length; i++) {
StackTraceElement v = err.getStackTrace()[i];
serverError.errorDescription += "\t" + v + "\n";
}
Log.e(LOG_TAG, "Exception:\n" + serverError.errorDescription);
data.clear();
data.add(serverError);
}
respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
mEng.onCommsInMessage();
Log.d(LOG_TAG, "reportBackToEngine - message added to response queue");
}
Aggregations