author | mgronlun |
Mon, 28 Oct 2019 18:43:04 +0100 | |
branch | JEP-349-branch |
changeset 58823 | 6a21dba79b81 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
44858
7183899b064b
8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents:
32034
diff
changeset
|
2 |
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang.management; |
|
27 |
import javax.management.openmbean.CompositeData; |
|
28 |
import sun.management.MemoryNotifInfoCompositeData; |
|
29 |
||
30 |
/** |
|
31 |
* The information about a memory notification. |
|
32 |
* |
|
33 |
* <p> |
|
34 |
* A memory notification is emitted by {@link MemoryMXBean} |
|
35 |
* when the Java virtual machine detects that the memory usage |
|
36 |
* of a memory pool is exceeding a threshold value. |
|
37 |
* The notification emitted will contain the memory notification |
|
38 |
* information about the detected condition: |
|
39 |
* <ul> |
|
40 |
* <li>The name of the memory pool.</li> |
|
41 |
* <li>The memory usage of the memory pool when the notification |
|
42 |
* was constructed.</li> |
|
43 |
* <li>The number of times that the memory usage has crossed |
|
44 |
* a threshold when the notification was constructed. |
|
45 |
* For usage threshold notifications, this count will be the |
|
46 |
* {@link MemoryPoolMXBean#getUsageThresholdCount usage threshold |
|
47 |
* count}. For collection threshold notifications, |
|
48 |
* this count will be the |
|
49 |
* {@link MemoryPoolMXBean#getCollectionUsageThresholdCount |
|
50 |
* collection usage threshold count}. |
|
51 |
* </li> |
|
52 |
* </ul> |
|
53 |
* |
|
54 |
* <p> |
|
55 |
* A {@link CompositeData CompositeData} representing |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
56 |
* the {@code MemoryNotificationInfo} object |
2 | 57 |
* is stored in the |
58 |
* {@link javax.management.Notification#setUserData user data} |
|
59 |
* of a {@link javax.management.Notification notification}. |
|
60 |
* The {@link #from from} method is provided to convert from |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
61 |
* a {@code CompositeData} to a {@code MemoryNotificationInfo} |
2 | 62 |
* object. For example: |
63 |
* |
|
64 |
* <blockquote><pre> |
|
65 |
* Notification notif; |
|
66 |
* |
|
67 |
* // receive the notification emitted by MemoryMXBean and set to notif |
|
68 |
* ... |
|
69 |
* |
|
70 |
* String notifType = notif.getType(); |
|
71 |
* if (notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED) || |
|
72 |
* notifType.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) { |
|
73 |
* // retrieve the memory notification information |
|
74 |
* CompositeData cd = (CompositeData) notif.getUserData(); |
|
75 |
* MemoryNotificationInfo info = MemoryNotificationInfo.from(cd); |
|
76 |
* .... |
|
77 |
* } |
|
78 |
* </pre></blockquote> |
|
79 |
* |
|
80 |
* <p> |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
81 |
* The types of notifications emitted by {@code MemoryMXBean} are: |
2 | 82 |
* <ul> |
83 |
* <li>A {@link #MEMORY_THRESHOLD_EXCEEDED |
|
84 |
* usage threshold exceeded notification}. |
|
85 |
* <br>This notification will be emitted when |
|
86 |
* the memory usage of a memory pool is increased and has reached |
|
87 |
* or exceeded its |
|
88 |
* <a href="MemoryPoolMXBean.html#UsageThreshold"> usage threshold</a> value. |
|
89 |
* Subsequent crossing of the usage threshold value does not cause |
|
90 |
* further notification until the memory usage has returned |
|
91 |
* to become less than the usage threshold value. |
|
24367
705490680527
8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents:
18799
diff
changeset
|
92 |
* </li> |
2 | 93 |
* <li>A {@link #MEMORY_COLLECTION_THRESHOLD_EXCEEDED |
94 |
* collection usage threshold exceeded notification}. |
|
95 |
* <br>This notification will be emitted when |
|
96 |
* the memory usage of a memory pool is greater than or equal to its |
|
97 |
* <a href="MemoryPoolMXBean.html#CollectionThreshold"> |
|
98 |
* collection usage threshold</a> after the Java virtual machine |
|
99 |
* has expended effort in recycling unused objects in that |
|
100 |
* memory pool.</li> |
|
101 |
* </ul> |
|
102 |
* |
|
103 |
* @author Mandy Chung |
|
104 |
* @since 1.5 |
|
105 |
* |
|
106 |
*/ |
|
107 |
public class MemoryNotificationInfo { |
|
108 |
private final String poolName; |
|
109 |
private final MemoryUsage usage; |
|
110 |
private final long count; |
|
111 |
||
112 |
/** |
|
113 |
* Notification type denoting that |
|
114 |
* the memory usage of a memory pool has |
|
115 |
* reached or exceeded its |
|
116 |
* <a href="MemoryPoolMXBean.html#UsageThreshold"> usage threshold</a> value. |
|
117 |
* This notification is emitted by {@link MemoryMXBean}. |
|
118 |
* Subsequent crossing of the usage threshold value does not cause |
|
119 |
* further notification until the memory usage has returned |
|
120 |
* to become less than the usage threshold value. |
|
121 |
* The value of this notification type is |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
122 |
* {@code java.management.memory.threshold.exceeded}. |
2 | 123 |
*/ |
124 |
public static final String MEMORY_THRESHOLD_EXCEEDED = |
|
125 |
"java.management.memory.threshold.exceeded"; |
|
126 |
||
127 |
/** |
|
128 |
* Notification type denoting that |
|
129 |
* the memory usage of a memory pool is greater than or equal to its |
|
130 |
* <a href="MemoryPoolMXBean.html#CollectionThreshold"> |
|
131 |
* collection usage threshold</a> after the Java virtual machine |
|
132 |
* has expended effort in recycling unused objects in that |
|
133 |
* memory pool. |
|
134 |
* This notification is emitted by {@link MemoryMXBean}. |
|
135 |
* The value of this notification type is |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
136 |
* {@code java.management.memory.collection.threshold.exceeded}. |
2 | 137 |
*/ |
138 |
public static final String MEMORY_COLLECTION_THRESHOLD_EXCEEDED = |
|
139 |
"java.management.memory.collection.threshold.exceeded"; |
|
140 |
||
141 |
/** |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
142 |
* Constructs a {@code MemoryNotificationInfo} object. |
2 | 143 |
* |
144 |
* @param poolName The name of the memory pool which triggers this notification. |
|
145 |
* @param usage Memory usage of the memory pool. |
|
146 |
* @param count The threshold crossing count. |
|
147 |
*/ |
|
148 |
public MemoryNotificationInfo(String poolName, |
|
149 |
MemoryUsage usage, |
|
150 |
long count) { |
|
151 |
if (poolName == null) { |
|
152 |
throw new NullPointerException("Null poolName"); |
|
153 |
} |
|
154 |
if (usage == null) { |
|
155 |
throw new NullPointerException("Null usage"); |
|
156 |
} |
|
157 |
||
158 |
this.poolName = poolName; |
|
159 |
this.usage = usage; |
|
160 |
this.count = count; |
|
161 |
} |
|
162 |
||
163 |
MemoryNotificationInfo(CompositeData cd) { |
|
164 |
MemoryNotifInfoCompositeData.validateCompositeData(cd); |
|
165 |
||
166 |
this.poolName = MemoryNotifInfoCompositeData.getPoolName(cd); |
|
167 |
this.usage = MemoryNotifInfoCompositeData.getUsage(cd); |
|
168 |
this.count = MemoryNotifInfoCompositeData.getCount(cd); |
|
169 |
} |
|
170 |
||
171 |
/** |
|
172 |
* Returns the name of the memory pool that triggers this notification. |
|
173 |
* The memory pool usage has crossed a threshold. |
|
174 |
* |
|
175 |
* @return the name of the memory pool that triggers this notification. |
|
176 |
*/ |
|
177 |
public String getPoolName() { |
|
178 |
return poolName; |
|
179 |
} |
|
180 |
||
181 |
/** |
|
182 |
* Returns the memory usage of the memory pool |
|
183 |
* when this notification was constructed. |
|
184 |
* |
|
185 |
* @return the memory usage of the memory pool |
|
186 |
* when this notification was constructed. |
|
187 |
*/ |
|
188 |
public MemoryUsage getUsage() { |
|
189 |
return usage; |
|
190 |
} |
|
191 |
||
192 |
/** |
|
193 |
* Returns the number of times that the memory usage has crossed |
|
194 |
* a threshold when the notification was constructed. |
|
195 |
* For usage threshold notifications, this count will be the |
|
196 |
* {@link MemoryPoolMXBean#getUsageThresholdCount threshold |
|
197 |
* count}. For collection threshold notifications, |
|
198 |
* this count will be the |
|
199 |
* {@link MemoryPoolMXBean#getCollectionUsageThresholdCount |
|
200 |
* collection usage threshold count}. |
|
201 |
* |
|
202 |
* @return the number of times that the memory usage has crossed |
|
203 |
* a threshold when the notification was constructed. |
|
204 |
*/ |
|
205 |
public long getCount() { |
|
206 |
return count; |
|
207 |
} |
|
208 |
||
209 |
/** |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
210 |
* Returns a {@code MemoryNotificationInfo} object represented by the |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
211 |
* given {@code CompositeData}. |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
212 |
* The given {@code CompositeData} must contain |
2 | 213 |
* the following attributes: |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
214 |
* <table class="striped" style="margin-left:2em"> |
44858
7183899b064b
8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents:
32034
diff
changeset
|
215 |
* <caption style="display:none">The attributes and the types the given CompositeData contains</caption> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
216 |
* <thead> |
2 | 217 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
218 |
* <th scope="col">Attribute Name</th> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
219 |
* <th scope="col">Type</th> |
2 | 220 |
* </tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
221 |
* </thead> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
222 |
* <tbody style="text-align:left"> |
2 | 223 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
224 |
* <th scope="row">poolName</th> |
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
225 |
* <td>{@code java.lang.String}</td> |
2 | 226 |
* </tr> |
227 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
228 |
* <th scope="row">usage</th> |
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
229 |
* <td>{@code javax.management.openmbean.CompositeData}</td> |
2 | 230 |
* </tr> |
231 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
232 |
* <th scope="row">count</th> |
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
233 |
* <td>{@code java.lang.Long}</td> |
2 | 234 |
* </tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
235 |
* </tbody> |
2 | 236 |
* </table> |
237 |
* |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
238 |
* @param cd {@code CompositeData} representing a |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
239 |
* {@code MemoryNotificationInfo} |
2 | 240 |
* |
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
241 |
* @throws IllegalArgumentException if {@code cd} does not |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
242 |
* represent a {@code MemoryNotificationInfo} object. |
2 | 243 |
* |
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
244 |
* @return a {@code MemoryNotificationInfo} object represented |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
245 |
* by {@code cd} if {@code cd} is not {@code null}; |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
246 |
* {@code null} otherwise. |
2 | 247 |
*/ |
248 |
public static MemoryNotificationInfo from(CompositeData cd) { |
|
249 |
if (cd == null) { |
|
250 |
return null; |
|
251 |
} |
|
252 |
||
253 |
if (cd instanceof MemoryNotifInfoCompositeData) { |
|
254 |
return ((MemoryNotifInfoCompositeData) cd).getMemoryNotifInfo(); |
|
255 |
} else { |
|
256 |
return new MemoryNotificationInfo(cd); |
|
257 |
} |
|
258 |
} |
|
259 |
} |