11 |
|
/** |
12 |
|
* AsyncActions that may be linked in parent-child relationships. |
13 |
|
* |
14 |
< |
* <p> Upon construction, an LinkedAsyncAction may register as a |
14 |
> |
* <p>Upon construction, an LinkedAsyncAction may register as a |
15 |
|
* subtask of a given parent task. In this case, completion of this |
16 |
|
* task will propagate to its parent. If the parent's pending subtask |
17 |
|
* completion count becomes zero, it too will complete. |
24 |
|
* <tt>complete</tt> of the subtask will trigger <tt>complete</tt> of the |
25 |
|
* parent without the parent explicitly doing so. |
26 |
|
* |
27 |
< |
* <p> In addition to supporting these different computation styles |
27 |
> |
* <p>In addition to supporting these different computation styles |
28 |
|
* compared to Recursive tasks, LinkedAsyncActions may have smaller |
29 |
|
* stack space footprints while executing, but may have greater |
30 |
|
* per-task overhead. |
31 |
|
* |
32 |
< |
* <p> <b>Sample Usage.</b> Here is a sketch of an LinkedAsyncAction |
32 |
> |
* <p><b>Sample Usage.</b> Here is a sketch of an LinkedAsyncAction |
33 |
|
* that visits all of the nodes of a graph. The details of the graph's |
34 |
|
* Node and Edge classes are omitted, but we assume each node contains |
35 |
|
* an <tt>AtomicBoolean</tt> mark that starts out false. To execute |
39 |
|
* |
40 |
|
* <pre> |
41 |
|
* class GraphVisitor extends LinkedAsyncAction { |
42 |
< |
* final Node node; |
43 |
< |
* GraphVisitor(GraphVistor parent, Node node) { |
44 |
< |
* super(parent); this.node = node; |
45 |
< |
* } |
46 |
< |
* protected void compute() { |
47 |
< |
* if (node.mark.compareAndSet(false, true)) { |
48 |
< |
* for (Edge e : node.edges()) { |
49 |
< |
* Node dest = e.getDestination(); |
50 |
< |
* if (!dest.mark.get()) |
51 |
< |
* new GraphVisitor(this, dest).fork(); |
52 |
< |
* } |
53 |
< |
* visit(node); |
54 |
< |
* } |
55 |
< |
* complete(); |
42 |
> |
* final Node node; |
43 |
> |
* GraphVisitor(GraphVistor parent, Node node) { |
44 |
> |
* super(parent); this.node = node; |
45 |
> |
* } |
46 |
> |
* protected void compute() { |
47 |
> |
* if (node.mark.compareAndSet(false, true)) { |
48 |
> |
* for (Edge e : node.edges()) { |
49 |
> |
* Node dest = e.getDestination(); |
50 |
> |
* if (!dest.mark.get()) |
51 |
> |
* new GraphVisitor(this, dest).fork(); |
52 |
> |
* } |
53 |
> |
* visit(node); |
54 |
> |
* } |
55 |
> |
* complete(); |
56 |
|
* } |
57 |
|
* } |
58 |
|
* </pre> |