Spring Web Services Framework

org.springframework.ws.transport.mail.monitor
Class AbstractMonitoringStrategy

java.lang.Object
  extended by org.springframework.ws.transport.mail.monitor.AbstractMonitoringStrategy
All Implemented Interfaces:
MonitoringStrategy
Direct Known Subclasses:
ImapIdleMonitoringStrategy, PollingMonitoringStrategy

public abstract class AbstractMonitoringStrategy
extends Object
implements MonitoringStrategy

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
protected  Log logger
          Logger available to subclasses.
 
Constructor Summary
AbstractMonitoringStrategy()
           
 
Method Summary
protected  void deleteMessages(Folder folder, Message[] messages)
          Deletes the given messages from the given folder.
protected  void fetchMessages(Folder folder, Message[] messages)
          Fetches the specified messages from the specified folder.
 int getFolderOpenMode()
          Returns the folder open mode to be used by this strategy.
 Message[] monitor(Folder folder)
          Monitors the given folder, and returns any new messages when they arrive.
protected  Message[] searchForNewMessages(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(Folder folder)
          Template method that blocks until new messages arrive in the given folder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Logger available to subclasses.

Constructor Detail

AbstractMonitoringStrategy

public AbstractMonitoringStrategy()
Method Detail

setDeleteMessages

public void setDeleteMessages(boolean deleteMessages)
Sets whether messages should be marked as DELETED after they have been read. Default is true.


getFolderOpenMode

public int getFolderOpenMode()
Description copied from interface: MonitoringStrategy
Returns the folder open mode to be used by this strategy. Can be either Folder.READ_ONLY or Folder.READ_WRITE.

Specified by:
getFolderOpenMode in interface MonitoringStrategy

monitor

public final Message[] monitor(Folder folder)
                        throws MessagingException,
                               InterruptedException
Monitors the given folder, and returns any new messages when they arrive. This implementation calls 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.

Specified by:
monitor in interface MonitoringStrategy
Parameters:
folder - the folder to monitor
Returns:
the new messages
Throws:
MessagingException - in case of JavaMail errors
InterruptedException - when a thread is interrupted

waitForNewMessages

protected abstract void waitForNewMessages(Folder folder)
                                    throws MessagingException,
                                           InterruptedException
Template method that blocks until new messages arrive in the given folder. Typical implementations use Thread.sleep(long) or the IMAP IDLE command.

Parameters:
folder - the folder to monitor
Throws:
MessagingException - in case of JavaMail errors
InterruptedException - when a thread is interrupted

searchForNewMessages

protected Message[] searchForNewMessages(Folder folder)
                                  throws MessagingException
Retrieves new messages from the given folder. This implementation creates a 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.

Parameters:
folder - the folder to retrieve new messages from
Returns:
the new messages
Throws:
MessagingException - in case of JavaMail errors

fetchMessages

protected void fetchMessages(Folder folder,
                             Message[] messages)
                      throws MessagingException
Fetches the specified messages from the specified folder. Default implementation fetches every FetchProfile.Item.

Parameters:
folder - the folder to fetch messages from
messages - the messages to fetch
Throws:
MessagingException - in case of JavMail errors

deleteMessages

protected void deleteMessages(Folder folder,
                              Message[] messages)
                       throws MessagingException
Deletes the given messages from the given folder. Only invoked when setDeleteMessages(boolean) is true.

Parameters:
folder - the folder to delete messages from
messages - the messages to delete
Throws:
MessagingException - in case of JavaMail errors

Spring Web Services Framework

Copyright © 2005-2010 The Spring Web Services Framework. All Rights Reserved.