use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class ContactSyncEngineTest method testCancelSync.
/**
* Tests the sync is cancelled in case we remove user data.
*/
@Suppress
public // Breaks tests.
void testCancelSync() {
Log.i(LOG_TAG, "**** testNativeSync_newEngineInstantiation() begin ****");
final ArrayList<ProcessorLog> processorLogs = new ArrayList<ProcessorLog>();
final UiEventCall uiEventCall = new UiEventCall();
final ProcessorLog processorLog = new ProcessorLog();
final IEngineEventCallback engineEventCallback = new HelperClasses.EngineCallbackBase() {
@Override
public void onUiEvent(ServiceUiRequest event, int request, int status, Object data) {
Log.i(LOG_TAG, "onUiEvent: " + event + ", " + request + ", " + status + ", " + data);
uiEventCall.event = event.ordinal();
uiEventCall.request = request;
uiEventCall.status = status;
uiEventCall.data = data;
}
};
final ProcessorFactory factory = new ProcessorFactory() {
@Override
public BaseSyncProcessor create(int type, IContactSyncCallback callback, DatabaseHelper dbHelper) {
Log.i(LOG_TAG, "create(), type=" + type);
ProcessorLog log = new ProcessorLog();
log.type = type;
log.time = System.currentTimeMillis();
processorLogs.add(log);
return new BaseSyncProcessor(mContactSyncEngine, null) {
@Override
protected void doCancel() {
// cancel the job
processorLog.type = 1;
}
@Override
protected void doStart() {
// set a "timeout" to be called back immediately
setTimeout(0);
processorLog.type = 2;
}
@Override
public void onTimeoutEvent() {
// set the job as completed
Log.i(LOG_TAG, "onTimeoutEvent()");
complete(ServiceStatus.SUCCESS);
processorLog.type = 3;
}
@Override
public void processCommsResponse(DecodedResponse resp) {
// we don't need this case in this test
processorLog.type = 4;
}
};
}
};
minimalEngineSetup(engineEventCallback, factory);
// set the connection to be fine
NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
long nextRuntime = mContactSyncEngine.getNextRunTime();
// should be equal to -1 because first time sync has not been yet
// started
assertEquals(-1, nextRuntime);
// force a first time sync
mContactSyncEngine.addUiStartFullSync();
processorLog.type = 0;
// start performing the sync
mContactSyncEngine.run();
// the first processor should have started
assertTrue(processorLog.type == 2);
// this will cancel any sync
mContactSyncEngine.onReset();
// get the engine to perform a cancel on the current processor
mContactSyncEngine.run();
assertTrue(processorLog.type == 1);
// check that the engine cancelled the sync
assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
assertEquals(uiEventCall.status, ServiceStatus.USER_CANCELLED.ordinal());
}
use of com.vodafone360.people.service.io.Request 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.Request in project 360-Engine-for-Android by 360.
the class TimeOutWatcher method sendTimeoutEvent.
/**
* Sends a timeout event for all the expired requests.
*
* @param currentTime the current time until when a timeout event needs to
* be sent
*/
private void sendTimeoutEvent(long currentTime) {
LogUtils.logV("TimeOutWatcher.sendTimeoutEvent(" + currentTime + ")");
while (mRequests.size() > 0) {
final Request request = mRequests.get(0);
if (request.getExpiryDate() <= currentTime) {
LogUtils.logW("TimeOutWatcher.sendTimeoutEvent(): " + "Expired request found with reqId=[" + request.getRequestId() + "], type=[" + request.mType + "] and timeout=" + request.getTimeout() + " milliseconds");
fireRequestExpired(request);
// no need to remove the request, this happened during previous
// method call... (removeRequest is called when adding a
// response)
} else {
// of it
break;
}
}
}
use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class TimeOutWatcher method fireRequestExpired.
/**
* Creates a TimeOut event and adds it to the response queue. FIXME: this
* assumes that adding a request to the response queue will trigger a
* synchronous removeRequest() call with the same thread.
*
* @param request the request that has timed out
*/
private void fireRequestExpired(Request request) {
// create a list with a server error containing a timeout
final List<BaseDataType> data = new ArrayList<BaseDataType>(1);
final ServerError timeoutError = new ServerError(ServerError.ErrorType.REQUEST_TIMEOUT, request.getRequestId());
timeoutError.errorDescription = "TimeOutWatcher detected that the request id=[" + request.getRequestId() + "] has timed out.";
data.add(timeoutError);
// set the request as expired
request.expired = true;
// add the timeout error to the response queue
LogUtils.logW("TimeOutWatcher.fireRequestExpired(): " + "adding a timeout error to the response queue for reqId=[" + request.getRequestId() + "]");
QueueManager.getInstance().addResponse(new DecodedResponse(request.getRequestId(), data, request.mEngineId, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
}
use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class UserDataProtection method processUserChanges.
/**
* Requests to log out from 360 if the user has changed.
*/
public void processUserChanges() {
LogUtils.logD("UserDataProtection.checkUserChanges()");
final LoginEngine loginEngine = EngineManager.getInstance().getLoginEngine();
if (hasUserChanged()) {
if (loginEngine.isLoggedIn()) {
// User has changed, log out
LogUtils.logD("UserDataProtection.checkUserChanges() - User has changed! Request logout.");
loginEngine.addUiRemoveUserDataRequest();
} else {
LoginPreferences.clearPreferencesFile(mContext);
}
}
}
Aggregations