author | chegar |
Fri, 09 Mar 2018 17:59:11 +0000 | |
branch | http-client-branch |
changeset 56272 | 7394452786ba |
parent 47216 | 71c04702a3d5 |
child 58766 | 54ffb15c4839 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2004, 2008, 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 sun.management; |
|
27 |
||
28 |
import java.lang.management.MemoryNotificationInfo; |
|
29 |
import java.lang.management.MemoryUsage; |
|
30 |
import javax.management.openmbean.CompositeData; |
|
31 |
import javax.management.openmbean.CompositeType; |
|
32 |
import javax.management.openmbean.CompositeDataSupport; |
|
33 |
import javax.management.openmbean.OpenDataException; |
|
34 |
||
35 |
/** |
|
36 |
* A CompositeData for MemoryNotificationInfo for the local management support. |
|
37 |
* This class avoids the performance penalty paid to the |
|
38 |
* construction of a CompositeData use in the local case. |
|
39 |
*/ |
|
40 |
public class MemoryNotifInfoCompositeData extends LazyCompositeData { |
|
41 |
private final MemoryNotificationInfo memoryNotifInfo; |
|
42 |
||
43 |
private MemoryNotifInfoCompositeData(MemoryNotificationInfo info) { |
|
44 |
this.memoryNotifInfo = info; |
|
45 |
} |
|
46 |
||
47 |
public MemoryNotificationInfo getMemoryNotifInfo() { |
|
48 |
return memoryNotifInfo; |
|
49 |
} |
|
50 |
||
51 |
public static CompositeData toCompositeData(MemoryNotificationInfo info) { |
|
52 |
MemoryNotifInfoCompositeData mnicd = |
|
53 |
new MemoryNotifInfoCompositeData(info); |
|
54 |
return mnicd.getCompositeData(); |
|
55 |
} |
|
56 |
||
57 |
protected CompositeData getCompositeData() { |
|
58 |
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH |
|
59 |
// memoryNotifInfoItemNames! |
|
60 |
final Object[] memoryNotifInfoItemValues = { |
|
61 |
memoryNotifInfo.getPoolName(), |
|
62 |
MemoryUsageCompositeData.toCompositeData(memoryNotifInfo.getUsage()), |
|
25186
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
5506
diff
changeset
|
63 |
memoryNotifInfo.getCount(), |
2 | 64 |
}; |
65 |
||
66 |
try { |
|
67 |
return new CompositeDataSupport(memoryNotifInfoCompositeType, |
|
68 |
memoryNotifInfoItemNames, |
|
69 |
memoryNotifInfoItemValues); |
|
70 |
} catch (OpenDataException e) { |
|
71 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
72 |
throw new AssertionError(e); |
2 | 73 |
} |
74 |
} |
|
75 |
||
76 |
private static final CompositeType memoryNotifInfoCompositeType; |
|
77 |
static { |
|
78 |
try { |
|
79 |
memoryNotifInfoCompositeType = (CompositeType) |
|
80 |
MappedMXBeanType.toOpenType(MemoryNotificationInfo.class); |
|
81 |
} catch (OpenDataException e) { |
|
82 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
83 |
throw new AssertionError(e); |
2 | 84 |
} |
85 |
} |
|
86 |
||
87 |
private static final String POOL_NAME = "poolName"; |
|
88 |
private static final String USAGE = "usage"; |
|
89 |
private static final String COUNT = "count"; |
|
90 |
private static final String[] memoryNotifInfoItemNames = { |
|
91 |
POOL_NAME, |
|
92 |
USAGE, |
|
93 |
COUNT, |
|
94 |
}; |
|
95 |
||
96 |
||
97 |
public static String getPoolName(CompositeData cd) { |
|
98 |
String poolname = getString(cd, POOL_NAME); |
|
99 |
if (poolname == null) { |
|
100 |
throw new IllegalArgumentException("Invalid composite data: " + |
|
101 |
"Attribute " + POOL_NAME + " has null value"); |
|
102 |
} |
|
103 |
return poolname; |
|
104 |
} |
|
105 |
||
106 |
public static MemoryUsage getUsage(CompositeData cd) { |
|
107 |
CompositeData usageData = (CompositeData) cd.get(USAGE); |
|
108 |
return MemoryUsage.from(usageData); |
|
109 |
} |
|
110 |
||
111 |
public static long getCount(CompositeData cd) { |
|
112 |
return getLong(cd, COUNT); |
|
113 |
} |
|
114 |
||
115 |
/** Validate if the input CompositeData has the expected |
|
116 |
* CompositeType (i.e. contain all attributes with expected |
|
117 |
* names and types). |
|
118 |
*/ |
|
119 |
public static void validateCompositeData(CompositeData cd) { |
|
120 |
if (cd == null) { |
|
121 |
throw new NullPointerException("Null CompositeData"); |
|
122 |
} |
|
123 |
||
124 |
if (!isTypeMatched(memoryNotifInfoCompositeType, cd.getCompositeType())) { |
|
125 |
throw new IllegalArgumentException( |
|
126 |
"Unexpected composite type for MemoryNotificationInfo"); |
|
127 |
} |
|
128 |
} |
|
129 |
||
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
130 |
private static final long serialVersionUID = -1805123446483771291L; |
2 | 131 |
} |