Class AbstractMonitoringStrategy
java.lang.Object
org.springframework.ws.transport.mail.monitor.AbstractMonitoringStrategy
- All Implemented Interfaces:
MonitoringStrategy
- Direct Known Subclasses:
ImapIdleMonitoringStrategy
,PollingMonitoringStrategy
Abstract base class for the
MonitoringStrategy
interface. Exposes a deleteMessages
property, and includes a basic workflow for message monitoring.- Since:
- 1.5.0
- Author:
- Arjen Poutsma
-
Field Summary
Modifier and TypeFieldDescriptionprotected final org.apache.commons.logging.Log
Logger available to subclasses. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
deleteMessages
(jakarta.mail.Folder folder, jakarta.mail.Message[] messages) Deletes the given messages from the given folder.protected void
fetchMessages
(jakarta.mail.Folder folder, jakarta.mail.Message[] messages) Fetches the specified messages from the specified folder.int
Returns the folder open mode to be used by this strategy.final jakarta.mail.Message[]
monitor
(jakarta.mail.Folder folder) Monitors the given folder, and returns any new messages when they arrive.protected jakarta.mail.Message[]
searchForNewMessages
(jakarta.mail.Folder folder) Retrieves new messages from the given folder.void
setDeleteMessages
(boolean deleteMessages) Sets whether messages should be marked asDELETED
after they have been read.protected abstract void
waitForNewMessages
(jakarta.mail.Folder folder) Template method that blocks until new messages arrive in the given folder.
-
Field Details
-
logger
protected final org.apache.commons.logging.Log loggerLogger available to subclasses.
-
-
Constructor Details
-
AbstractMonitoringStrategy
public AbstractMonitoringStrategy()
-
-
Method Details
-
setDeleteMessages
public void setDeleteMessages(boolean deleteMessages) Sets whether messages should be marked asDELETED
after they have been read. Default istrue
. -
getFolderOpenMode
public int getFolderOpenMode()Description copied from interface:MonitoringStrategy
Returns the folder open mode to be used by this strategy. Can be eitherFolder.READ_ONLY
orFolder.READ_WRITE
.- Specified by:
getFolderOpenMode
in interfaceMonitoringStrategy
-
monitor
public final jakarta.mail.Message[] monitor(jakarta.mail.Folder folder) throws jakarta.mail.MessagingException, InterruptedException Monitors the given folder, and returns any new messages when they arrive. This implementation callswaitForNewMessages(Folder)
, then searches for new messages usingsearchForNewMessages(Folder)
, fetches the messages usingfetchMessages(Folder, Message[])
, and finallydeletes
the messages, ifdeleteMessages
istrue
.- Specified by:
monitor
in interfaceMonitoringStrategy
- Parameters:
folder
- the folder to monitor- Returns:
- the new messages
- Throws:
jakarta.mail.MessagingException
- in case of JavaMail errorsInterruptedException
- when a thread is interrupted
-
waitForNewMessages
protected abstract void waitForNewMessages(jakarta.mail.Folder folder) throws jakarta.mail.MessagingException, InterruptedException Template method that blocks until new messages arrive in the given folder. Typical implementations useThread.sleep(long)
or the IMAP IDLE command.- Parameters:
folder
- the folder to monitor- Throws:
jakarta.mail.MessagingException
- in case of JavaMail errorsInterruptedException
- when a thread is interrupted
-
searchForNewMessages
protected jakarta.mail.Message[] searchForNewMessages(jakarta.mail.Folder folder) throws jakarta.mail.MessagingException Retrieves new messages from the given folder. This implementation creates aSearchTerm
that searches for all messages in the folder that areRECENT
, notANSWERED
, and notDELETED
. The search term is used tosearch
for new messages.- Parameters:
folder
- the folder to retrieve new messages from- Returns:
- the new messages
- Throws:
jakarta.mail.MessagingException
- in case of JavaMail errors
-
fetchMessages
protected void fetchMessages(jakarta.mail.Folder folder, jakarta.mail.Message[] messages) throws jakarta.mail.MessagingException Fetches the specified messages from the specified folder. Default implementationfetches
everyjavax.mail.FetchProfile.Item
.- Parameters:
folder
- the folder to fetch messages frommessages
- the messages to fetch- Throws:
jakarta.mail.MessagingException
- in case of JavMail errors
-
deleteMessages
protected void deleteMessages(jakarta.mail.Folder folder, jakarta.mail.Message[] messages) throws jakarta.mail.MessagingException Deletes the given messages from the given folder. Only invoked whensetDeleteMessages(boolean)
istrue
.- Parameters:
folder
- the folder to delete messages frommessages
- the messages to delete- Throws:
jakarta.mail.MessagingException
- in case of JavaMail errors
-