author | mgronlun |
Wed, 18 Sep 2019 12:19:58 +0200 | |
branch | JEP-349-branch |
changeset 58207 | 704387b7f5b9 |
parent 58200 | 2d147d680311 |
permissions | -rw-r--r-- |
58200 | 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 |
||
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
26 |
package jdk.jfr.internal.consumer; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
27 |
|
58145
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
28 |
import java.time.Instant; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
29 |
import java.util.ArrayList; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
30 |
import java.util.List; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
31 |
import java.util.function.Consumer; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
32 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
33 |
import jdk.jfr.consumer.RecordedEvent; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
34 |
import jdk.jfr.internal.Utils; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
35 |
import jdk.jfr.internal.consumer.Dispatcher.EventDispatcher; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
36 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
37 |
final class StreamConfiguration { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
38 |
final List<Runnable> closeActions = new ArrayList<>(); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
39 |
final List<Runnable> flushActions = new ArrayList<>(); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
40 |
final List<EventDispatcher> eventActions = new ArrayList<>(); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
41 |
final List<Consumer<Throwable>> errorActions = new ArrayList<>(); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
42 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
43 |
boolean reuse = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
44 |
boolean ordered = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
45 |
Instant startTime = null; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
46 |
Instant endTime = null; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
47 |
boolean started = false; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
48 |
long startNanos = 0; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
49 |
long endNanos = Long.MAX_VALUE; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
50 |
|
58197 | 51 |
private volatile boolean changed = true; |
58145
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
52 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
53 |
public synchronized boolean remove(Object action) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
54 |
boolean removed = false; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
55 |
removed |= flushActions.removeIf(e -> e == action); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
56 |
removed |= closeActions.removeIf(e -> e == action); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
57 |
removed |= errorActions.removeIf(e -> e == action); |
58197 | 58 |
removed |= eventActions.removeIf(e -> e.getAction() == action); |
58145
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
59 |
if (removed) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
60 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
61 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
62 |
return removed; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
63 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
64 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
65 |
public synchronized void addEventAction(String name, Consumer<RecordedEvent> consumer) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
66 |
eventActions.add(new EventDispatcher(name, consumer)); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
67 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
68 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
69 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
70 |
public void addEventAction(Consumer<RecordedEvent> action) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
71 |
addEventAction(null, action); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
72 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
73 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
74 |
public synchronized void addFlushAction(Runnable action) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
75 |
flushActions.add(action); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
76 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
77 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
78 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
79 |
public synchronized void addCloseAction(Runnable action) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
80 |
closeActions.add(action); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
81 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
82 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
83 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
84 |
public synchronized void addErrorAction(Consumer<Throwable> action) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
85 |
errorActions.add(action); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
86 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
87 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
88 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
89 |
public synchronized void setReuse(boolean reuse) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
90 |
this.reuse = reuse; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
91 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
92 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
93 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
94 |
public synchronized void setOrdered(boolean ordered) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
95 |
this.ordered = ordered; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
96 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
97 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
98 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
99 |
public synchronized void setEndTime(Instant endTime) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
100 |
this.endTime = endTime; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
101 |
this.endNanos = Utils.timeToNanos(endTime); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
102 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
103 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
104 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
105 |
public synchronized void setStartTime(Instant startTime) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
106 |
this.startTime = startTime; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
107 |
this.startNanos = Utils.timeToNanos(startTime); |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
108 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
109 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
110 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
111 |
public synchronized void setStartNanos(long startNanos) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
112 |
this.startNanos = startNanos; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
113 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
114 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
115 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
116 |
public synchronized void setStarted(boolean started) { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
117 |
this.started = started; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
118 |
changed = true; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
119 |
} |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
120 |
|
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
121 |
public boolean hasChanged() { |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
122 |
return changed; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58112
diff
changeset
|
123 |
} |
58207 | 124 |
} |