android/sdk/src/main/java/io/o2mc/sdk/business/batch/BatchManager.java
@Override
  public void run() {
    if (isStopped) return;

    if (isFirstRun) {
      // Initialize batchGenerator meta data
      batchBus.setDeviceInformation(trackingManager.getDeviceInformation());
      isFirstRun = false;
    }

    // Don't try resending a batch if the max retries limit has exceeded
    if (batchBus.getRetries() > maxRetries) {
      LogW(TAG, "run: Max retries limit has been reached. Not trying to resend batch.");
      isStopped = true;
      return;
    }

    // Only generate a batch if we have events
    if (getEvents().size() > 0) {
      batchBus.add(batchBus.generateBatch(batchId, getEvents()));
      LogD(TAG,
          String.format("run: Newly generated batch contains '%s' events", getEvents().size()));
      clearEvents();
    }

    // If there's a batch pending, skip this run
    if (batchBus.awaitingCallback()) {
      LogD(TAG, "run: Still awaiting a callback from previous run. Stopping here.");
      return;
    }

    // There's no pending batch, set / generate one if possible
    if (batchBus.getPendingBatch() == null) {
      batchBus.setPendingBatch();
    }

    // If there is one now, send it
    if (batchBus.getPendingBatch() == null) {
      LogI(TAG, "run: There is no pending batch set. Not dispatching.");
      return;
    }

    // Dispatch the newly set batch
    LogI(TAG, String.format("run: Dispatching batch with '%s' events.",
        batchBus.getPendingBatch().getEvents().size()));
    batchBus.preDispatch();

    batchDispatcher.post(endpoint, batchBus.getPendingBatch());
  }
/**
   * Batch preparation and queuing logic.
   */
Batch preparation and queuing logic.
Batch preparation and queuing logic .
@Override
  public void run() {
    if (isStopped) return;
    if (isFirstRun) {
      batchBus.setDeviceInformation(trackingManager.getDeviceInformation());
      isFirstRun = false;
    }
    if (batchBus.getRetries() > maxRetries) {
      LogW(TAG, "run: Max retries limit has been reached. Not trying to resend batch.");
      isStopped = true;
      return;
    }
    if (getEvents().size() > 0) {
      batchBus.add(batchBus.generateBatch(batchId, getEvents()));
      LogD(TAG,
          String.format("run: Newly generated batch contains '%s' events", getEvents().size()));
      clearEvents();
    }
    if (batchBus.awaitingCallback()) {
      LogD(TAG, "run: Still awaiting a callback from previous run. Stopping here.");
      return;
    }
    if (batchBus.getPendingBatch() == null) {
      batchBus.setPendingBatch();
    }
    if (batchBus.getPendingBatch() == null) {
      LogI(TAG, "run: There is no pending batch set. Not dispatching.");
      return;
    }
    LogI(TAG, String.format("run: Dispatching batch with '%s' events.",
        batchBus.getPendingBatch().getEvents().size()));
    batchBus.preDispatch();
    batchDispatcher.post(endpoint, batchBus.getPendingBatch());
  }
@ Override public void run ( ) { if ( isStopped ) return ; if ( isFirstRun ) { batchBus . setDeviceInformation ( trackingManager . getDeviceInformation ( ) ) ; isFirstRun = false ; } if ( batchBus . getRetries ( ) > maxRetries ) { LogW ( TAG , "run: Max retries limit has been reached. Not trying to resend batch." ) ; isStopped = true ; return ; } if ( getEvents ( ) . size ( ) > 0 ) { batchBus . add ( batchBus . generateBatch ( batchId , getEvents ( ) ) ) ; LogD ( TAG , String . format ( "run: Newly generated batch contains '%s' events" , getEvents ( ) . size ( ) ) ) ; clearEvents ( ) ; } if ( batchBus . awaitingCallback ( ) ) { LogD ( TAG , "run: Still awaiting a callback from previous run. Stopping here." ) ; return ; } if ( batchBus . getPendingBatch ( ) == null ) { batchBus . setPendingBatch ( ) ; } if ( batchBus . getPendingBatch ( ) == null ) { LogI ( TAG , "run: There is no pending batch set. Not dispatching." ) ; return ; } LogI ( TAG , String . format ( "run: Dispatching batch with '%s' events." , batchBus . getPendingBatch ( ) . getEvents ( ) . size ( ) ) ) ; batchBus . preDispatch ( ) ; batchDispatcher . post ( endpoint , batchBus . getPendingBatch ( ) ) ; }
Batch preparation and queuing logic.
Batch preparation and queuing logic .
// Initialize batchGenerator meta data // Don't try resending a batch if the max retries limit has exceeded // Only generate a batch if we have events // If there's a batch pending, skip this run // There's no pending batch, set / generate one if possible // If there is one now, send it // Dispatch the newly set batch