public abstract class AbstractMonitoringStrategy extends Object implements MonitoringStrategy
MonitoringStrategy interface. Exposes a deleteMessages property, and includes a basic workflow for message monitoring.| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
logger
Logger available to subclasses.
|
| Constructor and Description |
|---|
AbstractMonitoringStrategy() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
deleteMessages(javax.mail.Folder folder,
javax.mail.Message[] messages)
Deletes the given messages from the given folder.
|
protected void |
fetchMessages(javax.mail.Folder folder,
javax.mail.Message[] messages)
Fetches the specified messages from the specified folder.
|
int |
getFolderOpenMode()
Returns the folder open mode to be used by this strategy.
|
javax.mail.Message[] |
monitor(javax.mail.Folder folder)
Monitors the given folder, and returns any new messages when they arrive.
|
protected javax.mail.Message[] |
searchForNewMessages(javax.mail.Folder folder)
Retrieves new messages from the given folder.
|
void |
setDeleteMessages(boolean deleteMessages)
Sets whether messages should be marked as
DELETED after they have been
read. |
protected abstract void |
waitForNewMessages(javax.mail.Folder folder)
Template method that blocks until new messages arrive in the given folder.
|
protected final org.apache.commons.logging.Log logger
public void setDeleteMessages(boolean deleteMessages)
DELETED after they have been
read. Default is true.public int getFolderOpenMode()
MonitoringStrategyFolder.READ_ONLY or Folder.READ_WRITE.getFolderOpenMode in interface MonitoringStrategypublic final javax.mail.Message[] monitor(javax.mail.Folder folder)
throws javax.mail.MessagingException,
InterruptedException
waitForNewMessages(Folder), then searches for new messages using searchForNewMessages(Folder), fetches
the messages using fetchMessages(Folder, Message[]), and finally deletes the messages, if deleteMessages is true.monitor in interface MonitoringStrategyfolder - the folder to monitorjavax.mail.MessagingException - in case of JavaMail errorsInterruptedException - when a thread is interruptedprotected abstract void waitForNewMessages(javax.mail.Folder folder)
throws javax.mail.MessagingException,
InterruptedException
Thread.sleep(long) or the IMAP IDLE command.folder - the folder to monitorjavax.mail.MessagingException - in case of JavaMail errorsInterruptedException - when a thread is interruptedprotected javax.mail.Message[] searchForNewMessages(javax.mail.Folder folder)
throws javax.mail.MessagingException
SearchTerm that searches for
all messages in the folder that are RECENT, not ANSWERED, and not DELETED. The search term
is used to search for new messages.folder - the folder to retrieve new messages fromjavax.mail.MessagingException - in case of JavaMail errorsprotected void fetchMessages(javax.mail.Folder folder,
javax.mail.Message[] messages)
throws javax.mail.MessagingException
fetches every FetchProfile.Item.folder - the folder to fetch messages frommessages - the messages to fetchjavax.mail.MessagingException - in case of JavMail errorsprotected void deleteMessages(javax.mail.Folder folder,
javax.mail.Message[] messages)
throws javax.mail.MessagingException
setDeleteMessages(boolean) is
true.folder - the folder to delete messages frommessages - the messages to deletejavax.mail.MessagingException - in case of JavaMail errorsCopyright © 2017 Pivotal Software. All rights reserved.