Search in sources :

Example 1 with QueueManager

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();
    }
}
Also used : ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) Request(com.vodafone360.people.service.io.Request)

Example 2 with QueueManager

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);
}
Also used : Request(com.vodafone360.people.service.io.Request) IOException(java.io.IOException) IOException(java.io.IOException) QueueManager(com.vodafone360.people.service.io.QueueManager) AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 3 with QueueManager

use of com.vodafone360.people.service.io.QueueManager in project 360-Engine-for-Android by 360.

the class Contacts method deleteContactDetails.

/**
 * Implementation of contacts/deletecontactdetails API. Parameters are;
 * [auth], Long contactid, List<ContactDetail> detaillist
 *
 * @param engine Handle to ContactSync engine
 * @param contactid
 * @param detaillist
 * @return request id generated for this request.
 */
public static int deleteContactDetails(BaseEngine engine, Long contactid, List<ContactDetail> detaillist) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Contacts.deleteContactDetails() Invalid session, return -1");
        return -1;
    }
    if (contactid == null) {
        LogUtils.logE("Contacts.deleteContactDetails() contactidlist cannot be NULL");
        return -1;
    }
    if (detaillist == null) {
        LogUtils.logE("Contacts.deleteContactDetails() detaillist cannot be NULL");
        return -1;
    }
    Request request = new Request(FUNCTION_DELETE_CONTACT_DETAILS, Request.Type.CONTACT_DETAIL_DELETE, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_CONTACTS);
    request.addData("contactid", contactid);
    request.addData("detaillist", ApiUtils.createVectorOfContactDetail(detaillist));
    QueueManager queue = QueueManager.getInstance();
    int requestId = queue.addRequest(request);
    queue.fireQueueStateChanged();
    return requestId;
}
Also used : Request(com.vodafone360.people.service.io.Request) QueueManager(com.vodafone360.people.service.io.QueueManager)

Example 4 with QueueManager

use of com.vodafone360.people.service.io.QueueManager in project 360-Engine-for-Android by 360.

the class Contacts method setMe.

/**
 * Implementation of contacts/setme API. Parameters are; [auth],
 * List<ContactDetail> detaillist, String aboutme [opt]
 *
 * @param engine Handle to ContactSync engine
 * @param detaillist List of ContactDetails for the Me profile.
 * @param aboutme AboutMe string.
 * @param gender - gender.
 * @return request id generated for this request.
 */
public static int setMe(BaseEngine engine, List<ContactDetail> detaillist, String aboutme, Integer gender) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Contacts.SetMe() Invalid session, return -1");
        return -1;
    }
    Request request = new Request(FUNCTION_SET_ME, Request.Type.CONTACT_CHANGES_OR_UPDATES, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_CONTACTS);
    if (aboutme != null) {
        request.addData("aboutme", aboutme);
    }
    if (detaillist != null) {
        request.addData("detaillist", ApiUtils.createVectorOfContactDetail(detaillist));
    }
    if (gender != null) {
        request.addData("gender", gender);
    }
    QueueManager queue = QueueManager.getInstance();
    int requestId = queue.addRequest(request);
    queue.fireQueueStateChanged();
    return requestId;
}
Also used : Request(com.vodafone360.people.service.io.Request) QueueManager(com.vodafone360.people.service.io.QueueManager)

Example 5 with QueueManager

use of com.vodafone360.people.service.io.QueueManager in project 360-Engine-for-Android by 360.

the class Contacts method deleteContacts.

/**
 * Implementation of contacts/deletecontacts API. Parameters are; [auth],
 * List<Long> contactidlist
 *
 * @param engine Handle to ContactSync engine
 * @param contactidlist List of contact ids to be deleted.
 * @return request id generated for this request.
 */
public static int deleteContacts(BaseEngine engine, List<Long> contactidlist) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Contacts.deleteContacts() Invalid session, return -1");
        return -1;
    }
    if (contactidlist == null) {
        LogUtils.logE("Contacts.deleteContacts() contactidlist cannot be NULL");
        return -1;
    }
    Request request = new Request(FUNCTION_DELETE_CONTACTS, Request.Type.CONTACT_DELETE, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_CONTACTS);
    request.addData("contactidlist", new Vector<Object>(contactidlist));
    QueueManager queue = QueueManager.getInstance();
    int requestId = queue.addRequest(request);
    queue.fireQueueStateChanged();
    return requestId;
}
Also used : Request(com.vodafone360.people.service.io.Request) QueueManager(com.vodafone360.people.service.io.QueueManager)

Aggregations

QueueManager (com.vodafone360.people.service.io.QueueManager)29 Request (com.vodafone360.people.service.io.Request)28 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)2 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)2 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)1 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)1 ServerError (com.vodafone360.people.datatypes.ServerError)1 EngineId (com.vodafone360.people.engine.EngineManager.EngineId)1 ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1