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 |
|
8 import jdk.jfr.consumer.Dispatcher.EventDispatcher; |
|
9 import jdk.jfr.internal.Utils; |
|
10 |
|
11 final class StreamConfiguration { |
|
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<>(); |
|
16 |
|
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; |
|
24 |
|
25 volatile boolean changed = true; |
|
26 |
|
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; |
|
37 } |
|
38 |
|
39 public synchronized void addEventAction(String name, Consumer<RecordedEvent> consumer) { |
|
40 eventActions.add(new EventDispatcher(name, consumer)); |
|
41 changed = true; |
|
42 } |
|
43 |
|
44 public void addEventAction(Consumer<RecordedEvent> action) { |
|
45 addEventAction(null, action); |
|
46 } |
|
47 |
|
48 public synchronized void addFlushAction(Runnable action) { |
|
49 flushActions.add(action); |
|
50 changed = true; |
|
51 } |
|
52 |
|
53 public synchronized void addCloseAction(Runnable action) { |
|
54 closeActions.add(action); |
|
55 changed = true; |
|
56 } |
|
57 |
|
58 public synchronized void addErrorAction(Consumer<Throwable> action) { |
|
59 errorActions.add(action); |
|
60 changed = true; |
|
61 } |
|
62 |
|
63 public synchronized void setReuse(boolean reuse) { |
|
64 this.reuse = reuse; |
|
65 changed = true; |
|
66 } |
|
67 |
|
68 public synchronized void setOrdered(boolean ordered) { |
|
69 this.ordered = ordered; |
|
70 changed = true; |
|
71 } |
|
72 |
|
73 public synchronized void setEndTime(Instant endTime) { |
|
74 this.endTime = endTime; |
|
75 this.endNanos = Utils.timeToNanos(endTime); |
|
76 changed = true; |
|
77 } |
|
78 |
|
79 public synchronized void setStartTime(Instant startTime) { |
|
80 this.startTime = startTime; |
|
81 this.startNanos = Utils.timeToNanos(startTime); |
|
82 changed = true; |
|
83 } |
|
84 |
|
85 public synchronized void setStartNanos(long startNanos) { |
|
86 this.startNanos = startNanos; |
|
87 changed = true; |
|
88 } |
|
89 |
|
90 public synchronized void setStarted(boolean started) { |
|
91 this.started = started; |
|
92 changed = true; |
|
93 } |
|
94 |
|
95 public boolean hasChanged() { |
|
96 return changed; |
|
97 } |
|
98 |
|
99 public synchronized void clearChanged() { |
|
100 changed = false; |
|
101 } |
|
102 } |
|