View Javadoc

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