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
21
22 package org.apache.james.services;
23
24 import org.apache.mailet.Mail;
25
26 /**
27 * Interface for a Repository for Spooling Mails.
28 * A spool repository is a transitory repository which should empty itself
29 * if inbound deliveries stop.
30 *
31 * @version 1.0.0, 24/04/1999
32 */
33 public interface SpoolRepository
34 extends MailRepository {
35
36 /**
37 * The component role used by components implementing this service
38 */
39 String ROLE = "org.apache.james.services.SpoolRepository";
40
41 /**
42 * Implementations of AcceptFilter can be used to select which mails a SpoolRepository
43 * implementation returns from its accept (AcceptFilter) method
44 **/
45 public static interface AcceptFilter
46 {
47 /**
48 * This method is called by accept(Filter) to determine if the message is
49 * ready for delivery.
50 *
51 * @param key message key
52 * @param state the state of the message
53 * @param lastUpdated the last time the message was written to the spool
54 * @param errorMessage the current errorMessage
55 * @return true if the message is ready for delivery
56 **/
57 boolean accept (String key, String state, long lastUpdated, String errorMessage) ;
58
59
60 /**
61 * This method allows the filter to determine how long the thread should wait for a
62 * message to get ready for delivery, when currently there are none.
63 * @return the time to wait for a message to get ready for delivery
64 **/
65 long getWaitTime ();
66 }
67
68 /**
69 * Define a STREAM repository. Streams are stored in the specified
70 * destination.
71 */
72 String SPOOL = "SPOOL";
73
74 /**
75 * Returns an arbitrarily selected mail deposited in this Repository.
76 * Usage: SpoolManager calls accept() to see if there are any unprocessed
77 * mails in the spool repository.
78 *
79 * @return the mail
80 */
81 Mail accept() throws InterruptedException;
82
83 /**
84 * Returns an arbitrarily select mail deposited in this Repository that
85 * is either ready immediately for delivery, or is younger than it's last_updated plus
86 * the number of failed attempts times the delay time.
87 * Usage: RemoteDeliverySpool calls accept() with some delay and should block until an
88 * unprocessed mail is available.
89 *
90 * @return the mail
91 */
92 Mail accept(long delay) throws InterruptedException;
93
94 /**
95 * Returns an arbitrarily select mail deposited in this Repository for
96 * which the supplied filter's accept method returns true.
97 * Usage: RemoteDeliverySpool calls accept(filter) with some a filter which determines
98 * based on number of retries if the mail is ready for processing.
99 * If no message is ready the method will block until one is, the amount of time to block is
100 * determined by calling the filters getWaitTime method.
101 *
102 * @return the mail
103 */
104 Mail accept(AcceptFilter filter) throws InterruptedException;
105
106 }