| 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 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
|
|
|
| 75% |
Uncovered Elements: 10 (40) |
Complexity: 12 |
Complexity Density: 0.52 |
|
| 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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 28 |
1
|
public AbstractErrorQueuedTaskQueue(TaskQueue errorQueue, FifoBuffer buffer)... |
| 29 |
|
{ |
| 30 |
1
|
super(buffer); |
| 31 |
1
|
this.errorQueue = errorQueue; |
| 32 |
|
} |
| 33 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 34 |
3
|
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 |
|
|
|
|
|
| 52.9% |
Uncovered Elements: 8 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 44 |
3
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 69 |
4
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 79 |
3
|
public TaskQueue getErrorQueue()... |
| 80 |
|
{ |
| 81 |
3
|
return errorQueue; |
| 82 |
|
} |
| 83 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 84 |
0
|
public int getRetryCount()... |
| 85 |
|
{ |
| 86 |
0
|
return retryCount; |
| 87 |
|
} |
| 88 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 89 |
1
|
public void setRetryCount(int retryCount)... |
| 90 |
|
{ |
| 91 |
1
|
this.retryCount = retryCount; |
| 92 |
|
} |
| 93 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 94 |
|
public static class TaskDecorator implements Task, Serializable |
| 95 |
|
{ |
| 96 |
|
private Task task; |
| 97 |
|
private int executionCount = 0; |
| 98 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 99 |
2
|
public TaskDecorator(Task task)... |
| 100 |
|
{ |
| 101 |
2
|
this.task = task; |
| 102 |
|
} |
| 103 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 104 |
4
|
public void execute() throws Exception... |
| 105 |
|
{ |
| 106 |
4
|
executionCount++; |
| 107 |
4
|
task.execute(); |
| 108 |
|
} |
| 109 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
3
|
public int getExecutionCount()... |
| 111 |
|
{ |
| 112 |
3
|
return executionCount; |
| 113 |
|
} |
| 114 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 115 |
1
|
public Task getTask()... |
| 116 |
|
{ |
| 117 |
1
|
return task; |
| 118 |
|
} |
| 119 |
|
} |
| 120 |
|
} |