author | egahlin |
Mon, 16 Sep 2019 09:57:26 +0200 | |
branch | JEP-349-branch |
changeset 58146 | 9f3aadcaa430 |
parent 57921 | src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/InternalEventFilter.java@08327ab323c5 |
child 58180 | 0a8943b4d0dd |
permissions | -rw-r--r-- |
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
1 |
/* |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
4 |
* |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
10 |
* |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
15 |
* accompanied this code). |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
16 |
* |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
20 |
* |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
23 |
* questions. |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
24 |
*/ |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
25 |
|
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
26 |
package jdk.jfr.internal.consumer; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
27 |
|
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
28 |
import java.util.HashMap; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
29 |
import java.util.Map; |
57433 | 30 |
import java.util.StringJoiner; |
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
31 |
|
58146 | 32 |
public final class ParserFilter { |
33 |
public static final ParserFilter ACCEPT_ALL = new ParserFilter(true, Map.of()); |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
34 |
|
57433 | 35 |
private final Map<String, Long> thresholds; |
36 |
private final boolean acceptAll; |
|
37 |
||
58146 | 38 |
public ParserFilter() { |
57433 | 39 |
this(false, new HashMap<>()); |
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
40 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
41 |
|
58146 | 42 |
private ParserFilter(boolean acceptAll, Map<String, Long> thresholds) { |
57433 | 43 |
this.acceptAll = acceptAll; |
44 |
this.thresholds = thresholds; |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
45 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
46 |
|
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
47 |
public void setThreshold(String eventName, long nanos) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
48 |
Long l = thresholds.get(eventName); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
49 |
if (l != null) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
50 |
l = Math.min(l, nanos); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
51 |
} else { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
52 |
l = nanos; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
53 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
54 |
thresholds.put(eventName, l); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
55 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
56 |
|
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
57 |
public long getThreshold(String eventName) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
58 |
if (acceptAll) { |
57433 | 59 |
return 0L; |
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
60 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
61 |
Long l = thresholds.get(eventName); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
62 |
if (l != null) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
63 |
return l; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
64 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
65 |
return -1; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
66 |
} |
57433 | 67 |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
68 |
public String toString() { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
69 |
if (acceptAll) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
70 |
return "ACCEPT ALL"; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
71 |
} |
57433 | 72 |
|
73 |
StringJoiner sb = new StringJoiner(", "); |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
74 |
for (String key : thresholds.keySet().toArray(new String[0])) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
75 |
Long value = thresholds.get(key); |
57433 | 76 |
sb.add(key + " = " + value); |
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
77 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
78 |
return sb.toString(); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
79 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
diff
changeset
|
80 |
} |