-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy pathLinearTask.java
43 lines (38 loc) · 1.23 KB
/
LinearTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import akka.dispatch.forkjoin.RecursiveTask;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
public class LinearTask extends RecursiveTask<Integer> {
private final int depth;
private final int parent;
public LinearTask(int depth) {
this(0, depth);
}
private LinearTask(int parent, int depth) {
this.parent = parent;
this.depth = depth;
}
@Override
protected Integer compute() {
try {
// introduces delay to encourage parallelism
// which will expose problems with context propagation
Thread.sleep(5);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
if (parent == depth) {
return parent;
} else {
int next = parent + 1;
AgentSpan span = startSpan("akka-concurrent", Integer.toString(next));
try (AgentScope scope = activateSpan(span)) {
LinearTask child = new LinearTask(next, depth);
return child.fork().join();
} finally {
span.finish();
}
}
}
}