use of com.vodafone360.people.service.io.QueueManager in project 360-Engine-for-Android by 360.
the class Identities method setIdentityStatus.
/**
* @param engine
* @param network
* @param identityid
* @param identityStatus
* @return
*/
public static int setIdentityStatus(BaseEngine engine, String network, String identityid, String identityStatus) {
if (LoginEngine.getSession() == null) {
LogUtils.logE("Identities.setIdentityStatus() Invalid session, return -1");
return -1;
}
if (identityid == null) {
LogUtils.logE("Identities.setIdentityStatus() identityid cannot be NULL");
return -1;
}
if (network == null) {
LogUtils.logE("Identities.setIdentityStatus() network cannot be NULL");
return -1;
}
if (identityStatus == null) {
LogUtils.logE("Identities.setIdentityStatus() identity status cannot be NULL");
return -1;
}
Request request = new Request(FUNCTION_SET_IDENTITY_STATUS, Request.Type.EXPECTING_STATUS_ONLY, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_IDENTITIES);
request.addData("network", network);
request.addData("identityid", identityid);
request.addData("status", identityStatus);
QueueManager queue = QueueManager.getInstance();
int requestId = queue.addRequest(request);
queue.fireQueueStateChanged();
return requestId;
}
use of com.vodafone360.people.service.io.QueueManager in project 360-Engine-for-Android by 360.
the class TcpConnectionThread method run.
public void run() {
QueueManager queueManager = QueueManager.getInstance();
setFailedRetrying(false);
setIsRetrying(false);
try {
// start the initial connection
reconnectSocket();
HeartbeatSenderThread hbSender = new HeartbeatSenderThread(this, mService, mSocket);
hbSender.setOutputStream(mOs);
hbSender.sendHeartbeat();
hbSender = null;
// TODO run this when BE supports it but keep HB in front!
/*
* ConnectionTester connTester = new ConnectionTester(mIs, mOs); if
* (connTester.runTest()) { } else {}
*/
startHelperThreads();
ConnectionManager.getInstance().onConnectionStateChanged(ITcpConnectionListener.STATE_CONNECTED);
} catch (IOException e) {
haltAndRetryConnection(FIRST_ATTEMPT);
} catch (Exception e) {
haltAndRetryConnection(FIRST_ATTEMPT);
}
while (mConnectionShouldBeRunning) {
try {
if ((null != mOs) && (!getFailedRetrying())) {
List<Request> reqs = QueueManager.getInstance().getRpgRequests();
int reqNum = reqs.size();
List<Integer> reqIdList = null;
if (Settings.sEnableProtocolTrace || Settings.sEnableSuperExpensiveResponseFileLogging) {
reqIdList = new ArrayList<Integer>();
}
if (reqNum > 0) {
mBaos.reset();
// batch payloads
for (int i = 0; i < reqNum; i++) {
Request req = reqs.get(i);
if ((null == req) || (req.getAuthenticationType() == Request.USE_API)) {
HttpConnectionThread.logV("TcpConnectionThread.run()", "Ignoring non-RPG method");
continue;
}
HttpConnectionThread.logD("TcpConnectionThread.run()", "Preparing [" + req.getRequestId() + "] for sending via RPG...");
req.setActive(true);
req.writeToOutputStream(mBaos, true);
// so we should not remove it from the queue otherwise there will be no timeout triggered.
if (req.isFireAndForget() && (req.mType != Request.Type.AVAILABILITY)) {
// f-a-f, no response,
// remove from queue
HttpConnectionThread.logD("TcpConnectionThread.run()", "Removed F&F-Request: " + req.getRequestId());
queueManager.removeRequest(req.getRequestId());
}
if (Settings.sEnableProtocolTrace) {
reqIdList.add(req.getRequestId());
HttpConnectionThread.logD("HttpConnectionThread.run()", "Req ID: " + req.getRequestId() + " <-> Auth: " + req.getAuth());
}
}
mBaos.flush();
byte[] payload = mBaos.toByteArray();
if (null != payload) {
// log file containing response to SD card
if (Settings.sEnableSuperExpensiveResponseFileLogging) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < reqIdList.size(); i++) {
sb.append(reqIdList.get(i));
sb.append("_");
}
LogUtils.logE("XXXXXXYYYXXXXXX Do not Remove this!");
LogUtils.logToFile(payload, "people_" + (reqIdList.size() > 0 ? reqIdList.get(0) : 0) + "_" + System.currentTimeMillis() + "_req_" + // message
((int) payload[2]) + // type
".txt");
}
if (Settings.sEnableProtocolTrace) {
Long userID = null;
AuthSessionHolder auth = LoginEngine.getSession();
if (auth != null) {
userID = auth.userID;
}
HttpConnectionThread.logI("TcpConnectionThread.run()", "\n > Sending request(s) " + reqIdList.toString() + ", for user ID " + userID + " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + HessianUtils.getInHessian(new ByteArrayInputStream(payload), true) + "\n ");
}
try {
synchronized (mOs) {
mOs.write(payload);
mOs.flush();
}
} catch (IOException ioe) {
HttpConnectionThread.logE("TcpConnectionThread.run()", "Could not send request", ioe);
notifyOfNetworkProblems();
}
payload = null;
}
}
}
if (!getFailedRetrying()) {
synchronized (requestLock) {
requestLock.wait();
}
} else {
while (getFailedRetrying()) {
// loop until a retry
// succeeds
HttpConnectionThread.logI("TcpConnectionThread.run()", "Wait() for next connection retry has started.");
synchronized (errorLock) {
errorLock.wait(Settings.TCP_RETRY_BROKEN_CONNECTION_INTERVAL);
}
if (mConnectionShouldBeRunning) {
haltAndRetryConnection(FIRST_ATTEMPT);
}
}
}
} catch (Throwable t) {
HttpConnectionThread.logE("TcpConnectionThread.run()", "Unknown Error: ", t);
}
}
stopConnection();
ConnectionManager.getInstance().onConnectionStateChanged(ITcpConnectionListener.STATE_DISCONNECTED);
}
use of com.vodafone360.people.service.io.QueueManager 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.QueueManager in project 360-Engine-for-Android by 360.
the class EngineTestFramework method reportBackToFramework.
@Override
public void reportBackToFramework(int reqId, EngineId engine) {
Log.d("TAG", "EngineTestFramework.reportBackToFramework");
mObserver.reportBackToEngine(reqId, engine);
final QueueManager reqQ = QueueManager.getInstance();
final ResponseQueue respQ = ResponseQueue.getInstance();
if (reqQ.getRequest(reqId) != null) {
List<BaseDataType> dataTypeList = new ArrayList<BaseDataType>();
ServerError err = new ServerError(ServerError.ErrorType.UNKNOWN);
dataTypeList.add(err);
respQ.addToResponseQueue(new DecodedResponse(reqId, dataTypeList, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
}
}
use of com.vodafone360.people.service.io.QueueManager in project 360-Engine-for-Android by 360.
the class Auth method requestActivationCode.
/**
* Implementation of "auth/requestactivationcode" API.
*
* @param engine Handle to LoginEngine which handles requests using this
* API.
* @param username User-name for this account.
* @param mobileNumber Mobile number for this activation code to be sent.
* @return Request ID generated for this request.
* @return -1 when username is NULL.
* @throws NullPointerException when engine is NULL
* @throws NullPointerException when mobileNumber is NULL
*/
public static int requestActivationCode(BaseEngine engine, String username, String mobileNumber) {
if (engine == null) {
throw new NullPointerException("Auth.requestActivationCode() engine cannot be NULL");
}
if (username == null) {
LogUtils.logE("Auth.requestActivationCode() username must be specified");
return -1;
}
if (mobileNumber == null) {
throw new NullPointerException("Auth.requestActivationCode() mobileNumber cannot be NULL");
}
Request request = new Request(FUNCTION_REQUEST_ACTIVATION_CODE, Request.Type.STATUS, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_AUTH);
request.addData(USERNAME, username);
request.addData(VALUE, mobileNumber);
request.addData(FLAGS, ACTIVATE_MOBILE_CLIENT_FLAG);
QueueManager queue = QueueManager.getInstance();
int requestId = queue.addRequest(request);
queue.fireQueueStateChanged();
return requestId;
}
Aggregations