1 package com.atlassian.mail.queue;
2
3 import java.sql.Timestamp;
4 import java.util.Queue;
5
6 /**
7 * The MailQueue is used to asynchronously send mail from within applications.
8 * <p/>
9 * It is populated with {@link MailQueueItem} objects, which know how to send themselves.
10 * <p/>
11 * The queue also keeps track of which messages have attempted to be send, and were erroring.
12 */
13 public interface MailQueue
14 {
15 /**
16 * Send all the messages in the queue.
17 */
18 void sendBuffer();
19
20 /**
21 * @return The number of messages in the queue.
22 */
23 int size();
24
25 /**
26 * @return The number of erroring messages in the queue.
27 */
28 int errorSize();
29
30 /**
31 * Add a new item to the mail queue.
32 *
33 * @param item The item to be added to the queue.
34 */
35 void addItem(MailQueueItem item);
36
37 /**
38 * Add an error item
39 *
40 * @param item
41 */
42 void addErrorItem(MailQueueItem item);
43
44 /**
45 * Get access to the messages in the mail queue.
46 * <p/>
47 * Note: you should synchronize on access to this queue.
48 */
49 Queue<MailQueueItem> getQueue();
50
51 /**
52 * Get access to the messages in the error queue.
53 * <p/>
54 * Note: you should synchronize on access to this queue.
55 */
56 Queue<MailQueueItem> getErrorQueue();
57
58 /**
59 * @return Whether or not the queue is currently sending.
60 */
61 boolean isSending();
62
63 /**
64 * @return The date/time the queue started sending, null if the queue is not sending
65 */
66 Timestamp getSendingStarted();
67
68 /**
69 * Empty the error queue (discard these messages)
70 */
71 void emptyErrorQueue();
72
73 /**
74 * Send all messages in the error queue.
75 */
76 void resendErrorQueue();
77
78 /**
79 * Retrieve the item currently being sent.
80 */
81 MailQueueItem getItemBeingSent();
82
83 /**
84 * If the queue is sending and has 'stuck' on an item, this lets the queue proceed.
85 * Only relevant for synchronous queues.
86 */
87 void unstickQueue();
88 }