Class RelayDequeue

java.lang.Object
com.mimecast.robin.queue.RelayDequeue

public class RelayDequeue extends Object
RelayDequeue handles the dequeuing and processing of relay sessions from the persistent queue.

This class is responsible for:

  • Dequeuing relay sessions based on budget constraints
  • Checking retry timing and re-enqueueing sessions that are not ready
  • Attempting email delivery via appropriate protocol (SMTP or Dovecot LDA)
  • Processing delivery results and managing partial failures
  • Handling retry logic with exponential backoff
  • Generating bounce messages when max retries are exceeded
  • Field Details

  • Constructor Details

    • RelayDequeue

      public RelayDequeue(PersistentQueue<RelaySession> queue)
      Constructs a RelayDequeue processor with the specified queue.
      Parameters:
      queue - the persistent queue to dequeue relay sessions from
  • Method Details

    • processBatch

      public void processBatch(int maxDequeuePerTick, long currentEpochSeconds)
      Processes a batch of relay sessions from the queue.

      This method will attempt to dequeue and process up to maxDequeuePerTick sessions. Sessions that are not yet ready for retry will be re-enqueued.

      Parameters:
      maxDequeuePerTick - the maximum number of sessions to process in this execution
      currentEpochSeconds - the current time in epoch seconds
    • processSession

      void processSession(RelaySession relaySession, long currentEpochSeconds)
      Processes a single relay session.

      Checks if the session is ready for retry based on timing, attempts delivery, handles results, and manages re-enqueueing or bounce generation.

      Parameters:
      relaySession - the relay session to process
      currentEpochSeconds - the current time in epoch seconds
    • isReadyForRetry

      boolean isReadyForRetry(RelaySession relaySession, long currentEpochSeconds)
      Checks if a relay session is ready for retry based on its retry count and last retry time.
      Parameters:
      relaySession - the relay session to check
      currentEpochSeconds - the current time in epoch seconds
      Returns:
      true if the session is ready for retry, false otherwise
    • logSessionInfo

      private void logSessionInfo(RelaySession relaySession)
      Logs information about the session being processed.
      Parameters:
      relaySession - the relay session
    • countRecipients

      int countRecipients(RelaySession relaySession)
      Counts the total number of recipients across all envelopes in the session.
      Parameters:
      relaySession - the relay session
      Returns:
      the total number of recipients
    • attemptDelivery

      void attemptDelivery(RelaySession relaySession)
      Attempts delivery of the relay session using the appropriate protocol.
      Parameters:
      relaySession - the relay session to deliver
    • processDeliveryResults

      RelayDeliveryResult processDeliveryResults(RelaySession relaySession)
      Processes the delivery results, removing successful envelopes and updating failed ones.
      Parameters:
      relaySession - the relay session with delivery results
      Returns:
      a RelayDeliveryResult containing counts and successful envelopes
    • cleanupSuccessfulEnvelopes

      void cleanupSuccessfulEnvelopes(List<MessageEnvelope> successfulEnvelopes)
      Deletes the files associated with successful envelopes.
      Parameters:
      successfulEnvelopes - the list of successfully delivered envelopes
    • handleRemainingEnvelopes

      void handleRemainingEnvelopes(RelaySession relaySession, RelayDeliveryResult result)
      Handles remaining envelopes that were not successfully delivered.

      If under max retries, re-enqueues the session. Otherwise, generates bounce messages.

      Parameters:
      relaySession - the relay session
      result - the delivery result
    • retrySession

      void retrySession(RelaySession relaySession)
      Increments the retry count and re-enqueues the session for another attempt.
      Parameters:
      relaySession - the relay session to retry
    • reEnqueueSession

      void reEnqueueSession(RelaySession relaySession, String reason)
      Re-enqueues a session back to the queue after persisting its files.
      Parameters:
      relaySession - the relay session to re-enqueue
      reason - the reason for re-enqueueing (for logging)
    • generateBounces

      void generateBounces(RelaySession relaySession)
      Generates bounce messages for all recipients in the remaining envelopes.

      Called when max retry count has been exceeded.

      Parameters:
      relaySession - the relay session that has exceeded max retries
    • createAndEnqueueBounce

      void createAndEnqueueBounce(RelaySession originalSession, String recipient)
      Creates a bounce message for a failed recipient and enqueues it for delivery.
      Parameters:
      originalSession - the original relay session that failed
      recipient - the recipient to generate a bounce for