View Javadoc

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