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.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. If no new message has been received since the last notification, an empty list will be returned.- Specified by:
readMessagesin interfaceSmtpMessageHandler- Returns:
- All the (newly) received messages or an empty list if none.
-