Search in sources :

Example 31 with Ingestion

use of com.microsoft.appcenter.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.

the class DefaultChannel method suspend.

/**
 * Stop sending logs until app is restarted or the channel is enabled again.
 *
 * @param deleteLogs in addition to suspending, if this is true, delete all logs from Persistence.
 * @param exception  the exception that caused suspension.
 */
private void suspend(boolean deleteLogs, Exception exception) {
    mDiscardLogs = deleteLogs;
    mCurrentState++;
    for (GroupState groupState : mGroupStates.values()) {
        cancelTimer(groupState);
        /* Delete all other batches and call callback method that are currently in progress. */
        for (Iterator<Map.Entry<String, List<Log>>> iterator = groupState.mSendingBatches.entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry<String, List<Log>> entry = iterator.next();
            iterator.remove();
            if (deleteLogs) {
                GroupListener groupListener = groupState.mListener;
                if (groupListener != null) {
                    for (Log log : entry.getValue()) {
                        groupListener.onFailure(log, exception);
                    }
                }
            }
        }
    }
    for (Ingestion ingestion : mIngestions) {
        try {
            ingestion.close();
        } catch (IOException e) {
            AppCenterLog.error(LOG_TAG, "Failed to close ingestion: " + ingestion, e);
        }
    }
    if (deleteLogs) {
        for (GroupState groupState : mGroupStates.values()) {
            deleteLogsOnSuspended(groupState);
        }
    } else {
        mPersistence.clearPendingLogState();
    }
}
Also used : AppCenterLog(com.microsoft.appcenter.utils.AppCenterLog) Log(com.microsoft.appcenter.ingestion.models.Log) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Ingestion(com.microsoft.appcenter.ingestion.Ingestion) AppCenterIngestion(com.microsoft.appcenter.ingestion.AppCenterIngestion)

Aggregations

Ingestion (com.microsoft.appcenter.ingestion.Ingestion)31 Context (android.content.Context)29 Persistence (com.microsoft.appcenter.persistence.Persistence)29 Test (org.junit.Test)29 ServiceCallback (com.microsoft.appcenter.http.ServiceCallback)24 LogContainer (com.microsoft.appcenter.ingestion.models.LogContainer)24 UUID (java.util.UUID)24 Log (com.microsoft.appcenter.ingestion.models.Log)20 Matchers.anyString (org.mockito.Matchers.anyString)19 AppCenterIngestion (com.microsoft.appcenter.ingestion.AppCenterIngestion)14 IOException (java.io.IOException)13 SocketException (java.net.SocketException)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 HttpException (com.microsoft.appcenter.http.HttpException)4 Answer (org.mockito.stubbing.Answer)4 CancellationException (com.microsoft.appcenter.CancellationException)3 ArrayList (java.util.ArrayList)3 HttpResponse (com.microsoft.appcenter.http.HttpResponse)2 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)1 HashMap (java.util.HashMap)1