Class AbstractMonitoringStrategy

java.lang.Object
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

    Fields
    Modifier and Type
    Field
    Description
    protected final org.apache.commons.logging.Log
    Logger available to subclasses.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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 as DELETED 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      protected final org.apache.commons.logging.Log logger
      Logger available to subclasses.
  • Constructor Details

    • AbstractMonitoringStrategy

      public AbstractMonitoringStrategy()
  • Method Details

    • 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 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 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:
      jakarta.mail.MessagingException - in case of JavaMail errors
      InterruptedException - 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 use Thread.sleep(long) or the IMAP IDLE command.
      Parameters:
      folder - the folder to monitor
      Throws:
      jakarta.mail.MessagingException - in case of JavaMail errors
      InterruptedException - 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 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:
      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 implementation fetches every javax.mail.FetchProfile.Item.
      Parameters:
      folder - the folder to fetch messages from
      messages - 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 when setDeleteMessages(boolean) is true.
      Parameters:
      folder - the folder to delete messages from
      messages - the messages to delete
      Throws:
      jakarta.mail.MessagingException - in case of JavaMail errors