58863
|
1 |
/*
|
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package jdk.jfr.internal.consumer;
|
|
27 |
|
|
28 |
import java.time.Instant;
|
|
29 |
import java.util.ArrayList;
|
|
30 |
import java.util.List;
|
|
31 |
import java.util.function.Consumer;
|
|
32 |
|
|
33 |
import jdk.jfr.consumer.RecordedEvent;
|
|
34 |
import jdk.jfr.internal.Utils;
|
|
35 |
import jdk.jfr.internal.consumer.Dispatcher.EventDispatcher;
|
|
36 |
|
|
37 |
final class StreamConfiguration {
|
|
38 |
final List<Runnable> closeActions = new ArrayList<>();
|
|
39 |
final List<Runnable> flushActions = new ArrayList<>();
|
|
40 |
final List<EventDispatcher> eventActions = new ArrayList<>();
|
|
41 |
final List<Consumer<Throwable>> errorActions = new ArrayList<>();
|
|
42 |
|
|
43 |
boolean reuse = true;
|
|
44 |
boolean ordered = true;
|
|
45 |
Instant startTime = null;
|
|
46 |
Instant endTime = null;
|
|
47 |
boolean started = false;
|
|
48 |
long startNanos = 0;
|
|
49 |
long endNanos = Long.MAX_VALUE;
|
|
50 |
|
|
51 |
private volatile boolean changed = true;
|
|
52 |
|
|
53 |
public synchronized boolean remove(Object action) {
|
|
54 |
boolean removed = false;
|
|
55 |
removed |= flushActions.removeIf(e -> e == action);
|
|
56 |
removed |= closeActions.removeIf(e -> e == action);
|
|
57 |
removed |= errorActions.removeIf(e -> e == action);
|
|
58 |
removed |= eventActions.removeIf(e -> e.getAction() == action);
|
|
59 |
if (removed) {
|
|
60 |
changed = true;
|
|
61 |
}
|
|
62 |
return removed;
|
|
63 |
}
|
|
64 |
|
|
65 |
public synchronized void addEventAction(String name, Consumer<RecordedEvent> consumer) {
|
|
66 |
eventActions.add(new EventDispatcher(name, consumer));
|
|
67 |
changed = true;
|
|
68 |
}
|
|
69 |
|
|
70 |
public void addEventAction(Consumer<RecordedEvent> action) {
|
|
71 |
addEventAction(null, action);
|
|
72 |
}
|
|
73 |
|
|
74 |
public synchronized void addFlushAction(Runnable action) {
|
|
75 |
flushActions.add(action);
|
|
76 |
changed = true;
|
|
77 |
}
|
|
78 |
|
|
79 |
public synchronized void addCloseAction(Runnable action) {
|
|
80 |
closeActions.add(action);
|
|
81 |
changed = true;
|
|
82 |
}
|
|
83 |
|
|
84 |
public synchronized void addErrorAction(Consumer<Throwable> action) {
|
|
85 |
errorActions.add(action);
|
|
86 |
changed = true;
|
|
87 |
}
|
|
88 |
|
|
89 |
public synchronized void setReuse(boolean reuse) {
|
|
90 |
this.reuse = reuse;
|
|
91 |
changed = true;
|
|
92 |
}
|
|
93 |
|
|
94 |
public synchronized void setOrdered(boolean ordered) {
|
|
95 |
this.ordered = ordered;
|
|
96 |
changed = true;
|
|
97 |
}
|
|
98 |
|
|
99 |
public synchronized void setEndTime(Instant endTime) {
|
|
100 |
this.endTime = endTime;
|
|
101 |
this.endNanos = Utils.timeToNanos(endTime);
|
|
102 |
changed = true;
|
|
103 |
}
|
|
104 |
|
|
105 |
public synchronized void setStartTime(Instant startTime) {
|
|
106 |
this.startTime = startTime;
|
|
107 |
this.startNanos = Utils.timeToNanos(startTime);
|
|
108 |
changed = true;
|
|
109 |
}
|
|
110 |
|
|
111 |
public synchronized void setStartNanos(long startNanos) {
|
|
112 |
this.startNanos = startNanos;
|
|
113 |
changed = true;
|
|
114 |
}
|
|
115 |
|
|
116 |
public synchronized void setStarted(boolean started) {
|
|
117 |
this.started = started;
|
|
118 |
changed = true;
|
|
119 |
}
|
|
120 |
|
|
121 |
public boolean hasChanged() {
|
|
122 |
return changed;
|
|
123 |
}
|
|
124 |
}
|