58020
|
1 |
package jdk.jfr.consumer;
|
|
2 |
|
|
3 |
import java.time.Instant;
|
|
4 |
import java.util.ArrayList;
|
|
5 |
import java.util.List;
|
|
6 |
import java.util.function.Consumer;
|
|
7 |
|
58129
|
8 |
import jdk.jfr.consumer.Dispatcher.EventDispatcher;
|
58020
|
9 |
import jdk.jfr.internal.Utils;
|
|
10 |
|
|
11 |
final class StreamConfiguration {
|
58129
|
12 |
final List<Runnable> closeActions = new ArrayList<>();
|
|
13 |
final List<Runnable> flushActions = new ArrayList<>();
|
|
14 |
final List<EventDispatcher> eventActions = new ArrayList<>();
|
|
15 |
final List<Consumer<Throwable>> errorActions = new ArrayList<>();
|
58020
|
16 |
|
58129
|
17 |
boolean reuse = true;
|
|
18 |
boolean ordered = true;
|
|
19 |
Instant startTime = null;
|
|
20 |
Instant endTime = null;
|
|
21 |
boolean started = false;
|
|
22 |
long startNanos = 0;
|
|
23 |
long endNanos = Long.MAX_VALUE;
|
58020
|
24 |
|
58129
|
25 |
volatile boolean changed = true;
|
58020
|
26 |
|
58129
|
27 |
public synchronized boolean remove(Object action) {
|
|
28 |
boolean removed = false;
|
|
29 |
removed |= flushActions.removeIf(e -> e == action);
|
|
30 |
removed |= closeActions.removeIf(e -> e == action);
|
|
31 |
removed |= errorActions.removeIf(e -> e == action);
|
|
32 |
removed |= eventActions.removeIf(e -> e.action == action);
|
|
33 |
if (removed) {
|
|
34 |
changed = true;
|
|
35 |
}
|
|
36 |
return removed;
|
58020
|
37 |
}
|
|
38 |
|
58129
|
39 |
public synchronized void addEventAction(String name, Consumer<RecordedEvent> consumer) {
|
|
40 |
eventActions.add(new EventDispatcher(name, consumer));
|
|
41 |
changed = true;
|
58020
|
42 |
}
|
|
43 |
|
58129
|
44 |
public void addEventAction(Consumer<RecordedEvent> action) {
|
|
45 |
addEventAction(null, action);
|
58020
|
46 |
}
|
|
47 |
|
58129
|
48 |
public synchronized void addFlushAction(Runnable action) {
|
|
49 |
flushActions.add(action);
|
|
50 |
changed = true;
|
58020
|
51 |
}
|
|
52 |
|
58129
|
53 |
public synchronized void addCloseAction(Runnable action) {
|
|
54 |
closeActions.add(action);
|
|
55 |
changed = true;
|
58020
|
56 |
}
|
|
57 |
|
58129
|
58 |
public synchronized void addErrorAction(Consumer<Throwable> action) {
|
|
59 |
errorActions.add(action);
|
|
60 |
changed = true;
|
58020
|
61 |
}
|
|
62 |
|
58129
|
63 |
public synchronized void setReuse(boolean reuse) {
|
|
64 |
this.reuse = reuse;
|
|
65 |
changed = true;
|
58020
|
66 |
}
|
|
67 |
|
58129
|
68 |
public synchronized void setOrdered(boolean ordered) {
|
|
69 |
this.ordered = ordered;
|
|
70 |
changed = true;
|
58020
|
71 |
}
|
|
72 |
|
58129
|
73 |
public synchronized void setEndTime(Instant endTime) {
|
58020
|
74 |
this.endTime = endTime;
|
|
75 |
this.endNanos = Utils.timeToNanos(endTime);
|
58129
|
76 |
changed = true;
|
58020
|
77 |
}
|
|
78 |
|
58129
|
79 |
public synchronized void setStartTime(Instant startTime) {
|
58020
|
80 |
this.startTime = startTime;
|
|
81 |
this.startNanos = Utils.timeToNanos(startTime);
|
58129
|
82 |
changed = true;
|
58020
|
83 |
}
|
|
84 |
|
58129
|
85 |
public synchronized void setStartNanos(long startNanos) {
|
|
86 |
this.startNanos = startNanos;
|
|
87 |
changed = true;
|
58020
|
88 |
}
|
|
89 |
|
58129
|
90 |
public synchronized void setStarted(boolean started) {
|
58020
|
91 |
this.started = started;
|
58129
|
92 |
changed = true;
|
58020
|
93 |
}
|
|
94 |
|
|
95 |
public boolean hasChanged() {
|
58129
|
96 |
return changed;
|
58020
|
97 |
}
|
|
98 |
|
58129
|
99 |
public synchronized void clearChanged() {
|
|
100 |
changed = false;
|
58020
|
101 |
}
|
|
102 |
} |