Package ch.astorm.smtp4j.core
Class DefaultSmtpMessageHandler
java.lang.Object
ch.astorm.smtp4j.core.DefaultSmtpMessageHandler
- All Implemented Interfaces:
SmtpMessageHandler,SmtpServerListener
Simple
SmtpMessageHandler that stores the received messages in a list.
This class is Thread-safe.-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.astorm.smtp4j.core.SmtpMessageHandler
SmtpMessageHandler.SmtpMessageReader -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a newSmtpMessageReaderthat loops over the received messages.voidnotifyClose(SmtpServer server) Invoked when theserverhas been closed.voidnotifyMessage(SmtpServer server, SmtpMessage smtpMessage) Invoked when theserverhas received a message.voidnotifyStart(SmtpServer server) Invoked when theserverhas been started and is ready to receive messages.readMessages(long delayIfNoMessage, TimeUnit unit) Retrieves the received messages and clears the list.
-
Constructor Details
-
DefaultSmtpMessageHandler
public DefaultSmtpMessageHandler()
-
-
Method Details
-
notifyStart
Description copied from interface:SmtpServerListenerInvoked when theserverhas been started and is ready to receive messages.- Specified by:
notifyStartin interfaceSmtpServerListener- Parameters:
server- The startedSmtpServer.
-
notifyClose
Description copied from interface:SmtpServerListenerInvoked when theserverhas been closed.- Specified by:
notifyClosein interfaceSmtpServerListener- Parameters:
server- The stoppedSmtpServer.
-
notifyMessage
Description copied from interface:SmtpServerListenerInvoked when theserverhas received a message. This method will be invoked within the backgroundThreadused to receive the message.- Specified by:
notifyMessagein interfaceSmtpServerListener- Parameters:
server- TheSmtpServerthat received the message.smtpMessage- The received message.
-
messageReader
Description copied from interface:SmtpMessageHandlerReturns a newSmtpMessageReaderthat loops over the received messages. Note that if you create multipleSmtpMessageReaderinstances, the will compete over the same message list and the messages will be received only by one of the readers.- Specified by:
messageReaderin interfaceSmtpMessageHandler- Returns:
- A new
SmtpMessageReaderinstance.
-
readMessages
Description copied from interface:SmtpMessageHandlerRetrieves the received messages and clears the list. In case there are already some messages returned, this method returns them immediately without waiting.- Specified by:
readMessagesin interfaceSmtpMessageHandler- Parameters:
delayIfNoMessage- The delay to wait when there is no message yet received or a negative value to avoid any wait.unit- The unit of thedelayIfNoMessage.- Returns:
- All the (newly) received messages or an empty list if none.
-