Class PriorityQueueEmailSchedulerService

java.lang.Object
it.ozimov.springboot.mail.service.defaultimpl.PriorityQueueEmailSchedulerService
All Implemented Interfaces:
EmailSchedulerService

@Service("priorityQueueEmailSchedulerService") @ConditionalOnExpression("\'${spring.mail.scheduler.enabled:false}\' == \'true\'") public class PriorityQueueEmailSchedulerService extends Object implements EmailSchedulerService
The class provides a EmailSchedulerService implementation with priority queues and persistence.

Main logic for the thread wait-notify mechanism comes from

  • Field Details

    • CONSUMER_CYCLE_LENGTH

      protected static final Duration CONSUMER_CYCLE_LENGTH
      millisecs elapsed form the call of the send method and the actual sending by SMTP server
    • RESUMER_CYCLE_LENGTH

      protected static final Duration RESUMER_CYCLE_LENGTH
      millisecs elapsed form the call of the send method and the actual sending by SMTP server
  • Constructor Details

  • Method Details

    • schedule

      @Async public void schedule(@NonNull @NonNull Email mimeEmail, int desiredPriorityLevel)
      Description copied from interface: EmailSchedulerService
      Schedules the sending of an email message at time now (UTC).
      Specified by:
      schedule in interface EmailSchedulerService
      Parameters:
      mimeEmail - an email to be sent
      desiredPriorityLevel - the desiredPriority level for the email: the emails with scheduledTime<=now are sent according to an order depending on their desiredPriority level
    • schedule

      @Async public void schedule(@NonNull @NonNull Email mimeEmail, @NonNull @NonNull OffsetDateTime scheduledDateTime, int desiredPriorityLevel)
      Description copied from interface: EmailSchedulerService
      Schedules the sending of an email message.
      Specified by:
      schedule in interface EmailSchedulerService
      Parameters:
      mimeEmail - an email to be sent
      scheduledDateTime - the date-time at which the email should be sent
      desiredPriorityLevel - the desiredPriority level for the email: the emails with scheduledTime<=now are sent according to an order depending on their desiredPriority level
    • schedule

      @Async public void schedule(@NonNull @NonNull Email mimeEmail, int desiredPriorityLevel, @NonNull @NonNull String template, @NonNull @NonNull Map<String,Object> modelObject, InlinePicture... inlinePictures) throws CannotSendEmailException
      Description copied from interface: EmailSchedulerService
      Schedules the sending of an email message at time now (UTC).
      Specified by:
      schedule in interface EmailSchedulerService
      Parameters:
      mimeEmail - an email to be sent
      desiredPriorityLevel - the desiredPriority level for the email: the emails with scheduledTime<=now are sent according to an order depending on their desiredPriority level
      template - the reference to the template file
      modelObject - the model object to be used for the template engine, it may be null
      inlinePictures - list of pictures to be rendered inline in the template
      Throws:
      CannotSendEmailException
    • schedule

      @Async public void schedule(@NonNull @NonNull Email mimeEmail, @NonNull @NonNull OffsetDateTime scheduledDateTime, int desiredPriorityLevel, @NonNull @NonNull String template, @NonNull @NonNull Map<String,Object> modelObject, InlinePicture... inlinePictures) throws CannotSendEmailException
      Description copied from interface: EmailSchedulerService
      Schedules the sending of an email message.
      Specified by:
      schedule in interface EmailSchedulerService
      Parameters:
      mimeEmail - an email to be sent
      scheduledDateTime - the date-time at which the email should be sent
      desiredPriorityLevel - the desiredPriority level for the email: the emails with scheduledTime<=now are sent according to an order depending on their desiredPriority level
      template - the reference to the template file
      modelObject - the model object to be used for the template engine, it may be null
      inlinePictures - list of pictures to be rendered inline in the template
      Throws:
      CannotSendEmailException
    • buildEmailSchedulingData

      protected EmailSchedulingData buildEmailSchedulingData(@NonNull @NonNull Email mimeEmail, @NonNull @NonNull OffsetDateTime scheduledDateTime, int desiredPriorityLevel, int assignedPriorityLevel)
    • buildEmailSchedulingData

      protected EmailSchedulingData buildEmailSchedulingData(@NonNull @NonNull Email mimeEmail, @NonNull @NonNull OffsetDateTime scheduledDateTime, int desiredPriorityLevel, @NonNull @NonNull String template, @NonNull @NonNull Map<String,Object> modelObject, int assignedPriorityLevel, InlinePicture[] inlinePictures)
    • schedule

      protected void schedule(EmailSchedulingData emailSchedulingData)
    • startResumer

      protected void startResumer() throws InterruptedException
      Throws:
      InterruptedException
    • startConsumer

      protected void startConsumer() throws InterruptedException
      Throws:
      InterruptedException
    • addToPersistenceLayer

      protected void addToPersistenceLayer(EmailSchedulingData emailSchedulingData)
    • deleteFromPersistenceLayer

      protected void deleteFromPersistenceLayer(EmailSchedulingData emailSchedulingData)
    • loadNextBatch

      protected void loadNextBatch()
    • enqueueBatch

      protected void enqueueBatch(Collection<EmailSchedulingData> emailSchedulingDataCollection)
    • normalizePriority

      protected int normalizePriority(int priorityLevel)
    • cleanUp

      @PreDestroy protected void cleanUp() throws Exception
      Throws:
      Exception