1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.ui.client.mvc; |
17 |
|
|
18 |
|
|
19 |
|
@author |
20 |
|
|
21 |
|
import java.util.LinkedList; |
22 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 10 |
Complexity Density: 0.59 |
|
23 |
|
public class WorkQueue { |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
24 |
|
public static abstract class WorkItem { |
25 |
|
private boolean canceled = false; |
26 |
|
|
27 |
|
public abstract void exec(final Callback<Boolean> onCompleteCallback); |
28 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
29 |
0
|
public boolean isCanceled() {... |
30 |
0
|
return this.canceled; |
31 |
|
} |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
33 |
0
|
protected void setCanceled(final boolean canceled) {... |
34 |
0
|
this.canceled = canceled; |
35 |
|
} |
36 |
|
} |
37 |
|
|
38 |
|
private boolean running = false; |
39 |
|
private final LinkedList<WorkItem> queue = new LinkedList<WorkItem>(); |
40 |
|
|
41 |
|
private final Callback<Boolean> onCompleteCallback = new Callback<Boolean>() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
42 |
0
|
@Override... |
43 |
|
public void exec(final Boolean value) { |
44 |
0
|
processNext(); |
45 |
|
} |
46 |
|
}; |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
48 |
0
|
public void clear() {... |
49 |
0
|
for (final WorkItem item : queue) { |
50 |
0
|
item.setCanceled(true); |
51 |
|
} |
52 |
0
|
queue.clear(); |
53 |
|
} |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
0
|
public boolean isRunning() {... |
56 |
0
|
return this.running; |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
59 |
0
|
private void processNext() {... |
60 |
0
|
WorkItem item = null; |
61 |
0
|
while (!queue.isEmpty() && (item = queue.removeFirst()) != null) { |
62 |
0
|
if (item.isCanceled()) { |
63 |
0
|
item = null; |
64 |
|
} else { |
65 |
0
|
break; |
66 |
|
} |
67 |
|
} |
68 |
0
|
if (item == null) { |
69 |
0
|
running = false; |
70 |
|
} else { |
71 |
0
|
item.exec(onCompleteCallback); |
72 |
|
} |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
75 |
0
|
public void submit(final WorkItem item) {... |
76 |
0
|
queue.add(item); |
77 |
0
|
if (!running) { |
78 |
0
|
running = true; |
79 |
0
|
processNext(); |
80 |
|
} |
81 |
|
} |
82 |
|
} |