Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
28   120   16   2.55
10   92   0.57   5.5
11     1.45  
2    
 
 
  AbstractErrorQueuedTaskQueue       Line # 18 23 12 75% 0.75
  AbstractErrorQueuedTaskQueue.TaskDecorator       Line # 94 5 4 100% 1.0
 
  (1)
 
1    package com.atlassian.core.task;
2   
3    import org.apache.log4j.Logger;
4   
5    import javax.mail.MessagingException;
6    import java.io.Serializable;
7    import java.util.ArrayList;
8    import java.util.Iterator;
9    import java.util.List;
10   
11    /**
12    * Created by IntelliJ IDEA.
13    * User: Tomd
14    * Date: 26/04/2006
15    * Time: 11:22:54
16    * To change this template use File | Settings | File Templates.
17    */
 
18    public class AbstractErrorQueuedTaskQueue extends AbstractTaskQueue implements TaskQueueWithErrorQueue
19    {
20    private static final transient Logger log = Logger.getLogger(AbstractErrorQueuedTaskQueue.class);
21   
22    private TaskQueue errorQueue;
23   
24    private int retryCount = 5;
25   
26    private List failed;
27   
 
28  1 toggle public AbstractErrorQueuedTaskQueue(TaskQueue errorQueue, FifoBuffer buffer)
29    {
30  1 super(buffer);
31  1 this.errorQueue = errorQueue;
32    }
33   
 
34  3 toggle public void flush()
35    {
36  3 failed = new ArrayList();
37  3 super.flush();
38  5 for (Iterator iterator = failed.iterator(); iterator.hasNext();)
39    {
40  2 addTask((Task)iterator.next());
41    }
42    }
43   
 
44  3 toggle protected void handleException(Task task, Exception rootException)
45    {
46  3 TaskDecorator theTask = (TaskDecorator)task;
47   
48  3 if (theTask.getExecutionCount() > retryCount) {
49   
50  1 errorQueue.addTask(theTask.getTask());
51    }else {
52   
53  2 failed.add(task);
54    }
55  3 if (rootException instanceof MessagingException)
56    {
57  0 Exception e = rootException;
58  0 while (e instanceof MessagingException)
59    {
60  0 MessagingException me = (MessagingException)e;
61  0 log.error(me.getMessage(), me);
62  0 e = me.getNextException();
63    }
64    }
65    else
66  3 log.error(rootException, rootException);
67    }
68   
 
69  4 toggle public void addTask(Task task)
70    {
71  4 if(task instanceof TaskDecorator)
72    {
73  2 super.addTask(task);
74    } else {
75  2 super.addTask(new TaskDecorator(task));
76    }
77    }
78   
 
79  3 toggle public TaskQueue getErrorQueue()
80    {
81  3 return errorQueue;
82    }
83   
 
84  0 toggle public int getRetryCount()
85    {
86  0 return retryCount;
87    }
88   
 
89  1 toggle public void setRetryCount(int retryCount)
90    {
91  1 this.retryCount = retryCount;
92    }
93   
 
94    public static class TaskDecorator implements Task, Serializable
95    {
96    private Task task;
97    private int executionCount = 0;
98   
 
99  2 toggle public TaskDecorator(Task task)
100    {
101  2 this.task = task;
102    }
103   
 
104  4 toggle public void execute() throws Exception
105    {
106  4 executionCount++;
107  4 task.execute();
108    }
109   
 
110  3 toggle public int getExecutionCount()
111    {
112  3 return executionCount;
113    }
114   
 
115  1 toggle public Task getTask()
116    {
117  1 return task;
118    }
119    }
120    }