author | sjiang |
Fri, 17 Apr 2015 09:40:02 +0200 | |
changeset 30355 | e37c7eba132f |
parent 25859 | jdk/src/java.management/share/classes/sun/management/VMOptionCompositeData.java@3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, 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 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
26 |
package com.sun.management.internal; |
2 | 27 |
|
28 |
import com.sun.management.VMOption; |
|
29 |
import com.sun.management.VMOption.Origin; |
|
30 |
import javax.management.openmbean.CompositeType; |
|
31 |
import javax.management.openmbean.CompositeData; |
|
32 |
import javax.management.openmbean.CompositeDataSupport; |
|
33 |
import javax.management.openmbean.OpenDataException; |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
34 |
import sun.management.LazyCompositeData; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
35 |
import sun.management.MappedMXBeanType; |
2 | 36 |
|
37 |
/** |
|
38 |
* A CompositeData for VMOption for the local management support. |
|
39 |
* This class avoids the performance penalty paid to the |
|
40 |
* construction of a CompositeData use in the local case. |
|
41 |
*/ |
|
42 |
public class VMOptionCompositeData extends LazyCompositeData { |
|
43 |
private final VMOption option; |
|
44 |
||
45 |
private VMOptionCompositeData(VMOption option) { |
|
46 |
this.option = option; |
|
47 |
} |
|
48 |
||
49 |
public VMOption getVMOption() { |
|
50 |
return option; |
|
51 |
} |
|
52 |
||
53 |
public static CompositeData toCompositeData(VMOption option) { |
|
54 |
VMOptionCompositeData vcd = new VMOptionCompositeData(option); |
|
55 |
return vcd.getCompositeData(); |
|
56 |
} |
|
57 |
||
58 |
protected CompositeData getCompositeData() { |
|
59 |
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH |
|
60 |
// vmOptionItemNames! |
|
61 |
final Object[] vmOptionItemValues = { |
|
62 |
option.getName(), |
|
63 |
option.getValue(), |
|
24685
215fa91e1b4c
8044461: Cleanup new Boolean and single character strings
rriggs
parents:
5506
diff
changeset
|
64 |
option.isWriteable(), |
2 | 65 |
option.getOrigin().toString(), |
66 |
}; |
|
67 |
||
68 |
try { |
|
69 |
return new CompositeDataSupport(vmOptionCompositeType, |
|
70 |
vmOptionItemNames, |
|
71 |
vmOptionItemValues); |
|
72 |
} catch (OpenDataException e) { |
|
73 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
74 |
throw new AssertionError(e); |
2 | 75 |
} |
76 |
} |
|
77 |
||
78 |
private static final CompositeType vmOptionCompositeType; |
|
79 |
static { |
|
80 |
try { |
|
81 |
vmOptionCompositeType = (CompositeType) |
|
82 |
MappedMXBeanType.toOpenType(VMOption.class); |
|
83 |
} catch (OpenDataException e) { |
|
84 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
85 |
throw new AssertionError(e); |
2 | 86 |
} |
87 |
} |
|
88 |
||
89 |
static CompositeType getVMOptionCompositeType() { |
|
90 |
return vmOptionCompositeType; |
|
91 |
} |
|
92 |
||
93 |
private static final String NAME = "name"; |
|
94 |
private static final String VALUE = "value"; |
|
95 |
private static final String WRITEABLE = "writeable"; |
|
96 |
private static final String ORIGIN = "origin"; |
|
97 |
||
98 |
private static final String[] vmOptionItemNames = { |
|
99 |
NAME, |
|
100 |
VALUE, |
|
101 |
WRITEABLE, |
|
102 |
ORIGIN, |
|
103 |
}; |
|
104 |
||
105 |
public static String getName(CompositeData cd) { |
|
106 |
return getString(cd, NAME); |
|
107 |
} |
|
108 |
public static String getValue(CompositeData cd) { |
|
109 |
return getString(cd, VALUE); |
|
110 |
} |
|
111 |
public static Origin getOrigin(CompositeData cd) { |
|
112 |
String o = getString(cd, ORIGIN); |
|
113 |
return Enum.valueOf(Origin.class, o); |
|
114 |
} |
|
115 |
public static boolean isWriteable(CompositeData cd) { |
|
116 |
return getBoolean(cd, WRITEABLE); |
|
117 |
} |
|
118 |
||
119 |
/** Validate if the input CompositeData has the expected |
|
120 |
* CompositeType (i.e. contain all attributes with expected |
|
121 |
* names and types). |
|
122 |
*/ |
|
123 |
public static void validateCompositeData(CompositeData cd) { |
|
124 |
if (cd == null) { |
|
125 |
throw new NullPointerException("Null CompositeData"); |
|
126 |
} |
|
127 |
||
128 |
if (!isTypeMatched(vmOptionCompositeType, cd.getCompositeType())) { |
|
129 |
throw new IllegalArgumentException( |
|
130 |
"Unexpected composite type for VMOption"); |
|
131 |
} |
|
132 |
} |
|
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
133 |
|
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
134 |
private static final long serialVersionUID = -2395573975093578470L; |
2 | 135 |
} |