View Javadoc

1   /************************************************************************
2    * Copyright (c) 1999-2006 The Apache Software Foundation.             *
3    * All rights reserved.                                                *
4    * ------------------------------------------------------------------- *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you *
6    * may not use this file except in compliance with the License. You    *
7    * may obtain a copy of the License at:                                *
8    *                                                                     *
9    *     http://www.apache.org/licenses/LICENSE-2.0                      *
10   *                                                                     *
11   * Unless required by applicable law or agreed to in writing, software *
12   * distributed under the License is distributed on an "AS IS" BASIS,   *
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
14   * implied.  See the License for the specific language governing       *
15   * permissions and limitations under the License.                      *
16   ***********************************************************************/
17  
18  package org.apache.james.services;
19  
20  import org.apache.mailet.Mail;
21  
22  /***
23   * Interface for a Repository for Spooling Mails.
24   * A spool repository is a transitory repository which should empty itself 
25   * if inbound deliveries stop.
26   *
27   * @version 1.0.0, 24/04/1999
28   */
29  public interface SpoolRepository 
30      extends MailRepository {
31  
32      /***
33       * The component role used by components implementing this service
34       */
35      String ROLE = "org.apache.james.services.SpoolRepository";
36  
37      /***
38       * Implementations of AcceptFilter can be used to select which mails a SpoolRepository
39       * implementation returns from its accept (AcceptFilter) method
40       **/
41      public static interface AcceptFilter
42      {
43          /***
44           * This method is called by accept(Filter) to determine if the message is
45           * ready for delivery.
46           *
47           * @param key message key
48           * @param state the state of the message
49           * @param lastUpdated the last time the message was written to the spool
50           * @param errorMessage the current errorMessage
51           * @return true if the message is ready for delivery
52           **/
53          boolean accept (String key, String state, long lastUpdated, String errorMessage) ;
54  
55  
56          /***
57           * This method allows the filter to determine how long the thread should wait for a
58           * message to get ready for delivery, when currently there are none.
59           * @return the time to wait for a message to get ready for delivery
60           **/
61          long getWaitTime ();
62      }
63      
64      /***
65       * Define a STREAM repository. Streams are stored in the specified
66       * destination.
67       */
68      String SPOOL = "SPOOL";
69  
70      /***
71       * Returns an arbitrarily selected mail deposited in this Repository.
72       * Usage: SpoolManager calls accept() to see if there are any unprocessed 
73       * mails in the spool repository.
74       *
75       * @return the mail
76       */
77      Mail accept() throws InterruptedException;
78  
79      /***
80       * Returns an arbitrarily select mail deposited in this Repository that
81       * is either ready immediately for delivery, or is younger than it's last_updated plus
82       * the number of failed attempts times the delay time.
83       * Usage: RemoteDeliverySpool calls accept() with some delay and should block until an
84       * unprocessed mail is available.
85       *
86       * @return the mail
87       */
88      Mail accept(long delay) throws InterruptedException;
89  
90      /***
91       * Returns an arbitrarily select mail deposited in this Repository for
92       * which the supplied filter's accept method returns true.
93       * Usage: RemoteDeliverySpool calls accept(filter) with some a filter which determines
94       * based on number of retries if the mail is ready for processing.
95       * If no message is ready the method will block until one is, the amount of time to block is
96       * determined by calling the filters getWaitTime method.
97       *
98       * @return the mail
99       */
100     Mail accept(AcceptFilter filter) throws InterruptedException;
101 
102 }