1   package com.atlassian.mail.queue;
2   
3   import com.atlassian.mail.MailThreader;
4   
5   import java.util.Date;
6   
7   public abstract class AbstractMailQueueItem implements MailQueueItem
8   {
9       String subject;
10      Date dateQueued;
11      private int timesSent = 0;
12      protected MailThreader mailThreader;
13      
14  
15      public AbstractMailQueueItem()
16      {
17          this.dateQueued = new Date();
18      }
19  
20      public AbstractMailQueueItem(String subject)
21      {
22          this();
23          this.subject = subject;
24      }
25  
26      public String getSubject()
27      {
28          return subject;
29      }
30  
31      public Date getDateQueued()
32      {
33          return dateQueued;
34      }
35  
36      public int getSendCount()
37      {
38          return timesSent;
39      }
40  
41      public boolean hasError()
42      {
43          return (timesSent > 0);
44      }
45  
46      protected void incrementSendCount()
47      {
48          timesSent++;
49      }
50  
51      public void setMailThreader(MailThreader mailThreader) {
52          this.mailThreader = mailThreader;
53      }
54  
55      public void execute() throws Exception
56      {
57          send();
58      }
59  
60      final public int compareTo(MailQueueItem o)
61      {
62          int priorityComparator = new Integer(timesSent).compareTo(o.getSendCount());
63          return priorityComparator == 0 ? dateQueued.compareTo(o.getDateQueued()) : priorityComparator;
64      }
65  }