Package com.mimecast.robin.queue
Class RelayDequeue
java.lang.Object
com.mimecast.robin.queue.RelayDequeue
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.apache.logging.log4j.Loggerprivate final PersistentQueue<RelaySession> -
Constructor Summary
ConstructorsConstructorDescriptionRelayDequeue(PersistentQueue<RelaySession> queue) Constructs a RelayDequeue processor with the specified queue. -
Method Summary
Modifier and TypeMethodDescription(package private) voidattemptDelivery(RelaySession relaySession) Attempts delivery of the relay session using the appropriate protocol.(package private) voidcleanupSuccessfulEnvelopes(List<MessageEnvelope> successfulEnvelopes) Deletes the files associated with successful envelopes.(package private) intcountRecipients(RelaySession relaySession) Counts the total number of recipients across all envelopes in the session.(package private) voidcreateAndEnqueueBounce(RelaySession originalSession, String recipient) Creates a bounce message for a failed recipient and enqueues it for delivery.(package private) voidgenerateBounces(RelaySession relaySession) Generates bounce messages for all recipients in the remaining envelopes.(package private) voidhandleRemainingEnvelopes(RelaySession relaySession, RelayDeliveryResult result) Handles remaining envelopes that were not successfully delivered.(package private) booleanisReadyForRetry(RelaySession relaySession, long currentEpochSeconds) Checks if a relay session is ready for retry based on its retry count and last retry time.private voidlogSessionInfo(RelaySession relaySession) Logs information about the session being processed.voidprocessBatch(int maxDequeuePerTick, long currentEpochSeconds) Processes a batch of relay sessions from the queue.(package private) RelayDeliveryResultprocessDeliveryResults(RelaySession relaySession) Processes the delivery results, removing successful envelopes and updating failed ones.(package private) voidprocessSession(RelaySession relaySession, long currentEpochSeconds) Processes a single relay session.(package private) voidreEnqueueSession(RelaySession relaySession, String reason) Re-enqueues a session back to the queue after persisting its files.(package private) voidretrySession(RelaySession relaySession) Increments the retry count and re-enqueues the session for another attempt.
-
Field Details
-
log
private static final org.apache.logging.log4j.Logger log -
queue
-
-
Constructor Details
-
RelayDequeue
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
maxDequeuePerTicksessions. Sessions that are not yet ready for retry will be re-enqueued.- Parameters:
maxDequeuePerTick- the maximum number of sessions to process in this executioncurrentEpochSeconds- the current time in epoch seconds
-
processSession
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 processcurrentEpochSeconds- the current time in epoch seconds
-
isReadyForRetry
Checks if a relay session is ready for retry based on its retry count and last retry time.- Parameters:
relaySession- the relay session to checkcurrentEpochSeconds- the current time in epoch seconds- Returns:
- true if the session is ready for retry, false otherwise
-
logSessionInfo
Logs information about the session being processed.- Parameters:
relaySession- the relay session
-
countRecipients
Counts the total number of recipients across all envelopes in the session.- Parameters:
relaySession- the relay session- Returns:
- the total number of recipients
-
attemptDelivery
Attempts delivery of the relay session using the appropriate protocol.- Parameters:
relaySession- the relay session to deliver
-
processDeliveryResults
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
Deletes the files associated with successful envelopes.- Parameters:
successfulEnvelopes- the list of successfully delivered envelopes
-
handleRemainingEnvelopes
Handles remaining envelopes that were not successfully delivered.If under max retries, re-enqueues the session. Otherwise, generates bounce messages.
- Parameters:
relaySession- the relay sessionresult- the delivery result
-
retrySession
Increments the retry count and re-enqueues the session for another attempt.- Parameters:
relaySession- the relay session to retry
-
reEnqueueSession
Re-enqueues a session back to the queue after persisting its files.- Parameters:
relaySession- the relay session to re-enqueuereason- the reason for re-enqueueing (for logging)
-
generateBounces
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
Creates a bounce message for a failed recipient and enqueues it for delivery.- Parameters:
originalSession- the original relay session that failedrecipient- the recipient to generate a bounce for
-