author | dfuchs |
Wed, 27 Apr 2016 18:04:16 +0200 | |
changeset 37672 | 03684934dc09 |
parent 36237 | 963d1115678b |
child 39634 | 812020bcb9f1 |
permissions | -rw-r--r-- |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1 |
/* |
36237
963d1115678b
8150998: Fix module dependences in java/lang tests
shurailine
parents:
33875
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
4 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
8 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
14 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
18 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
22 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
23 |
import java.security.AccessControlException; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
24 |
import java.security.CodeSource; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
25 |
import java.security.Permission; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
26 |
import java.security.PermissionCollection; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
27 |
import java.security.Permissions; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
28 |
import java.security.Policy; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
29 |
import java.security.ProtectionDomain; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
30 |
import java.util.Arrays; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
31 |
import java.util.Collections; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
32 |
import java.util.Enumeration; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
33 |
import java.util.HashMap; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
34 |
import java.util.Map; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
35 |
import java.util.Objects; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
36 |
import java.util.Queue; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
37 |
import java.util.ResourceBundle; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
38 |
import java.util.concurrent.ArrayBlockingQueue; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
39 |
import java.util.concurrent.ConcurrentHashMap; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
40 |
import java.util.concurrent.atomic.AtomicBoolean; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
41 |
import java.util.concurrent.atomic.AtomicLong; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
42 |
import java.util.function.Supplier; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
43 |
import java.util.logging.Handler; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
44 |
import java.util.logging.LogRecord; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
45 |
import java.lang.System.LoggerFinder; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
46 |
import java.lang.System.Logger; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
47 |
import java.lang.System.Logger.Level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
48 |
import java.util.stream.Stream; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
49 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
50 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
51 |
* @test |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
52 |
* @bug 8140364 |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
53 |
* @summary Tests the default implementation of System.Logger, when |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
54 |
* JUL is the default backend. |
36237
963d1115678b
8150998: Fix module dependences in java/lang tests
shurailine
parents:
33875
diff
changeset
|
55 |
* @modules java.logging |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
56 |
* @build AccessSystemLogger DefaultLoggerFinderTest |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
57 |
* @run driver AccessSystemLogger |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
58 |
* @run main/othervm -Xbootclasspath/a:boot DefaultLoggerFinderTest NOSECURITY |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
59 |
* @run main/othervm -Xbootclasspath/a:boot DefaultLoggerFinderTest NOPERMISSIONS |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
60 |
* @run main/othervm -Xbootclasspath/a:boot DefaultLoggerFinderTest WITHPERMISSIONS |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
61 |
* @author danielfuchs |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
62 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
63 |
public class DefaultLoggerFinderTest { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
64 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
65 |
static final RuntimePermission LOGGERFINDER_PERMISSION = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
66 |
new RuntimePermission("loggerFinder"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
67 |
final static AtomicLong sequencer = new AtomicLong(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
68 |
final static boolean VERBOSE = false; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
69 |
static final ThreadLocal<AtomicBoolean> allowControl = new ThreadLocal<AtomicBoolean>() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
70 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
71 |
protected AtomicBoolean initialValue() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
72 |
return new AtomicBoolean(false); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
73 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
74 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
75 |
static final ThreadLocal<AtomicBoolean> allowAll = new ThreadLocal<AtomicBoolean>() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
76 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
77 |
protected AtomicBoolean initialValue() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
78 |
return new AtomicBoolean(false); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
79 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
80 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
81 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
82 |
static final AccessSystemLogger accessSystemLogger = new AccessSystemLogger(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
83 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
84 |
public static final Queue<LogEvent> eventQueue = new ArrayBlockingQueue<>(128); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
85 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
86 |
public static final class LogEvent { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
87 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
88 |
public LogEvent() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
89 |
this(sequencer.getAndIncrement()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
90 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
91 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
92 |
LogEvent(long sequenceNumber) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
93 |
this.sequenceNumber = sequenceNumber; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
94 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
95 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
96 |
long sequenceNumber; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
97 |
boolean isLoggable; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
98 |
String loggerName; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
99 |
java.util.logging.Level level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
100 |
ResourceBundle bundle; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
101 |
Throwable thrown; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
102 |
Object[] args; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
103 |
String msg; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
104 |
String className; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
105 |
String methodName; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
106 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
107 |
Object[] toArray() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
108 |
return new Object[] { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
109 |
sequenceNumber, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
110 |
isLoggable, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
111 |
loggerName, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
112 |
level, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
113 |
bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
114 |
thrown, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
115 |
args, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
116 |
msg, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
117 |
className, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
118 |
methodName, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
119 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
120 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
121 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
122 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
123 |
public String toString() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
124 |
return Arrays.deepToString(toArray()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
125 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
126 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
127 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
128 |
public boolean equals(Object obj) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
129 |
return obj instanceof LogEvent |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
130 |
&& Objects.deepEquals(this.toArray(), ((LogEvent)obj).toArray()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
131 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
132 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
133 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
134 |
public int hashCode() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
135 |
return Objects.hash(toArray()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
136 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
137 |
public static LogEvent of(long sequenceNumber, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
138 |
boolean isLoggable, String name, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
139 |
java.util.logging.Level level, ResourceBundle bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
140 |
String key, Throwable thrown, Object... params) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
141 |
return LogEvent.of(sequenceNumber, isLoggable, name, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
142 |
DefaultLoggerFinderTest.class.getName(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
143 |
"testLogger", level, bundle, key, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
144 |
thrown, params); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
145 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
146 |
public static LogEvent of(long sequenceNumber, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
147 |
boolean isLoggable, String name, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
148 |
String className, String methodName, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
149 |
java.util.logging.Level level, ResourceBundle bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
150 |
String key, Throwable thrown, Object... params) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
151 |
LogEvent evt = new LogEvent(sequenceNumber); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
152 |
evt.loggerName = name; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
153 |
evt.level = level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
154 |
evt.args = params; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
155 |
evt.bundle = bundle; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
156 |
evt.thrown = thrown; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
157 |
evt.msg = key; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
158 |
evt.isLoggable = isLoggable; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
159 |
evt.className = className; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
160 |
evt.methodName = methodName; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
161 |
return evt; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
162 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
163 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
164 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
165 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
166 |
static java.util.logging.Level mapToJul(Level level) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
167 |
switch (level) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
168 |
case ALL: return java.util.logging.Level.ALL; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
169 |
case TRACE: return java.util.logging.Level.FINER; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
170 |
case DEBUG: return java.util.logging.Level.FINE; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
171 |
case INFO: return java.util.logging.Level.INFO; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
172 |
case WARNING: return java.util.logging.Level.WARNING; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
173 |
case ERROR: return java.util.logging.Level.SEVERE; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
174 |
case OFF: return java.util.logging.Level.OFF; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
175 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
176 |
throw new InternalError("No such level: " + level); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
177 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
178 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
179 |
static final java.util.logging.Level[] julLevels = { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
180 |
java.util.logging.Level.ALL, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
181 |
new java.util.logging.Level("FINER_THAN_FINEST", java.util.logging.Level.FINEST.intValue() - 10) {}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
182 |
java.util.logging.Level.FINEST, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
183 |
new java.util.logging.Level("FINER_THAN_FINER", java.util.logging.Level.FINER.intValue() - 10) {}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
184 |
java.util.logging.Level.FINER, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
185 |
new java.util.logging.Level("FINER_THAN_FINE", java.util.logging.Level.FINE.intValue() - 10) {}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
186 |
java.util.logging.Level.FINE, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
187 |
new java.util.logging.Level("FINER_THAN_CONFIG", java.util.logging.Level.FINE.intValue() + 10) {}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
188 |
java.util.logging.Level.CONFIG, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
189 |
new java.util.logging.Level("FINER_THAN_INFO", java.util.logging.Level.INFO.intValue() - 10) {}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
190 |
java.util.logging.Level.INFO, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
191 |
new java.util.logging.Level("FINER_THAN_WARNING", java.util.logging.Level.INFO.intValue() + 10) {}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
192 |
java.util.logging.Level.WARNING, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
193 |
new java.util.logging.Level("FINER_THAN_SEVERE", java.util.logging.Level.SEVERE.intValue() - 10) {}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
194 |
java.util.logging.Level.SEVERE, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
195 |
new java.util.logging.Level("FATAL", java.util.logging.Level.SEVERE.intValue() + 10) {}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
196 |
java.util.logging.Level.OFF, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
197 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
198 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
199 |
static final Level[] mappedLevels = { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
200 |
Level.ALL, // ALL |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
201 |
Level.DEBUG, // FINER_THAN_FINEST |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
202 |
Level.DEBUG, // FINEST |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
203 |
Level.DEBUG, // FINER_THAN_FINER |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
204 |
Level.TRACE, // FINER |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
205 |
Level.TRACE, // FINER_THAN_FINE |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
206 |
Level.DEBUG, // FINE |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
207 |
Level.DEBUG, // FINER_THAN_CONFIG |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
208 |
Level.DEBUG, // CONFIG |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
209 |
Level.DEBUG, // FINER_THAN_INFO |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
210 |
Level.INFO, // INFO |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
211 |
Level.INFO, // FINER_THAN_WARNING |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
212 |
Level.WARNING, // WARNING |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
213 |
Level.WARNING, // FINER_THAN_SEVERE |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
214 |
Level.ERROR, // SEVERE |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
215 |
Level.ERROR, // FATAL |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
216 |
Level.OFF, // OFF |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
217 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
218 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
219 |
final static Map<java.util.logging.Level, Level> julToSpiMap; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
220 |
static { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
221 |
Map<java.util.logging.Level, Level> map = new HashMap<>(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
222 |
if (mappedLevels.length != julLevels.length) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
223 |
throw new ExceptionInInitializerError("Array lengths differ" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
224 |
+ "\n\tjulLevels=" + Arrays.deepToString(julLevels) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
225 |
+ "\n\tmappedLevels=" + Arrays.deepToString(mappedLevels)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
226 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
227 |
for (int i=0; i<julLevels.length; i++) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
228 |
map.put(julLevels[i], mappedLevels[i]); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
229 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
230 |
julToSpiMap = Collections.unmodifiableMap(map); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
231 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
232 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
233 |
public static class MyBundle extends ResourceBundle { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
234 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
235 |
final ConcurrentHashMap<String,String> map = new ConcurrentHashMap<>(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
236 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
237 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
238 |
protected Object handleGetObject(String key) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
239 |
if (key.contains(" (translated)")) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
240 |
throw new RuntimeException("Unexpected key: " + key); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
241 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
242 |
return map.computeIfAbsent(key, k -> k + " (translated)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
243 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
244 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
245 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
246 |
public Enumeration<String> getKeys() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
247 |
return Collections.enumeration(map.keySet()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
248 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
249 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
250 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
251 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
252 |
public static class MyHandler extends Handler { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
253 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
254 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
255 |
public java.util.logging.Level getLevel() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
256 |
return java.util.logging.Level.ALL; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
257 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
258 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
259 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
260 |
public void publish(LogRecord record) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
261 |
eventQueue.add(LogEvent.of(sequencer.getAndIncrement(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
262 |
true, record.getLoggerName(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
263 |
record.getSourceClassName(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
264 |
record.getSourceMethodName(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
265 |
record.getLevel(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
266 |
record.getResourceBundle(), record.getMessage(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
267 |
record.getThrown(), record.getParameters())); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
268 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
269 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
270 |
public void flush() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
271 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
272 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
273 |
public void close() throws SecurityException { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
274 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
275 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
276 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
277 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
278 |
public static class MyLoggerBundle extends MyBundle { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
279 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
280 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
281 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
282 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
283 |
static enum TestCases {NOSECURITY, NOPERMISSIONS, WITHPERMISSIONS}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
284 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
285 |
static void setSecurityManager() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
286 |
if (System.getSecurityManager() == null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
287 |
Policy.setPolicy(new SimplePolicy(allowAll, allowControl)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
288 |
System.setSecurityManager(new SecurityManager()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
289 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
290 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
291 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
292 |
public static void main(String[] args) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
293 |
if (args.length == 0) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
294 |
args = new String[] { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
295 |
"NOSECURITY", |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
296 |
"NOPERMISSIONS", |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
297 |
"WITHPERMISSIONS" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
298 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
299 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
300 |
final java.util.logging.Logger appSink = java.util.logging.Logger.getLogger("foo"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
301 |
final java.util.logging.Logger sysSink = accessSystemLogger.demandSystemLogger("foo"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
302 |
appSink.addHandler(new MyHandler()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
303 |
sysSink.addHandler(new MyHandler()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
304 |
appSink.setUseParentHandlers(VERBOSE); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
305 |
sysSink.setUseParentHandlers(VERBOSE); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
306 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
307 |
Stream.of(args).map(TestCases::valueOf).forEach((testCase) -> { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
308 |
LoggerFinder provider; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
309 |
switch (testCase) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
310 |
case NOSECURITY: |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
311 |
System.out.println("\n*** Without Security Manager\n"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
312 |
provider = LoggerFinder.getLoggerFinder(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
313 |
test(provider, true, appSink, sysSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
314 |
System.out.println("Tetscase count: " + sequencer.get()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
315 |
break; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
316 |
case NOPERMISSIONS: |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
317 |
System.out.println("\n*** With Security Manager, without permissions\n"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
318 |
setSecurityManager(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
319 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
320 |
provider = LoggerFinder.getLoggerFinder(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
321 |
throw new RuntimeException("Expected exception not raised"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
322 |
} catch (AccessControlException x) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
323 |
if (!LOGGERFINDER_PERMISSION.equals(x.getPermission())) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
324 |
throw new RuntimeException("Unexpected permission check", x); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
325 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
326 |
final boolean control = allowControl.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
327 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
328 |
allowControl.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
329 |
provider = LoggerFinder.getLoggerFinder(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
330 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
331 |
allowControl.get().set(control); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
332 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
333 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
334 |
test(provider, false, appSink, sysSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
335 |
System.out.println("Tetscase count: " + sequencer.get()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
336 |
break; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
337 |
case WITHPERMISSIONS: |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
338 |
System.out.println("\n*** With Security Manager, with control permission\n"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
339 |
setSecurityManager(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
340 |
final boolean control = allowControl.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
341 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
342 |
allowControl.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
343 |
provider = LoggerFinder.getLoggerFinder(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
344 |
test(provider, true, appSink, sysSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
345 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
346 |
allowControl.get().set(control); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
347 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
348 |
break; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
349 |
default: |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
350 |
throw new RuntimeException("Unknown test case: " + testCase); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
351 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
352 |
}); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
353 |
System.out.println("\nPASSED: Tested " + sequencer.get() + " cases."); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
354 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
355 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
356 |
public static void test(LoggerFinder provider, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
357 |
boolean hasRequiredPermissions, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
358 |
java.util.logging.Logger appSink, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
359 |
java.util.logging.Logger sysSink) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
360 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
361 |
ResourceBundle loggerBundle = ResourceBundle.getBundle(MyLoggerBundle.class.getName()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
362 |
final Map<Logger, String> loggerDescMap = new HashMap<>(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
363 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
364 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
365 |
Logger appLogger1 = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
366 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
367 |
appLogger1 = provider.getLogger("foo", DefaultLoggerFinderTest.class.getModule()); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
368 |
loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", DefaultLoggerFinderTest.class.getModule())"); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
369 |
if (!hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
370 |
throw new RuntimeException("Managed to obtain a logger without permission"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
371 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
372 |
} catch (AccessControlException acx) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
373 |
if (hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
374 |
throw new RuntimeException("Unexpected security exception: ", acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
375 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
376 |
if (!acx.getPermission().equals(LOGGERFINDER_PERMISSION)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
377 |
throw new RuntimeException("Unexpected permission in exception: " + acx, acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
378 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
379 |
System.out.println("Got expected exception for logger: " + acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
380 |
boolean old = allowControl.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
381 |
allowControl.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
382 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
383 |
appLogger1 =provider.getLogger("foo", DefaultLoggerFinderTest.class.getModule()); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
384 |
loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", DefaultLoggerFinderTest.class.getModule())"); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
385 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
386 |
allowControl.get().set(old); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
387 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
388 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
389 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
390 |
Logger sysLogger1 = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
391 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
392 |
sysLogger1 = provider.getLogger("foo", Thread.class.getModule()); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
393 |
loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class.getModule())"); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
394 |
if (!hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
395 |
throw new RuntimeException("Managed to obtain a system logger without permission"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
396 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
397 |
} catch (AccessControlException acx) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
398 |
if (hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
399 |
throw new RuntimeException("Unexpected security exception: ", acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
400 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
401 |
if (!acx.getPermission().equals(LOGGERFINDER_PERMISSION)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
402 |
throw new RuntimeException("Unexpected permission in exception: " + acx, acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
403 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
404 |
System.out.println("Got expected exception for system logger: " + acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
405 |
boolean old = allowControl.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
406 |
allowControl.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
407 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
408 |
sysLogger1 = provider.getLogger("foo", Thread.class.getModule()); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
409 |
loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class.getModule())"); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
410 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
411 |
allowControl.get().set(old); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
412 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
413 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
414 |
if (appLogger1 == sysLogger1) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
415 |
throw new RuntimeException("identical loggers"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
416 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
417 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
418 |
Logger appLogger2 = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
419 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
420 |
appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, DefaultLoggerFinderTest.class.getModule()); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
421 |
loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, DefaultLoggerFinderTest.class.getModule())"); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
422 |
if (!hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
423 |
throw new RuntimeException("Managed to obtain a logger without permission"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
424 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
425 |
} catch (AccessControlException acx) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
426 |
if (hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
427 |
throw new RuntimeException("Unexpected security exception: ", acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
428 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
429 |
if (!acx.getPermission().equals(LOGGERFINDER_PERMISSION)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
430 |
throw new RuntimeException("Unexpected permission in exception: " + acx, acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
431 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
432 |
System.out.println("Got expected exception for logger: " + acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
433 |
boolean old = allowControl.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
434 |
allowControl.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
435 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
436 |
appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, DefaultLoggerFinderTest.class.getModule()); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
437 |
loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, DefaultLoggerFinderTest.class.getModule())"); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
438 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
439 |
allowControl.get().set(old); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
440 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
441 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
442 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
443 |
Logger sysLogger2 = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
444 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
445 |
sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule()); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
446 |
loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule())"); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
447 |
if (!hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
448 |
throw new RuntimeException("Managed to obtain a system logger without permission"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
449 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
450 |
} catch (AccessControlException acx) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
451 |
if (hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
452 |
throw new RuntimeException("Unexpected security exception: ", acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
453 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
454 |
if (!acx.getPermission().equals(LOGGERFINDER_PERMISSION)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
455 |
throw new RuntimeException("Unexpected permission in exception: " + acx, acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
456 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
457 |
System.out.println("Got expected exception for localized system logger: " + acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
458 |
boolean old = allowControl.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
459 |
allowControl.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
460 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
461 |
sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule()); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
36237
diff
changeset
|
462 |
loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule())"); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
463 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
464 |
allowControl.get().set(old); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
465 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
466 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
467 |
if (appLogger2 == sysLogger2) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
468 |
throw new RuntimeException("identical loggers"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
469 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
470 |
if (appLogger2 == appLogger1) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
471 |
throw new RuntimeException("identical loggers"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
472 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
473 |
if (sysLogger2 == sysLogger1) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
474 |
throw new RuntimeException("identical loggers"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
475 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
476 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
477 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
478 |
testLogger(provider, loggerDescMap, "foo", null, appLogger1, appSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
479 |
testLogger(provider, loggerDescMap, "foo", null, sysLogger1, sysSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
480 |
testLogger(provider, loggerDescMap, "foo", loggerBundle, appLogger2, appSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
481 |
testLogger(provider, loggerDescMap, "foo", loggerBundle, sysLogger2, sysSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
482 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
483 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
484 |
Logger appLogger3 = System.getLogger("foo"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
485 |
loggerDescMap.put(appLogger3, "System.getLogger(\"foo\")"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
486 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
487 |
testLogger(provider, loggerDescMap, "foo", null, appLogger3, appSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
488 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
489 |
Logger appLogger4 = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
490 |
System.getLogger("foo", loggerBundle); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
491 |
loggerDescMap.put(appLogger4, "System.getLogger(\"foo\", loggerBundle)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
492 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
493 |
if (appLogger4 == appLogger1) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
494 |
throw new RuntimeException("identical loggers"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
495 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
496 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
497 |
testLogger(provider, loggerDescMap, "foo", loggerBundle, appLogger4, appSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
498 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
499 |
Logger sysLogger3 = accessSystemLogger.getLogger("foo"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
500 |
loggerDescMap.put(sysLogger3, "AccessSystemLogger.getLogger(\"foo\")"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
501 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
502 |
testLogger(provider, loggerDescMap, "foo", null, sysLogger3, sysSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
503 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
504 |
Logger sysLogger4 = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
505 |
accessSystemLogger.getLogger("foo", loggerBundle); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
506 |
loggerDescMap.put(appLogger4, "AccessSystemLogger.getLogger(\"foo\", loggerBundle)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
507 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
508 |
if (sysLogger4 == sysLogger1) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
509 |
throw new RuntimeException("identical loggers"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
510 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
511 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
512 |
testLogger(provider, loggerDescMap, "foo", loggerBundle, sysLogger4, sysSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
513 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
514 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
515 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
516 |
public static class Foo { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
517 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
518 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
519 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
520 |
static void verbose(String msg) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
521 |
if (VERBOSE) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
522 |
System.out.println(msg); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
523 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
524 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
525 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
526 |
static void setLevel(java.util.logging.Logger sink, java.util.logging.Level loggerLevel) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
527 |
boolean before = allowAll.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
528 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
529 |
allowAll.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
530 |
sink.setLevel(loggerLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
531 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
532 |
allowAll.get().set(before); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
533 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
534 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
535 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
536 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
537 |
// Calls the 8 methods defined on Logger and verify the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
538 |
// parameters received by the underlying Logger Impl |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
539 |
// logger. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
540 |
private static void testLogger(LoggerFinder provider, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
541 |
Map<Logger, String> loggerDescMap, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
542 |
String name, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
543 |
ResourceBundle loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
544 |
Logger logger, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
545 |
java.util.logging.Logger sink) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
546 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
547 |
System.out.println("Testing " + loggerDescMap.get(logger) + " [" + logger + "]"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
548 |
final java.util.logging.Level OFF = java.util.logging.Level.OFF; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
549 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
550 |
Foo foo = new Foo(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
551 |
String fooMsg = foo.toString(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
552 |
for (java.util.logging.Level loggerLevel : julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
553 |
setLevel(sink, loggerLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
554 |
for (Level messageLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
555 |
java.util.logging.Level julLevel = mapToJul(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
556 |
String desc = "logger.log(messageLevel, foo): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
557 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
558 |
LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
559 |
LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
560 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
561 |
julLevel.intValue() >= loggerLevel.intValue(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
562 |
name, julLevel, (ResourceBundle)null, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
563 |
fooMsg, (Throwable)null, (Object[])null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
564 |
logger.log(messageLevel, foo); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
565 |
if (loggerLevel == OFF || julLevel.intValue() < loggerLevel.intValue()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
566 |
if (eventQueue.poll() != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
567 |
throw new RuntimeException("unexpected event in queue for " + desc); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
568 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
569 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
570 |
LogEvent actual = eventQueue.poll(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
571 |
if (!expected.equals(actual)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
572 |
throw new RuntimeException("mismatch for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
573 |
+ "\n\texpected=" + expected |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
574 |
+ "\n\t actual=" + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
575 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
576 |
verbose("Got expected results for " |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
577 |
+ desc + "\n\t" + expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
578 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
579 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
580 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
581 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
582 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
583 |
String msg = "blah"; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
584 |
for (java.util.logging.Level loggerLevel : julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
585 |
setLevel(sink, loggerLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
586 |
for (Level messageLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
587 |
java.util.logging.Level julLevel = mapToJul(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
588 |
String desc = "logger.log(messageLevel, \"blah\"): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
589 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
590 |
LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
591 |
LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
592 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
593 |
julLevel.intValue() >= loggerLevel.intValue(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
594 |
name, julLevel, loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
595 |
msg, (Throwable)null, (Object[])null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
596 |
logger.log(messageLevel, msg); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
597 |
if (loggerLevel == OFF || julLevel.intValue() < loggerLevel.intValue()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
598 |
if (eventQueue.poll() != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
599 |
throw new RuntimeException("unexpected event in queue for " + desc); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
600 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
601 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
602 |
LogEvent actual = eventQueue.poll(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
603 |
if (!expected.equals(actual)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
604 |
throw new RuntimeException("mismatch for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
605 |
+ "\n\texpected=" + expected |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
606 |
+ "\n\t actual=" + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
607 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
608 |
verbose("Got expected results for " |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
609 |
+ desc + "\n\t" + expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
610 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
611 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
612 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
613 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
614 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
615 |
Supplier<String> fooSupplier = new Supplier<String>() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
616 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
617 |
public String get() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
618 |
return this.toString(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
619 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
620 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
621 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
622 |
for (java.util.logging.Level loggerLevel : julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
623 |
setLevel(sink, loggerLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
624 |
for (Level messageLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
625 |
java.util.logging.Level julLevel = mapToJul(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
626 |
String desc = "logger.log(messageLevel, fooSupplier): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
627 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
628 |
LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
629 |
LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
630 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
631 |
julLevel.intValue() >= loggerLevel.intValue(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
632 |
name, julLevel, (ResourceBundle)null, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
633 |
fooSupplier.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
634 |
(Throwable)null, (Object[])null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
635 |
logger.log(messageLevel, fooSupplier); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
636 |
if (loggerLevel == OFF || julLevel.intValue() < loggerLevel.intValue()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
637 |
if (eventQueue.poll() != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
638 |
throw new RuntimeException("unexpected event in queue for " + desc); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
639 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
640 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
641 |
LogEvent actual = eventQueue.poll(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
642 |
if (!expected.equals(actual)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
643 |
throw new RuntimeException("mismatch for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
644 |
+ "\n\texpected=" + expected |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
645 |
+ "\n\t actual=" + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
646 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
647 |
verbose("Got expected results for " |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
648 |
+ desc + "\n\t" + expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
649 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
650 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
651 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
652 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
653 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
654 |
String format = "two params [{1} {2}]"; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
655 |
Object arg1 = foo; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
656 |
Object arg2 = msg; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
657 |
for (java.util.logging.Level loggerLevel : julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
658 |
setLevel(sink, loggerLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
659 |
for (Level messageLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
660 |
java.util.logging.Level julLevel = mapToJul(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
661 |
String desc = "logger.log(messageLevel, format, params...): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
662 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
663 |
LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
664 |
LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
665 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
666 |
julLevel.intValue() >= loggerLevel.intValue(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
667 |
name, julLevel, loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
668 |
format, (Throwable)null, new Object[] {arg1, arg2}); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
669 |
logger.log(messageLevel, format, arg1, arg2); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
670 |
if (loggerLevel == OFF || julLevel.intValue() < loggerLevel.intValue()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
671 |
if (eventQueue.poll() != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
672 |
throw new RuntimeException("unexpected event in queue for " + desc); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
673 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
674 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
675 |
LogEvent actual = eventQueue.poll(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
676 |
if (!expected.equals(actual)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
677 |
throw new RuntimeException("mismatch for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
678 |
+ "\n\texpected=" + expected |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
679 |
+ "\n\t actual=" + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
680 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
681 |
verbose("Got expected results for " |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
682 |
+ desc + "\n\t" + expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
683 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
684 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
685 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
686 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
687 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
688 |
Throwable thrown = new Exception("OK: log me!"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
689 |
for (java.util.logging.Level loggerLevel : julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
690 |
setLevel(sink, loggerLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
691 |
for (Level messageLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
692 |
java.util.logging.Level julLevel = mapToJul(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
693 |
String desc = "logger.log(messageLevel, \"blah\", thrown): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
694 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
695 |
LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
696 |
LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
697 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
698 |
julLevel.intValue() >= loggerLevel.intValue(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
699 |
name, julLevel, loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
700 |
msg, thrown, (Object[]) null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
701 |
logger.log(messageLevel, msg, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
702 |
if (loggerLevel == OFF || julLevel.intValue() < loggerLevel.intValue()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
703 |
if (eventQueue.poll() != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
704 |
throw new RuntimeException("unexpected event in queue for " + desc); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
705 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
706 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
707 |
LogEvent actual = eventQueue.poll(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
708 |
if (!expected.equals(actual)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
709 |
throw new RuntimeException("mismatch for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
710 |
+ "\n\texpected=" + expected |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
711 |
+ "\n\t actual=" + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
712 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
713 |
verbose("Got expected results for " |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
714 |
+ desc + "\n\t" + expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
715 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
716 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
717 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
718 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
719 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
720 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
721 |
for (java.util.logging.Level loggerLevel : julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
722 |
setLevel(sink, loggerLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
723 |
for (Level messageLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
724 |
java.util.logging.Level julLevel = mapToJul(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
725 |
String desc = "logger.log(messageLevel, thrown, fooSupplier): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
726 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
727 |
LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
728 |
LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
729 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
730 |
julLevel.intValue() >= loggerLevel.intValue(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
731 |
name, julLevel, (ResourceBundle)null, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
732 |
fooSupplier.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
733 |
(Throwable)thrown, (Object[])null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
734 |
logger.log(messageLevel, fooSupplier, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
735 |
if (loggerLevel == OFF || julLevel.intValue() < loggerLevel.intValue()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
736 |
if (eventQueue.poll() != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
737 |
throw new RuntimeException("unexpected event in queue for " + desc); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
738 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
739 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
740 |
LogEvent actual = eventQueue.poll(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
741 |
if (!expected.equals(actual)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
742 |
throw new RuntimeException("mismatch for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
743 |
+ "\n\texpected=" + expected |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
744 |
+ "\n\t actual=" + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
745 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
746 |
verbose("Got expected results for " |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
747 |
+ desc + "\n\t" + expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
748 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
749 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
750 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
751 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
752 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
753 |
ResourceBundle bundle = ResourceBundle.getBundle(MyBundle.class.getName()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
754 |
for (java.util.logging.Level loggerLevel : julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
755 |
setLevel(sink, loggerLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
756 |
for (Level messageLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
757 |
java.util.logging.Level julLevel = mapToJul(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
758 |
String desc = "logger.log(messageLevel, bundle, format, params...): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
759 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
760 |
LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
761 |
LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
762 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
763 |
julLevel.intValue() >= loggerLevel.intValue(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
764 |
name, julLevel, bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
765 |
format, (Throwable)null, new Object[] {foo, msg}); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
766 |
logger.log(messageLevel, bundle, format, foo, msg); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
767 |
if (loggerLevel == OFF || julLevel.intValue() < loggerLevel.intValue()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
768 |
if (eventQueue.poll() != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
769 |
throw new RuntimeException("unexpected event in queue for " + desc); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
770 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
771 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
772 |
LogEvent actual = eventQueue.poll(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
773 |
if (!expected.equals(actual)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
774 |
throw new RuntimeException("mismatch for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
775 |
+ "\n\texpected=" + expected |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
776 |
+ "\n\t actual=" + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
777 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
778 |
verbose("Got expected results for " |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
779 |
+ desc + "\n\t" + expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
780 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
781 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
782 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
783 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
784 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
785 |
for (java.util.logging.Level loggerLevel : julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
786 |
setLevel(sink, loggerLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
787 |
for (Level messageLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
788 |
java.util.logging.Level julLevel = mapToJul(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
789 |
String desc = "logger.log(messageLevel, bundle, \"blah\", thrown): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
790 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
791 |
LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
792 |
LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
793 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
794 |
julLevel.intValue() >= loggerLevel.intValue(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
795 |
name, julLevel, bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
796 |
msg, thrown, (Object[]) null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
797 |
logger.log(messageLevel, bundle, msg, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
798 |
if (loggerLevel == OFF || julLevel.intValue() < loggerLevel.intValue()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
799 |
if (eventQueue.poll() != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
800 |
throw new RuntimeException("unexpected event in queue for " + desc); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
801 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
802 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
803 |
LogEvent actual = eventQueue.poll(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
804 |
if (!expected.equals(actual)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
805 |
throw new RuntimeException("mismatch for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
806 |
+ "\n\texpected=" + expected |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
807 |
+ "\n\t actual=" + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
808 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
809 |
verbose("Got expected results for " |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
810 |
+ desc + "\n\t" + expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
811 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
812 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
813 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
814 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
815 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
816 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
817 |
final static class PermissionsBuilder { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
818 |
final Permissions perms; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
819 |
public PermissionsBuilder() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
820 |
this(new Permissions()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
821 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
822 |
public PermissionsBuilder(Permissions perms) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
823 |
this.perms = perms; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
824 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
825 |
public PermissionsBuilder add(Permission p) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
826 |
perms.add(p); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
827 |
return this; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
828 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
829 |
public PermissionsBuilder addAll(PermissionCollection col) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
830 |
if (col != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
831 |
for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
832 |
perms.add(e.nextElement()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
833 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
834 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
835 |
return this; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
836 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
837 |
public Permissions toPermissions() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
838 |
final PermissionsBuilder builder = new PermissionsBuilder(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
839 |
builder.addAll(perms); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
840 |
return builder.perms; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
841 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
842 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
843 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
844 |
public static class SimplePolicy extends Policy { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
845 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
846 |
final Permissions permissions; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
847 |
final Permissions withControlPermissions; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
848 |
final Permissions allPermissions; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
849 |
final ThreadLocal<AtomicBoolean> allowAll; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
850 |
final ThreadLocal<AtomicBoolean> allowControl; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
851 |
public SimplePolicy(ThreadLocal<AtomicBoolean> allowAll, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
852 |
ThreadLocal<AtomicBoolean> allowControl) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
853 |
this.allowAll = allowAll; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
854 |
this.allowControl = allowControl; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
855 |
permissions = new Permissions(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
856 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
857 |
withControlPermissions = new Permissions(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
858 |
withControlPermissions.add(LOGGERFINDER_PERMISSION); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
859 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
860 |
// these are used for configuring the test itself... |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
861 |
allPermissions = new Permissions(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
862 |
allPermissions.add(new java.security.AllPermission()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
863 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
864 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
865 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
866 |
public boolean implies(ProtectionDomain domain, Permission permission) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
867 |
if (allowAll.get().get()) return allPermissions.implies(permission); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
868 |
if (allowControl.get().get()) return withControlPermissions.implies(permission); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
869 |
return permissions.implies(permission); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
870 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
871 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
872 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
873 |
public PermissionCollection getPermissions(CodeSource codesource) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
874 |
return new PermissionsBuilder().addAll( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
875 |
allowAll.get().get() ? allPermissions : |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
876 |
allowControl.get().get() |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
877 |
? withControlPermissions : permissions).toPermissions(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
878 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
879 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
880 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
881 |
public PermissionCollection getPermissions(ProtectionDomain domain) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
882 |
return new PermissionsBuilder().addAll( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
883 |
allowAll.get().get() ? allPermissions : |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
884 |
allowControl.get().get() |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
885 |
? withControlPermissions : permissions).toPermissions(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
886 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
887 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
888 |
} |