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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPriorityQueueEmailSchedulerService(EmailService emailService, EmailSchedulerProperties emailSchedulerProperties, Optional<PersistenceService> persistenceServiceOptional, EmailLogRenderer emailLogRenderer) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddToPersistenceLayer(EmailSchedulingData emailSchedulingData) protected EmailSchedulingDatabuildEmailSchedulingData(@NonNull Email mimeEmail, @NonNull OffsetDateTime scheduledDateTime, int desiredPriorityLevel, int assignedPriorityLevel) protected EmailSchedulingDatabuildEmailSchedulingData(@NonNull Email mimeEmail, @NonNull OffsetDateTime scheduledDateTime, int desiredPriorityLevel, @NonNull String template, @NonNull Map<String, Object> modelObject, int assignedPriorityLevel, InlinePicture[] inlinePictures) protected voidcleanUp()protected voiddeleteFromPersistenceLayer(EmailSchedulingData emailSchedulingData) protected voidenqueueBatch(Collection<EmailSchedulingData> emailSchedulingDataCollection) protected voidprotected intnormalizePriority(int priorityLevel) voidSchedules the sending of an email message at time now (UTC).voidschedule(@NonNull Email mimeEmail, int desiredPriorityLevel, @NonNull String template, @NonNull Map<String, Object> modelObject, InlinePicture... inlinePictures) Schedules the sending of an email message at time now (UTC).voidschedule(@NonNull Email mimeEmail, @NonNull OffsetDateTime scheduledDateTime, int desiredPriorityLevel) Schedules the sending of an email message.voidschedule(@NonNull Email mimeEmail, @NonNull OffsetDateTime scheduledDateTime, int desiredPriorityLevel, @NonNull String template, @NonNull Map<String, Object> modelObject, InlinePicture... inlinePictures) Schedules the sending of an email message.protected voidschedule(EmailSchedulingData emailSchedulingData) protected voidprotected voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface it.ozimov.springboot.mail.service.EmailSchedulerService
status
-
Field Details
-
CONSUMER_CYCLE_LENGTH
millisecs elapsed form the call of the send method and the actual sending by SMTP server -
RESUMER_CYCLE_LENGTH
millisecs elapsed form the call of the send method and the actual sending by SMTP server
-
-
Constructor Details
-
PriorityQueueEmailSchedulerService
@Autowired public PriorityQueueEmailSchedulerService(EmailService emailService, EmailSchedulerProperties emailSchedulerProperties, Optional<PersistenceService> persistenceServiceOptional, EmailLogRenderer emailLogRenderer) throws InterruptedException - Throws:
InterruptedException
-
-
Method Details
-
schedule
Description copied from interface:EmailSchedulerServiceSchedules the sending of an email message at time now (UTC).- Specified by:
schedulein interfaceEmailSchedulerService- Parameters:
mimeEmail- an email to be sentdesiredPriorityLevel- 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:EmailSchedulerServiceSchedules the sending of an email message.- Specified by:
schedulein interfaceEmailSchedulerService- Parameters:
mimeEmail- an email to be sentscheduledDateTime- the date-time at which the email should be sentdesiredPriorityLevel- 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 CannotSendEmailExceptionDescription copied from interface:EmailSchedulerServiceSchedules the sending of an email message at time now (UTC).- Specified by:
schedulein interfaceEmailSchedulerService- Parameters:
mimeEmail- an email to be sentdesiredPriorityLevel- the desiredPriority level for the email: the emails with scheduledTime<=now are sent according to an order depending on their desiredPriority leveltemplate- the reference to the template filemodelObject- the model object to be used for the template engine, it may be nullinlinePictures- 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 CannotSendEmailExceptionDescription copied from interface:EmailSchedulerServiceSchedules the sending of an email message.- Specified by:
schedulein interfaceEmailSchedulerService- Parameters:
mimeEmail- an email to be sentscheduledDateTime- the date-time at which the email should be sentdesiredPriorityLevel- the desiredPriority level for the email: the emails with scheduledTime<=now are sent according to an order depending on their desiredPriority leveltemplate- the reference to the template filemodelObject- the model object to be used for the template engine, it may be nullinlinePictures- 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
-
startResumer
- Throws:
InterruptedException
-
startConsumer
- Throws:
InterruptedException
-
addToPersistenceLayer
-
deleteFromPersistenceLayer
-
loadNextBatch
protected void loadNextBatch() -
enqueueBatch
-
normalizePriority
protected int normalizePriority(int priorityLevel) -
cleanUp
- Throws:
Exception
-