Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
ae942eac
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ae942eac
编写于
6月 05, 2008
作者:
E
emcmanus
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6562936: Support custom type mappings in MXBeans
Reviewed-by: dfuchs
上级
97272418
变更
30
展开全部
隐藏空白更改
内联
并排
Showing
30 changed file
with
2788 addition
and
601 deletion
+2788
-601
src/share/classes/com/sun/jmx/mbeanserver/ConvertingMethod.java
...are/classes/com/sun/jmx/mbeanserver/ConvertingMethod.java
+46
-30
src/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java
.../com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java
+382
-328
src/share/classes/com/sun/jmx/mbeanserver/Introspector.java
src/share/classes/com/sun/jmx/mbeanserver/Introspector.java
+25
-11
src/share/classes/com/sun/jmx/mbeanserver/MBeanAnalyzer.java
src/share/classes/com/sun/jmx/mbeanserver/MBeanAnalyzer.java
+22
-19
src/share/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java
...re/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java
+32
-13
src/share/classes/com/sun/jmx/mbeanserver/MBeanSupport.java
src/share/classes/com/sun/jmx/mbeanserver/MBeanSupport.java
+12
-10
src/share/classes/com/sun/jmx/mbeanserver/MXBeanIntrospector.java
...e/classes/com/sun/jmx/mbeanserver/MXBeanIntrospector.java
+57
-9
src/share/classes/com/sun/jmx/mbeanserver/MXBeanLookup.java
src/share/classes/com/sun/jmx/mbeanserver/MXBeanLookup.java
+183
-49
src/share/classes/com/sun/jmx/mbeanserver/MXBeanProxy.java
src/share/classes/com/sun/jmx/mbeanserver/MXBeanProxy.java
+29
-9
src/share/classes/com/sun/jmx/mbeanserver/MXBeanSupport.java
src/share/classes/com/sun/jmx/mbeanserver/MXBeanSupport.java
+25
-19
src/share/classes/com/sun/jmx/mbeanserver/NotificationMBeanSupport.java
...ses/com/sun/jmx/mbeanserver/NotificationMBeanSupport.java
+2
-1
src/share/classes/com/sun/jmx/mbeanserver/PerInterface.java
src/share/classes/com/sun/jmx/mbeanserver/PerInterface.java
+1
-1
src/share/classes/com/sun/jmx/mbeanserver/StandardMBeanSupport.java
...classes/com/sun/jmx/mbeanserver/StandardMBeanSupport.java
+3
-4
src/share/classes/javax/management/JMX.java
src/share/classes/javax/management/JMX.java
+367
-20
src/share/classes/javax/management/MBeanServerInvocationHandler.java
...lasses/javax/management/MBeanServerInvocationHandler.java
+49
-16
src/share/classes/javax/management/MXBean.java
src/share/classes/javax/management/MXBean.java
+88
-8
src/share/classes/javax/management/StandardMBean.java
src/share/classes/javax/management/StandardMBean.java
+139
-29
src/share/classes/javax/management/openmbean/CompositeDataInvocationHandler.java
.../management/openmbean/CompositeDataInvocationHandler.java
+16
-7
src/share/classes/javax/management/openmbean/CompositeType.java
...are/classes/javax/management/openmbean/CompositeType.java
+2
-2
src/share/classes/javax/management/openmbean/MXBeanMapping.java
...are/classes/javax/management/openmbean/MXBeanMapping.java
+207
-0
src/share/classes/javax/management/openmbean/MXBeanMappingClass.java
...lasses/javax/management/openmbean/MXBeanMappingClass.java
+61
-0
src/share/classes/javax/management/openmbean/MXBeanMappingFactory.java
...sses/javax/management/openmbean/MXBeanMappingFactory.java
+162
-0
src/share/classes/javax/management/openmbean/MXBeanMappingFactoryClass.java
...javax/management/openmbean/MXBeanMappingFactoryClass.java
+72
-0
src/share/classes/javax/management/openmbean/OpenType.java
src/share/classes/javax/management/openmbean/OpenType.java
+1
-1
test/javax/management/mxbean/CustomTypeTest.java
test/javax/management/mxbean/CustomTypeTest.java
+590
-0
test/javax/management/mxbean/customtypes/CustomLongMXBean.java
...javax/management/mxbean/customtypes/CustomLongMXBean.java
+31
-0
test/javax/management/mxbean/customtypes/CustomMXBean.java
test/javax/management/mxbean/customtypes/CustomMXBean.java
+7
-15
test/javax/management/mxbean/customtypes/IntegerIsLongFactory.java
...x/management/mxbean/customtypes/IntegerIsLongFactory.java
+74
-0
test/javax/management/mxbean/customtypes/IntegerIsStringFactory.java
...management/mxbean/customtypes/IntegerIsStringFactory.java
+76
-0
test/javax/management/mxbean/customtypes/package-info.java
test/javax/management/mxbean/customtypes/package-info.java
+27
-0
未找到文件。
src/share/classes/com/sun/jmx/mbeanserver/ConvertingMethod.java
浏览文件 @
ae942eac
...
@@ -31,13 +31,15 @@ import java.lang.reflect.Type;
...
@@ -31,13 +31,15 @@ import java.lang.reflect.Type;
import
javax.management.Descriptor
;
import
javax.management.Descriptor
;
import
javax.management.MBeanException
;
import
javax.management.MBeanException
;
import
javax.management.openmbean.MXBeanMapping
;
import
javax.management.openmbean.MXBeanMappingFactory
;
import
javax.management.openmbean.OpenDataException
;
import
javax.management.openmbean.OpenDataException
;
import
javax.management.openmbean.OpenType
;
import
javax.management.openmbean.OpenType
;
final
class
ConvertingMethod
{
final
class
ConvertingMethod
{
static
ConvertingMethod
from
(
Method
m
)
{
static
ConvertingMethod
from
(
Method
m
,
MXBeanMappingFactory
mappingFactory
)
{
try
{
try
{
return
new
ConvertingMethod
(
m
);
return
new
ConvertingMethod
(
m
,
mappingFactory
);
}
catch
(
OpenDataException
ode
)
{
}
catch
(
OpenDataException
ode
)
{
final
String
msg
=
"Method "
+
m
.
getDeclaringClass
().
getName
()
+
final
String
msg
=
"Method "
+
m
.
getDeclaringClass
().
getName
()
+
"."
+
m
.
getName
()
+
" has parameter or return type that "
+
"."
+
m
.
getName
()
+
" has parameter or return type that "
+
...
@@ -67,13 +69,13 @@ final class ConvertingMethod {
...
@@ -67,13 +69,13 @@ final class ConvertingMethod {
}
}
OpenType
getOpenReturnType
()
{
OpenType
getOpenReturnType
()
{
return
return
Converter
.
getOpenType
();
return
return
Mapping
.
getOpenType
();
}
}
OpenType
[]
getOpenParameterTypes
()
{
OpenType
[]
getOpenParameterTypes
()
{
final
OpenType
[]
types
=
new
OpenType
[
param
Converter
s
.
length
];
final
OpenType
[]
types
=
new
OpenType
[
param
Mapping
s
.
length
];
for
(
int
i
=
0
;
i
<
param
Converter
s
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
param
Mapping
s
.
length
;
i
++)
types
[
i
]
=
param
Converter
s
[
i
].
getOpenType
();
types
[
i
]
=
param
Mapping
s
[
i
].
getOpenType
();
return
types
;
return
types
;
}
}
...
@@ -85,9 +87,9 @@ final class ConvertingMethod {
...
@@ -85,9 +87,9 @@ final class ConvertingMethod {
* value will be converted to an Open Type, so if it is convertible
* value will be converted to an Open Type, so if it is convertible
* at all there is no further check needed.
* at all there is no further check needed.
*/
*/
void
checkCallFromOpen
()
throws
IllegalArgumentException
{
void
checkCallFromOpen
()
{
try
{
try
{
for
(
OpenConverter
paramConverter
:
paramConverter
s
)
for
(
MXBeanMapping
paramConverter
:
paramMapping
s
)
paramConverter
.
checkReconstructible
();
paramConverter
.
checkReconstructible
();
}
catch
(
InvalidObjectException
e
)
{
}
catch
(
InvalidObjectException
e
)
{
throw
new
IllegalArgumentException
(
e
);
throw
new
IllegalArgumentException
(
e
);
...
@@ -102,32 +104,32 @@ final class ConvertingMethod {
...
@@ -102,32 +104,32 @@ final class ConvertingMethod {
* open types, so if it is convertible at all there is no further
* open types, so if it is convertible at all there is no further
* check needed.
* check needed.
*/
*/
void
checkCallToOpen
()
throws
IllegalArgumentException
{
void
checkCallToOpen
()
{
try
{
try
{
return
Converter
.
checkReconstructible
();
return
Mapping
.
checkReconstructible
();
}
catch
(
InvalidObjectException
e
)
{
}
catch
(
InvalidObjectException
e
)
{
throw
new
IllegalArgumentException
(
e
);
throw
new
IllegalArgumentException
(
e
);
}
}
}
}
String
[]
getOpenSignature
()
{
String
[]
getOpenSignature
()
{
if
(
param
Converter
s
.
length
==
0
)
if
(
param
Mapping
s
.
length
==
0
)
return
noStrings
;
return
noStrings
;
String
[]
sig
=
new
String
[
param
Converter
s
.
length
];
String
[]
sig
=
new
String
[
param
Mapping
s
.
length
];
for
(
int
i
=
0
;
i
<
param
Converter
s
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
param
Mapping
s
.
length
;
i
++)
sig
[
i
]
=
param
Converter
s
[
i
].
getOpenClass
().
getName
();
sig
[
i
]
=
param
Mapping
s
[
i
].
getOpenClass
().
getName
();
return
sig
;
return
sig
;
}
}
final
Object
toOpenReturnValue
(
MXBeanLookup
lookup
,
Object
ret
)
final
Object
toOpenReturnValue
(
MXBeanLookup
lookup
,
Object
ret
)
throws
OpenDataException
{
throws
OpenDataException
{
return
return
Converter
.
toOpenValue
(
lookup
,
ret
);
return
return
Mapping
.
toOpenValue
(
ret
);
}
}
final
Object
fromOpenReturnValue
(
MXBeanLookup
lookup
,
Object
ret
)
final
Object
fromOpenReturnValue
(
MXBeanLookup
lookup
,
Object
ret
)
throws
InvalidObjectException
{
throws
InvalidObjectException
{
return
return
Converter
.
fromOpenValue
(
lookup
,
ret
);
return
return
Mapping
.
fromOpenValue
(
ret
);
}
}
final
Object
[]
toOpenParameters
(
MXBeanLookup
lookup
,
Object
[]
params
)
final
Object
[]
toOpenParameters
(
MXBeanLookup
lookup
,
Object
[]
params
)
...
@@ -136,17 +138,17 @@ final class ConvertingMethod {
...
@@ -136,17 +138,17 @@ final class ConvertingMethod {
return
params
;
return
params
;
final
Object
[]
oparams
=
new
Object
[
params
.
length
];
final
Object
[]
oparams
=
new
Object
[
params
.
length
];
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
oparams
[
i
]
=
param
Converters
[
i
].
toOpenValue
(
lookup
,
params
[
i
]);
oparams
[
i
]
=
param
Mappings
[
i
].
toOpenValue
(
params
[
i
]);
return
oparams
;
return
oparams
;
}
}
final
Object
[]
fromOpenParameters
(
MXBeanLookup
lookup
,
Object
[]
params
)
final
Object
[]
fromOpenParameters
(
Object
[]
params
)
throws
InvalidObjectException
{
throws
InvalidObjectException
{
if
(
paramConversionIsIdentity
||
params
==
null
)
if
(
paramConversionIsIdentity
||
params
==
null
)
return
params
;
return
params
;
final
Object
[]
jparams
=
new
Object
[
params
.
length
];
final
Object
[]
jparams
=
new
Object
[
params
.
length
];
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
jparams
[
i
]
=
param
Converters
[
i
].
fromOpenValue
(
lookup
,
params
[
i
]);
jparams
[
i
]
=
param
Mappings
[
i
].
fromOpenValue
(
params
[
i
]);
return
jparams
;
return
jparams
;
}
}
...
@@ -154,23 +156,35 @@ final class ConvertingMethod {
...
@@ -154,23 +156,35 @@ final class ConvertingMethod {
Object
param
,
Object
param
,
int
paramNo
)
int
paramNo
)
throws
OpenDataException
{
throws
OpenDataException
{
return
param
Converters
[
paramNo
].
toOpenValue
(
lookup
,
param
);
return
param
Mappings
[
paramNo
].
toOpenValue
(
param
);
}
}
final
Object
fromOpenParameter
(
MXBeanLookup
lookup
,
final
Object
fromOpenParameter
(
MXBeanLookup
lookup
,
Object
param
,
Object
param
,
int
paramNo
)
int
paramNo
)
throws
InvalidObjectException
{
throws
InvalidObjectException
{
return
param
Converters
[
paramNo
].
fromOpenValue
(
lookup
,
param
);
return
param
Mappings
[
paramNo
].
fromOpenValue
(
param
);
}
}
Object
invokeWithOpenReturn
(
MXBeanLookup
lookup
,
Object
invokeWithOpenReturn
(
MXBeanLookup
lookup
,
Object
obj
,
Object
[]
params
)
Object
obj
,
Object
[]
params
)
throws
MBeanException
,
IllegalAccessException
,
throws
MBeanException
,
IllegalAccessException
,
InvocationTargetException
{
InvocationTargetException
{
MXBeanLookup
old
=
MXBeanLookup
.
getLookup
();
try
{
MXBeanLookup
.
setLookup
(
lookup
);
return
invokeWithOpenReturn
(
obj
,
params
);
}
finally
{
MXBeanLookup
.
setLookup
(
old
);
}
}
private
Object
invokeWithOpenReturn
(
Object
obj
,
Object
[]
params
)
throws
MBeanException
,
IllegalAccessException
,
InvocationTargetException
{
final
Object
[]
javaParams
;
final
Object
[]
javaParams
;
try
{
try
{
javaParams
=
fromOpenParameters
(
lookup
,
params
);
javaParams
=
fromOpenParameters
(
params
);
}
catch
(
InvalidObjectException
e
)
{
}
catch
(
InvalidObjectException
e
)
{
// probably can't happen
// probably can't happen
final
String
msg
=
methodName
()
+
": cannot convert parameters "
+
final
String
msg
=
methodName
()
+
": cannot convert parameters "
+
...
@@ -179,7 +193,7 @@ final class ConvertingMethod {
...
@@ -179,7 +193,7 @@ final class ConvertingMethod {
}
}
final
Object
javaReturn
=
method
.
invoke
(
obj
,
javaParams
);
final
Object
javaReturn
=
method
.
invoke
(
obj
,
javaParams
);
try
{
try
{
return
return
Converter
.
toOpenValue
(
lookup
,
javaReturn
);
return
return
Mapping
.
toOpenValue
(
javaReturn
);
}
catch
(
OpenDataException
e
)
{
}
catch
(
OpenDataException
e
)
{
// probably can't happen
// probably can't happen
final
String
msg
=
methodName
()
+
": cannot convert return "
+
final
String
msg
=
methodName
()
+
": cannot convert return "
+
...
@@ -192,15 +206,17 @@ final class ConvertingMethod {
...
@@ -192,15 +206,17 @@ final class ConvertingMethod {
return
method
.
getDeclaringClass
()
+
"."
+
method
.
getName
();
return
method
.
getDeclaringClass
()
+
"."
+
method
.
getName
();
}
}
private
ConvertingMethod
(
Method
m
)
throws
OpenDataException
{
private
ConvertingMethod
(
Method
m
,
MXBeanMappingFactory
mappingFactory
)
throws
OpenDataException
{
this
.
method
=
m
;
this
.
method
=
m
;
returnConverter
=
OpenConverter
.
toConverter
(
m
.
getGenericReturnType
());
returnMapping
=
mappingFactory
.
mappingForType
(
m
.
getGenericReturnType
(),
mappingFactory
);
Type
[]
params
=
m
.
getGenericParameterTypes
();
Type
[]
params
=
m
.
getGenericParameterTypes
();
param
Converters
=
new
OpenConverter
[
params
.
length
];
param
Mappings
=
new
MXBeanMapping
[
params
.
length
];
boolean
identity
=
true
;
boolean
identity
=
true
;
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
{
param
Converters
[
i
]
=
OpenConverter
.
toConverter
(
params
[
i
]
);
param
Mappings
[
i
]
=
mappingFactory
.
mappingForType
(
params
[
i
],
mappingFactory
);
identity
&=
paramConverters
[
i
].
isIdentity
(
);
identity
&=
DefaultMXBeanMappingFactory
.
isIdentity
(
paramMappings
[
i
]
);
}
}
paramConversionIsIdentity
=
identity
;
paramConversionIsIdentity
=
identity
;
}
}
...
@@ -208,7 +224,7 @@ final class ConvertingMethod {
...
@@ -208,7 +224,7 @@ final class ConvertingMethod {
private
static
final
String
[]
noStrings
=
new
String
[
0
];
private
static
final
String
[]
noStrings
=
new
String
[
0
];
private
final
Method
method
;
private
final
Method
method
;
private
final
OpenConverter
returnConverter
;
private
final
MXBeanMapping
returnMapping
;
private
final
OpenConverter
[]
paramConverter
s
;
private
final
MXBeanMapping
[]
paramMapping
s
;
private
final
boolean
paramConversionIsIdentity
;
private
final
boolean
paramConversionIsIdentity
;
}
}
src/share/classes/com/sun/jmx/mbeanserver/
OpenConverter
.java
→
src/share/classes/com/sun/jmx/mbeanserver/
DefaultMXBeanMappingFactory
.java
浏览文件 @
ae942eac
此差异已折叠。
点击以展开。
src/share/classes/com/sun/jmx/mbeanserver/Introspector.java
浏览文件 @
ae942eac
...
@@ -42,7 +42,6 @@ import javax.management.ImmutableDescriptor;
...
@@ -42,7 +42,6 @@ import javax.management.ImmutableDescriptor;
import
javax.management.MBeanInfo
;
import
javax.management.MBeanInfo
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.NotCompliantMBeanException
;
import
com.sun.jmx.mbeanserver.Util
;
import
com.sun.jmx.remote.util.EnvHelp
;
import
com.sun.jmx.remote.util.EnvHelp
;
import
java.beans.BeanInfo
;
import
java.beans.BeanInfo
;
import
java.beans.PropertyDescriptor
;
import
java.beans.PropertyDescriptor
;
...
@@ -50,6 +49,7 @@ import java.lang.reflect.Array;
...
@@ -50,6 +49,7 @@ import java.lang.reflect.Array;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
javax.management.AttributeNotFoundException
;
import
javax.management.AttributeNotFoundException
;
import
javax.management.openmbean.CompositeData
;
import
javax.management.openmbean.CompositeData
;
import
javax.management.openmbean.MXBeanMappingFactory
;
/**
/**
* This class contains the methods for performing all the tests needed to verify
* This class contains the methods for performing all the tests needed to verify
...
@@ -165,30 +165,34 @@ public class Introspector {
...
@@ -165,30 +165,34 @@ public class Introspector {
throw
new
NotCompliantMBeanException
(
msg
);
throw
new
NotCompliantMBeanException
(
msg
);
}
}
public
static
DynamicMBean
makeDynamicMBean
(
Object
mbean
)
public
static
<
T
>
DynamicMBean
makeDynamicMBean
(
T
mbean
)
throws
NotCompliantMBeanException
{
throws
NotCompliantMBeanException
{
if
(
mbean
==
null
)
throw
new
NotCompliantMBeanException
(
"Null MBean object"
);
if
(
mbean
instanceof
DynamicMBean
)
if
(
mbean
instanceof
DynamicMBean
)
return
(
DynamicMBean
)
mbean
;
return
(
DynamicMBean
)
mbean
;
final
Class
mbeanClass
=
mbean
.
getClass
();
final
Class
mbeanClass
=
mbean
.
getClass
();
Class
<?>
c
=
null
;
Class
<?
super
T
>
c
=
null
;
try
{
try
{
c
=
getStandardMBeanInterface
(
mbeanClass
);
c
=
Util
.
cast
(
getStandardMBeanInterface
(
mbeanClass
)
);
}
catch
(
NotCompliantMBeanException
e
)
{
}
catch
(
NotCompliantMBeanException
e
)
{
// Ignore exception - we need to check whether
// Ignore exception - we need to check whether
// mbean is an MXBean first.
// mbean is an MXBean first.
}
}
if
(
c
!=
null
)
if
(
c
!=
null
)
return
new
StandardMBeanSupport
(
mbean
,
Util
.<
Class
<
Object
>>
cast
(
c
)
);
return
new
StandardMBeanSupport
(
mbean
,
c
);
try
{
try
{
c
=
getMXBeanInterface
(
mbeanClass
);
c
=
Util
.
cast
(
getMXBeanInterface
(
mbeanClass
)
);
}
catch
(
NotCompliantMBeanException
e
)
{
}
catch
(
NotCompliantMBeanException
e
)
{
// Ignore exception - we cannot decide whether mbean was supposed
// Ignore exception - we cannot decide whether mbean was supposed
// to be an MBean or an MXBean. We will call checkCompliance()
// to be an MBean or an MXBean. We will call checkCompliance()
// to generate the appropriate exception.
// to generate the appropriate exception.
}
}
if
(
c
!=
null
)
if
(
c
!=
null
)
{
return
new
MXBeanSupport
(
mbean
,
Util
.<
Class
<
Object
>>
cast
(
c
));
MXBeanMappingFactory
factory
=
MXBeanMappingFactory
.
forInterface
(
c
);
return
new
MXBeanSupport
(
mbean
,
c
,
factory
);
}
checkCompliance
(
mbeanClass
);
checkCompliance
(
mbeanClass
);
throw
new
NotCompliantMBeanException
(
"Not compliant"
);
// not reached
throw
new
NotCompliantMBeanException
(
"Not compliant"
);
// not reached
}
}
...
@@ -217,9 +221,10 @@ public class Introspector {
...
@@ -217,9 +221,10 @@ public class Introspector {
return
testCompliance
(
baseClass
,
null
);
return
testCompliance
(
baseClass
,
null
);
}
}
public
static
void
testComplianceMXBeanInterface
(
Class
interfaceClass
)
public
static
void
testComplianceMXBeanInterface
(
Class
interfaceClass
,
MXBeanMappingFactory
factory
)
throws
NotCompliantMBeanException
{
throws
NotCompliantMBeanException
{
MXBeanIntrospector
.
getInstance
().
getAnalyzer
(
interfaceClass
);
MXBeanIntrospector
.
getInstance
(
factory
).
getAnalyzer
(
interfaceClass
);
}
}
/**
/**
...
@@ -325,6 +330,15 @@ public class Introspector {
...
@@ -325,6 +330,15 @@ public class Introspector {
}
}
}
}
public
static
<
T
>
Class
<?
super
T
>
getStandardOrMXBeanInterface
(
Class
<
T
>
baseClass
,
boolean
mxbean
)
throws
NotCompliantMBeanException
{
if
(
mxbean
)
return
getMXBeanInterface
(
baseClass
);
else
return
getStandardMBeanInterface
(
baseClass
);
}
/*
/*
* ------------------------------------------
* ------------------------------------------
* PRIVATE METHODS
* PRIVATE METHODS
...
...
src/share/classes/com/sun/jmx/mbeanserver/MBeanAnalyzer.java
浏览文件 @
ae942eac
...
@@ -29,13 +29,10 @@ import static com.sun.jmx.mbeanserver.Util.*;
...
@@ -29,13 +29,10 @@ import static com.sun.jmx.mbeanserver.Util.*;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Comparator
;
import
java.util.Comparator
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.NotCompliantMBeanException
;
/**
/**
...
@@ -54,15 +51,15 @@ import javax.management.NotCompliantMBeanException;
...
@@ -54,15 +51,15 @@ import javax.management.NotCompliantMBeanException;
*/
*/
class
MBeanAnalyzer
<
M
>
{
class
MBeanAnalyzer
<
M
>
{
static
interface
MBeanVisitor
<
M
>
{
static
interface
MBeanVisitor
<
M
,
X
extends
Exception
>
{
public
void
visitAttribute
(
String
attributeName
,
public
void
visitAttribute
(
String
attributeName
,
M
getter
,
M
getter
,
M
setter
);
M
setter
)
throws
X
;
public
void
visitOperation
(
String
operationName
,
public
void
visitOperation
(
String
operationName
,
M
operation
);
M
operation
)
throws
X
;
}
}
void
visit
(
MBeanVisitor
<
M
>
visitor
)
{
<
X
extends
Exception
>
void
visit
(
MBeanVisitor
<
M
,
X
>
visitor
)
throws
X
{
// visit attributes
// visit attributes
for
(
Map
.
Entry
<
String
,
AttrMethods
<
M
>>
entry
:
attrMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
AttrMethods
<
M
>>
entry
:
attrMap
.
entrySet
())
{
String
name
=
entry
.
getKey
();
String
name
=
entry
.
getKey
();
...
@@ -98,21 +95,21 @@ class MBeanAnalyzer<M> {
...
@@ -98,21 +95,21 @@ class MBeanAnalyzer<M> {
// cached PerInterface object for an MBean interface means that
// cached PerInterface object for an MBean interface means that
// an analyzer will not be recreated for a second MBean using the
// an analyzer will not be recreated for a second MBean using the
// same interface.
// same interface.
static
<
M
>
MBeanAnalyzer
<
M
>
analyzer
(
Class
<?>
mbean
Interfac
e
,
static
<
M
>
MBeanAnalyzer
<
M
>
analyzer
(
Class
<?>
mbean
Typ
e
,
MBeanIntrospector
<
M
>
introspector
)
MBeanIntrospector
<
M
>
introspector
)
throws
NotCompliantMBeanException
{
throws
NotCompliantMBeanException
{
return
new
MBeanAnalyzer
<
M
>(
mbean
Interfac
e
,
introspector
);
return
new
MBeanAnalyzer
<
M
>(
mbean
Typ
e
,
introspector
);
}
}
private
MBeanAnalyzer
(
Class
<?>
mbean
Interfac
e
,
private
MBeanAnalyzer
(
Class
<?>
mbean
Typ
e
,
MBeanIntrospector
<
M
>
introspector
)
MBeanIntrospector
<
M
>
introspector
)
throws
NotCompliantMBeanException
{
throws
NotCompliantMBeanException
{
introspector
.
checkCompliance
(
mbean
Interfac
e
);
introspector
.
checkCompliance
(
mbean
Typ
e
);
try
{
try
{
initMaps
(
mbean
Interfac
e
,
introspector
);
initMaps
(
mbean
Typ
e
,
introspector
);
}
catch
(
Exception
x
)
{
}
catch
(
Exception
x
)
{
throw
Introspector
.
throwException
(
mbean
Interfac
e
,
x
);
throw
Introspector
.
throwException
(
mbean
Typ
e
,
x
);
}
}
}
}
...
@@ -126,7 +123,8 @@ class MBeanAnalyzer<M> {
...
@@ -126,7 +123,8 @@ class MBeanAnalyzer<M> {
/* Run through the methods to detect inconsistencies and to enable
/* Run through the methods to detect inconsistencies and to enable
us to give getter and setter together to visitAttribute. */
us to give getter and setter together to visitAttribute. */
for
(
Method
m
:
methods
)
{
for
(
Method
m
:
methods
)
{
String
name
=
m
.
getName
();
final
String
name
=
m
.
getName
();
final
int
nParams
=
m
.
getParameterTypes
().
length
;
final
M
cm
=
introspector
.
mFrom
(
m
);
final
M
cm
=
introspector
.
mFrom
(
m
);
...
@@ -137,7 +135,7 @@ class MBeanAnalyzer<M> {
...
@@ -137,7 +135,7 @@ class MBeanAnalyzer<M> {
&&
m
.
getReturnType
()
==
boolean
.
class
)
&&
m
.
getReturnType
()
==
boolean
.
class
)
attrName
=
name
.
substring
(
2
);
attrName
=
name
.
substring
(
2
);
if
(
attrName
.
length
()
!=
0
&&
m
.
getParameterTypes
().
length
==
0
if
(
attrName
.
length
()
!=
0
&&
nParams
==
0
&&
m
.
getReturnType
()
!=
void
.
class
)
{
&&
m
.
getReturnType
()
!=
void
.
class
)
{
// It's a getter
// It's a getter
// Check we don't have both isX and getX
// Check we don't have both isX and getX
...
@@ -154,7 +152,7 @@ class MBeanAnalyzer<M> {
...
@@ -154,7 +152,7 @@ class MBeanAnalyzer<M> {
am
.
getter
=
cm
;
am
.
getter
=
cm
;
attrMap
.
put
(
attrName
,
am
);
attrMap
.
put
(
attrName
,
am
);
}
else
if
(
name
.
startsWith
(
"set"
)
&&
name
.
length
()
>
3
}
else
if
(
name
.
startsWith
(
"set"
)
&&
name
.
length
()
>
3
&&
m
.
getParameterTypes
().
length
==
1
&&
&&
nParams
==
1
&&
m
.
getReturnType
()
==
void
.
class
)
{
m
.
getReturnType
()
==
void
.
class
)
{
// It's a setter
// It's a setter
attrName
=
name
.
substring
(
3
);
attrName
=
name
.
substring
(
3
);
...
@@ -228,7 +226,11 @@ class MBeanAnalyzer<M> {
...
@@ -228,7 +226,11 @@ class MBeanAnalyzer<M> {
but only the overriding one is of interest. We return the methods
but only the overriding one is of interest. We return the methods
in the same order they arrived in. This isn't required by the spec
in the same order they arrived in. This isn't required by the spec
but existing code may depend on it and users may be used to seeing
but existing code may depend on it and users may be used to seeing
operations or attributes appear in a particular order. */
operations or attributes appear in a particular order.
Because of the way this method works, if the same Method appears
more than once in the given List then it will be completely deleted!
So don't do that. */
static
List
<
Method
>
static
List
<
Method
>
eliminateCovariantMethods
(
List
<
Method
>
startMethods
)
{
eliminateCovariantMethods
(
List
<
Method
>
startMethods
)
{
// We are assuming that you never have very many methods with the
// We are assuming that you never have very many methods with the
...
@@ -243,7 +245,7 @@ class MBeanAnalyzer<M> {
...
@@ -243,7 +245,7 @@ class MBeanAnalyzer<M> {
final
Method
m0
=
sorted
[
i
-
1
];
final
Method
m0
=
sorted
[
i
-
1
];
final
Method
m1
=
sorted
[
i
];
final
Method
m1
=
sorted
[
i
];
// Methods that don't have the same name can't override each other
s
// Methods that don't have the same name can't override each other
if
(!
m0
.
getName
().
equals
(
m1
.
getName
()))
continue
;
if
(!
m0
.
getName
().
equals
(
m1
.
getName
()))
continue
;
// Methods that have the same name and same signature override
// Methods that have the same name and same signature override
...
@@ -251,7 +253,8 @@ class MBeanAnalyzer<M> {
...
@@ -251,7 +253,8 @@ class MBeanAnalyzer<M> {
// due to the way we have sorted them in MethodOrder.
// due to the way we have sorted them in MethodOrder.
if
(
Arrays
.
equals
(
m0
.
getParameterTypes
(),
if
(
Arrays
.
equals
(
m0
.
getParameterTypes
(),
m1
.
getParameterTypes
()))
{
m1
.
getParameterTypes
()))
{
overridden
.
add
(
m0
);
if
(!
overridden
.
add
(
m0
))
throw
new
RuntimeException
(
"Internal error: duplicate Method"
);
}
}
}
}
...
...
src/share/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java
浏览文件 @
ae942eac
...
@@ -40,6 +40,7 @@ import java.util.WeakHashMap;
...
@@ -40,6 +40,7 @@ import java.util.WeakHashMap;
import
javax.management.Descriptor
;
import
javax.management.Descriptor
;
import
javax.management.ImmutableDescriptor
;
import
javax.management.ImmutableDescriptor
;
import
javax.management.IntrospectionException
;
import
javax.management.InvalidAttributeValueException
;
import
javax.management.InvalidAttributeValueException
;
import
javax.management.MBeanAttributeInfo
;
import
javax.management.MBeanAttributeInfo
;
import
javax.management.MBeanConstructorInfo
;
import
javax.management.MBeanConstructorInfo
;
...
@@ -53,8 +54,9 @@ import javax.management.ReflectionException;
...
@@ -53,8 +54,9 @@ import javax.management.ReflectionException;
/**
/**
* An introspector for MBeans of a certain type. There is one instance
* An introspector for MBeans of a certain type. There is one instance
* of this class for Standard MBeans and one for MXBeans, characterized
* of this class for Standard MBeans, and one for every MXBeanMappingFactory;
* by the two concrete subclasses of this abstract class.
* these two cases correspond to the two concrete subclasses of this abstract
* class.
*
*
* @param <M> the representation of methods for this kind of MBean:
* @param <M> the representation of methods for this kind of MBean:
* Method for Standard MBeans, ConvertingMethod for MXBeans.
* Method for Standard MBeans, ConvertingMethod for MXBeans.
...
@@ -119,7 +121,7 @@ abstract class MBeanIntrospector<M> {
...
@@ -119,7 +121,7 @@ abstract class MBeanIntrospector<M> {
* MXBean interface is not valid if one of its parameters cannot be
* MXBean interface is not valid if one of its parameters cannot be
* mapped to an Open Type.
* mapped to an Open Type.
*/
*/
abstract
void
checkMethod
(
M
m
)
throws
IllegalArgumentException
;
abstract
void
checkMethod
(
M
m
);
/**
/**
* Invoke the method with the given target and arguments.
* Invoke the method with the given target and arguments.
...
@@ -149,7 +151,8 @@ abstract class MBeanIntrospector<M> {
...
@@ -149,7 +151,8 @@ abstract class MBeanIntrospector<M> {
* may be null.
* may be null.
*/
*/
abstract
MBeanAttributeInfo
getMBeanAttributeInfo
(
String
attributeName
,
abstract
MBeanAttributeInfo
getMBeanAttributeInfo
(
String
attributeName
,
M
getter
,
M
setter
);
M
getter
,
M
setter
)
throws
IntrospectionException
;
/**
/**
* Construct an MBeanOperationInfo for the given operation based on
* Construct an MBeanOperationInfo for the given operation based on
* the M it was derived from.
* the M it was derived from.
...
@@ -170,6 +173,16 @@ abstract class MBeanIntrospector<M> {
...
@@ -170,6 +173,16 @@ abstract class MBeanIntrospector<M> {
*/
*/
abstract
Descriptor
getMBeanDescriptor
(
Class
<?>
resourceClass
);
abstract
Descriptor
getMBeanDescriptor
(
Class
<?>
resourceClass
);
/**
* Get any additional Descriptor entries for this introspector instance.
* If there is a non-default MXBeanMappingFactory, it will appear in
* this Descriptor.
* @return Additional Descriptor entries, or an empty Descriptor if none.
*/
Descriptor
getSpecificMBeanDescriptor
()
{
return
ImmutableDescriptor
.
EMPTY_DESCRIPTOR
;
}
void
checkCompliance
(
Class
<?>
mbeanType
)
throws
NotCompliantMBeanException
{
void
checkCompliance
(
Class
<?>
mbeanType
)
throws
NotCompliantMBeanException
{
if
(!
mbeanType
.
isInterface
())
{
if
(!
mbeanType
.
isInterface
())
{
throw
new
NotCompliantMBeanException
(
"Not an interface: "
+
throw
new
NotCompliantMBeanException
(
"Not an interface: "
+
...
@@ -216,7 +229,7 @@ abstract class MBeanIntrospector<M> {
...
@@ -216,7 +229,7 @@ abstract class MBeanIntrospector<M> {
* the MBeanInfo's Descriptor.
* the MBeanInfo's Descriptor.
*/
*/
private
MBeanInfo
makeInterfaceMBeanInfo
(
Class
<?>
mbeanInterface
,
private
MBeanInfo
makeInterfaceMBeanInfo
(
Class
<?>
mbeanInterface
,
MBeanAnalyzer
<
M
>
analyzer
)
{
MBeanAnalyzer
<
M
>
analyzer
)
throws
IntrospectionException
{
final
MBeanInfoMaker
maker
=
new
MBeanInfoMaker
();
final
MBeanInfoMaker
maker
=
new
MBeanInfoMaker
();
analyzer
.
visit
(
maker
);
analyzer
.
visit
(
maker
);
final
String
description
=
final
String
description
=
...
@@ -317,11 +330,12 @@ abstract class MBeanIntrospector<M> {
...
@@ -317,11 +330,12 @@ abstract class MBeanIntrospector<M> {
}
}
/** A visitor that constructs the per-interface MBeanInfo. */
/** A visitor that constructs the per-interface MBeanInfo. */
private
class
MBeanInfoMaker
implements
MBeanAnalyzer
.
MBeanVisitor
<
M
>
{
private
class
MBeanInfoMaker
implements
MBeanAnalyzer
.
MBeanVisitor
<
M
,
IntrospectionException
>
{
public
void
visitAttribute
(
String
attributeName
,
public
void
visitAttribute
(
String
attributeName
,
M
getter
,
M
getter
,
M
setter
)
{
M
setter
)
throws
IntrospectionException
{
MBeanAttributeInfo
mbai
=
MBeanAttributeInfo
mbai
=
getMBeanAttributeInfo
(
attributeName
,
getter
,
setter
);
getMBeanAttributeInfo
(
attributeName
,
getter
,
setter
);
...
@@ -346,13 +360,14 @@ abstract class MBeanIntrospector<M> {
...
@@ -346,13 +360,14 @@ abstract class MBeanIntrospector<M> {
ops
.
toArray
(
new
MBeanOperationInfo
[
0
]);
ops
.
toArray
(
new
MBeanOperationInfo
[
0
]);
final
String
interfaceClassName
=
final
String
interfaceClassName
=
"interfaceClassName="
+
mbeanInterface
.
getName
();
"interfaceClassName="
+
mbeanInterface
.
getName
();
final
Descriptor
interf
Descriptor
=
final
Descriptor
className
Descriptor
=
new
ImmutableDescriptor
(
interfaceClassName
);
new
ImmutableDescriptor
(
interfaceClassName
);
final
Descriptor
mbeanDescriptor
=
getBasicMBeanDescriptor
();
final
Descriptor
mbeanDescriptor
=
getBasicMBeanDescriptor
();
final
Descriptor
annotatedDescriptor
=
final
Descriptor
annotatedDescriptor
=
Introspector
.
descriptorForElement
(
mbeanInterface
);
Introspector
.
descriptorForElement
(
mbeanInterface
);
final
Descriptor
descriptor
=
final
Descriptor
descriptor
=
DescriptorCache
.
getInstance
().
union
(
interfDescriptor
,
DescriptorCache
.
getInstance
().
union
(
classNameDescriptor
,
mbeanDescriptor
,
mbeanDescriptor
,
annotatedDescriptor
);
annotatedDescriptor
);
...
@@ -388,20 +403,24 @@ abstract class MBeanIntrospector<M> {
...
@@ -388,20 +403,24 @@ abstract class MBeanIntrospector<M> {
* Return the MBeanInfo for the given resource, based on the given
* Return the MBeanInfo for the given resource, based on the given
* per-interface data.
* per-interface data.
*/
*/
final
MBeanInfo
getMBeanInfo
(
Object
resource
,
PerInterface
<
M
>
perInterface
)
{
final
MBeanInfo
getMBeanInfo
(
Object
resource
,
PerInterface
<
M
>
perInterface
)
throws
NotCompliantMBeanException
{
MBeanInfo
mbi
=
MBeanInfo
mbi
=
getClassMBeanInfo
(
resource
.
getClass
(),
perInterface
);
getClassMBeanInfo
(
resource
.
getClass
(),
perInterface
);
MBeanNotificationInfo
[]
notifs
=
findNotifications
(
resource
);
MBeanNotificationInfo
[]
notifs
=
findNotifications
(
resource
);
if
(
notifs
==
null
||
notifs
.
length
==
0
)
Descriptor
d
=
getSpecificMBeanDescriptor
();
boolean
anyNotifs
=
(
notifs
!=
null
&&
notifs
.
length
>
0
);
if
(!
anyNotifs
&&
ImmutableDescriptor
.
EMPTY_DESCRIPTOR
.
equals
(
d
))
return
mbi
;
return
mbi
;
else
{
else
{
d
=
ImmutableDescriptor
.
union
(
d
,
mbi
.
getDescriptor
());
return
new
MBeanInfo
(
mbi
.
getClassName
(),
return
new
MBeanInfo
(
mbi
.
getClassName
(),
mbi
.
getDescription
(),
mbi
.
getDescription
(),
mbi
.
getAttributes
(),
mbi
.
getAttributes
(),
mbi
.
getConstructors
(),
mbi
.
getConstructors
(),
mbi
.
getOperations
(),
mbi
.
getOperations
(),
notifs
,
notifs
,
mbi
.
getDescriptor
()
);
d
);
}
}
}
}
...
@@ -446,7 +465,7 @@ abstract class MBeanIntrospector<M> {
...
@@ -446,7 +465,7 @@ abstract class MBeanIntrospector<M> {
return
null
;
return
null
;
MBeanNotificationInfo
[]
mbn
=
MBeanNotificationInfo
[]
mbn
=
((
NotificationBroadcaster
)
moi
).
getNotificationInfo
();
((
NotificationBroadcaster
)
moi
).
getNotificationInfo
();
if
(
mbn
==
null
)
if
(
mbn
==
null
||
mbn
.
length
==
0
)
return
null
;
return
null
;
MBeanNotificationInfo
[]
result
=
MBeanNotificationInfo
[]
result
=
new
MBeanNotificationInfo
[
mbn
.
length
];
new
MBeanNotificationInfo
[
mbn
.
length
];
...
...
src/share/classes/com/sun/jmx/mbeanserver/MBeanSupport.java
浏览文件 @
ae942eac
...
@@ -38,6 +38,7 @@ import javax.management.MBeanServer;
...
@@ -38,6 +38,7 @@ import javax.management.MBeanServer;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.ObjectName
;
import
javax.management.ObjectName
;
import
javax.management.ReflectionException
;
import
javax.management.ReflectionException
;
import
javax.management.openmbean.MXBeanMappingFactory
;
/**
/**
* Base class for MBeans. There is one instance of this class for
* Base class for MBeans. There is one instance of this class for
...
@@ -121,24 +122,26 @@ import javax.management.ReflectionException;
...
@@ -121,24 +122,26 @@ import javax.management.ReflectionException;
public
abstract
class
MBeanSupport
<
M
>
public
abstract
class
MBeanSupport
<
M
>
implements
DynamicMBean2
,
MBeanRegistration
{
implements
DynamicMBean2
,
MBeanRegistration
{
<
T
>
MBeanSupport
(
T
resource
,
Class
<
T
>
mbeanInterface
)
<
T
>
MBeanSupport
(
T
resource
,
Class
<
T
>
mbeanInterfaceType
,
MXBeanMappingFactory
mappingFactory
)
throws
NotCompliantMBeanException
{
throws
NotCompliantMBeanException
{
if
(
mbeanInterface
==
null
)
if
(
mbeanInterface
Type
==
null
)
throw
new
NotCompliantMBeanException
(
"Null MBean interface"
);
throw
new
NotCompliantMBeanException
(
"Null MBean interface"
);
if
(!
mbeanInterface
.
isInstance
(
resource
))
{
if
(!
mbeanInterface
Type
.
isInstance
(
resource
))
{
final
String
msg
=
final
String
msg
=
"Resource class "
+
resource
.
getClass
().
getName
()
+
"Resource class "
+
resource
.
getClass
().
getName
()
+
" is not an instance of "
+
mbeanInterface
.
getName
();
" is not an instance of "
+
mbeanInterface
Type
.
getName
();
throw
new
NotCompliantMBeanException
(
msg
);
throw
new
NotCompliantMBeanException
(
msg
);
}
}
this
.
resource
=
resource
;
this
.
resource
=
resource
;
MBeanIntrospector
<
M
>
introspector
=
getMBeanIntrospector
();
MBeanIntrospector
<
M
>
introspector
=
getMBeanIntrospector
(
mappingFactory
);
this
.
perInterface
=
introspector
.
getPerInterface
(
mbeanInterface
);
this
.
perInterface
=
introspector
.
getPerInterface
(
mbeanInterface
Type
);
this
.
mbeanInfo
=
introspector
.
getMBeanInfo
(
resource
,
perInterface
);
this
.
mbeanInfo
=
introspector
.
getMBeanInfo
(
resource
,
perInterface
);
}
}
/** Return the appropriate introspector for this type of MBean. */
/** Return the appropriate introspector for this type of MBean. */
abstract
MBeanIntrospector
<
M
>
getMBeanIntrospector
();
abstract
MBeanIntrospector
<
M
>
getMBeanIntrospector
(
MXBeanMappingFactory
mappingFactory
);
/**
/**
* Return a cookie for this MBean. This cookie will be passed to
* Return a cookie for this MBean. This cookie will be passed to
...
@@ -162,9 +165,8 @@ public abstract class MBeanSupport<M>
...
@@ -162,9 +165,8 @@ public abstract class MBeanSupport<M>
public
final
ObjectName
preRegister
(
MBeanServer
server
,
ObjectName
name
)
public
final
ObjectName
preRegister
(
MBeanServer
server
,
ObjectName
name
)
throws
Exception
{
throws
Exception
{
if
(
resource
instanceof
MBeanRegistration
)
if
(
resource
instanceof
MBeanRegistration
)
return
((
MBeanRegistration
)
resource
).
preRegister
(
server
,
name
);
name
=
((
MBeanRegistration
)
resource
).
preRegister
(
server
,
name
);
else
return
name
;
return
name
;
}
}
public
final
void
preRegister2
(
MBeanServer
server
,
ObjectName
name
)
public
final
void
preRegister2
(
MBeanServer
server
,
ObjectName
name
)
...
...
src/share/classes/com/sun/jmx/mbeanserver/MXBeanIntrospector.java
浏览文件 @
ae942eac
...
@@ -25,18 +25,26 @@
...
@@ -25,18 +25,26 @@
package
com.sun.jmx.mbeanserver
;
package
com.sun.jmx.mbeanserver
;
import
com.sun.jmx.mbeanserver.MBeanIntrospector.MBeanInfoMap
;
import
com.sun.jmx.mbeanserver.MBeanIntrospector.PerInterfaceMap
;
import
java.lang.annotation.Annotation
;
import
java.lang.annotation.Annotation
;
import
java.lang.ref.WeakReference
;
import
java.lang.reflect.GenericArrayType
;
import
java.lang.reflect.GenericArrayType
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Type
;
import
java.lang.reflect.Type
;
import
java.util.Map
;
import
java.util.WeakHashMap
;
import
javax.management.Descriptor
;
import
javax.management.Descriptor
;
import
javax.management.ImmutableDescriptor
;
import
javax.management.ImmutableDescriptor
;
import
javax.management.IntrospectionException
;
import
javax.management.JMX
;
import
javax.management.MBeanAttributeInfo
;
import
javax.management.MBeanAttributeInfo
;
import
javax.management.MBeanException
;
import
javax.management.MBeanException
;
import
javax.management.MBeanOperationInfo
;
import
javax.management.MBeanOperationInfo
;
import
javax.management.MBeanParameterInfo
;
import
javax.management.MBeanParameterInfo
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.openmbean.MXBeanMappingFactory
;
import
javax.management.openmbean.OpenMBeanAttributeInfoSupport
;
import
javax.management.openmbean.OpenMBeanAttributeInfoSupport
;
import
javax.management.openmbean.OpenMBeanOperationInfoSupport
;
import
javax.management.openmbean.OpenMBeanOperationInfoSupport
;
import
javax.management.openmbean.OpenMBeanParameterInfo
;
import
javax.management.openmbean.OpenMBeanParameterInfo
;
...
@@ -49,10 +57,36 @@ import javax.management.openmbean.OpenType;
...
@@ -49,10 +57,36 @@ import javax.management.openmbean.OpenType;
* @since 1.6
* @since 1.6
*/
*/
class
MXBeanIntrospector
extends
MBeanIntrospector
<
ConvertingMethod
>
{
class
MXBeanIntrospector
extends
MBeanIntrospector
<
ConvertingMethod
>
{
private
static
final
MXBeanIntrospector
instance
=
new
MXBeanIntrospector
();
/* We keep one MXBeanIntrospector per MXBeanMappingFactory, since the results
* of the introspection depend on the factory. The MXBeanIntrospector
* has a reference back to the factory, so we wrap it in a WeakReference.
* It will be strongly referenced by any MXBeanSupport instances using it;
* if there are none then it is OK to gc it.
*/
private
static
final
Map
<
MXBeanMappingFactory
,
WeakReference
<
MXBeanIntrospector
>>
map
=
new
WeakHashMap
<
MXBeanMappingFactory
,
WeakReference
<
MXBeanIntrospector
>>();
static
MXBeanIntrospector
getInstance
(
MXBeanMappingFactory
factory
)
{
if
(
factory
==
null
)
factory
=
MXBeanMappingFactory
.
DEFAULT
;
synchronized
(
map
)
{
MXBeanIntrospector
intro
;
WeakReference
<
MXBeanIntrospector
>
wr
=
map
.
get
(
factory
);
if
(
wr
!=
null
)
{
intro
=
wr
.
get
();
if
(
intro
!=
null
)
return
intro
;
}
intro
=
new
MXBeanIntrospector
(
factory
);
wr
=
new
WeakReference
<
MXBeanIntrospector
>(
intro
);
map
.
put
(
factory
,
wr
);
return
intro
;
}
}
static
MXBeanIntrospector
getInstance
(
)
{
private
MXBeanIntrospector
(
MXBeanMappingFactory
factory
)
{
return
instance
;
this
.
mappingFactory
=
factory
;
}
}
@Override
@Override
...
@@ -78,7 +112,7 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
...
@@ -78,7 +112,7 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
@Override
@Override
ConvertingMethod
mFrom
(
Method
m
)
{
ConvertingMethod
mFrom
(
Method
m
)
{
return
ConvertingMethod
.
from
(
m
);
return
ConvertingMethod
.
from
(
m
,
mappingFactory
);
}
}
@Override
@Override
...
@@ -139,7 +173,8 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
...
@@ -139,7 +173,8 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
@Override
@Override
MBeanAttributeInfo
getMBeanAttributeInfo
(
String
attributeName
,
MBeanAttributeInfo
getMBeanAttributeInfo
(
String
attributeName
,
ConvertingMethod
getter
,
ConvertingMethod
setter
)
{
ConvertingMethod
getter
,
ConvertingMethod
setter
)
throws
IntrospectionException
{
final
boolean
isReadable
=
(
getter
!=
null
);
final
boolean
isReadable
=
(
getter
!=
null
);
final
boolean
isWritable
=
(
setter
!=
null
);
final
boolean
isWritable
=
(
setter
!=
null
);
...
@@ -222,14 +257,14 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
...
@@ -222,14 +257,14 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
Introspector
.
descriptorForAnnotations
(
annots
[
i
]));
Introspector
.
descriptorForAnnotations
(
annots
[
i
]));
final
MBeanParameterInfo
pi
;
final
MBeanParameterInfo
pi
;
if
(
canUseOpenInfo
(
originalType
))
{
if
(
canUseOpenInfo
(
originalType
))
{
pi
=
new
OpenMBeanParameterInfoSupport
(
"p"
+
i
,
pi
=
new
OpenMBeanParameterInfoSupport
(
paramName
,
paramDescription
,
paramDescription
,
openType
,
openType
,
descriptor
);
descriptor
);
}
else
{
}
else
{
openParameterTypes
=
false
;
openParameterTypes
=
false
;
pi
=
new
MBeanParameterInfo
(
pi
=
new
MBeanParameterInfo
(
"p"
+
i
,
paramName
,
originalTypeString
(
originalType
),
originalTypeString
(
originalType
),
paramDescription
,
paramDescription
,
descriptor
);
descriptor
);
...
@@ -291,6 +326,17 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
...
@@ -291,6 +326,17 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
return
ImmutableDescriptor
.
EMPTY_DESCRIPTOR
;
return
ImmutableDescriptor
.
EMPTY_DESCRIPTOR
;
}
}
@Override
Descriptor
getSpecificMBeanDescriptor
()
{
if
(
mappingFactory
==
MXBeanMappingFactory
.
DEFAULT
)
return
ImmutableDescriptor
.
EMPTY_DESCRIPTOR
;
else
{
return
new
ImmutableDescriptor
(
JMX
.
MXBEAN_MAPPING_FACTORY_CLASS_FIELD
+
"="
+
mappingFactory
.
getClass
().
getName
());
}
}
private
static
Descriptor
typeDescriptor
(
OpenType
openType
,
private
static
Descriptor
typeDescriptor
(
OpenType
openType
,
Type
originalType
)
{
Type
originalType
)
{
return
new
ImmutableDescriptor
(
return
new
ImmutableDescriptor
(
...
@@ -331,8 +377,10 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
...
@@ -331,8 +377,10 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
return
type
.
toString
();
return
type
.
toString
();
}
}
private
static
final
PerInterfaceMap
<
ConvertingMethod
>
private
final
PerInterfaceMap
<
ConvertingMethod
>
perInterfaceMap
=
new
PerInterfaceMap
<
ConvertingMethod
>();
perInterfaceMap
=
new
PerInterfaceMap
<
ConvertingMethod
>();
private
static
final
MBeanInfoMap
mbeanInfoMap
=
new
MBeanInfoMap
();
private
final
MBeanInfoMap
mbeanInfoMap
=
new
MBeanInfoMap
();
private
final
MXBeanMappingFactory
mappingFactory
;
}
}
src/share/classes/com/sun/jmx/mbeanserver/MXBeanLookup.java
浏览文件 @
ae942eac
...
@@ -25,15 +25,21 @@
...
@@ -25,15 +25,21 @@
package
com.sun.jmx.mbeanserver
;
package
com.sun.jmx.mbeanserver
;
import
com.sun.jmx.remote.util.EnvHelp
;
import
java.io.InvalidObjectException
;
import
static
com
.
sun
.
jmx
.
mbeanserver
.
Util
.*;
import
static
com
.
sun
.
jmx
.
mbeanserver
.
Util
.*;
import
java.util.Map
;
import
java.util.Map
;
import
java.lang.ref.WeakReference
;
import
java.lang.ref.WeakReference
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.Proxy
;
import
java.lang.reflect.Proxy
;
import
java.security.AccessController
;
import
javax.management.InstanceAlreadyExistsException
;
import
javax.management.JMX
;
import
javax.management.JMX
;
import
javax.management.MBeanServerConnection
;
import
javax.management.MBeanServerConnection
;
import
javax.management.MBeanServerInvocationHandler
;
import
javax.management.MBeanServerInvocationHandler
;
import
javax.management.MalformedObjectNameException
;
import
javax.management.ObjectName
;
import
javax.management.ObjectName
;
import
javax.management.openmbean.OpenDataException
;
/**
/**
* @since 1.6
* @since 1.6
...
@@ -80,71 +86,199 @@ import javax.management.ObjectName;
...
@@ -80,71 +86,199 @@ import javax.management.ObjectName;
*
*
* From the above, it is clear that the logic for getX on an MXBean is
* From the above, it is clear that the logic for getX on an MXBean is
* the same as for setX on a proxy, and vice versa.
* the same as for setX on a proxy, and vice versa.
*
* The above describes the logic for "plain" MXBeanLookup, represented
* by MXBeanLookup.Plain. When namespaces enter the picture, we see
* MXBeanLookup.Prefix. Here, the idea is that the name of the ModuleMXBean
* might be a//m:m=m. In this case, we don't accept a reference to
* an MXBean object, since that would require different namespaces to know
* each others' objects. We only accept proxies. Suppose you have a proxy
* for a//m:m=m, call it moduleProxy, and you call
* moduleProxy.setProduct(productProxy). Then if productProxy is for
* a//p:p=p we should convert this to just p:p=p. If productProxy is for
* a//b//p:p=p we should convert it to b//p:p=p. Conversely, if getProduct
* returns an ObjectName like b//p:p=p then we should convert it into a proxy
* for a//b//p:p=p.
*/
*/
public
class
MXBeanLookup
{
public
abstract
class
MXBeanLookup
{
private
MXBeanLookup
(
MBeanServerConnection
mbsc
)
{
private
MXBeanLookup
(
MBeanServerConnection
mbsc
)
{
this
.
mbsc
=
mbsc
;
this
.
mbsc
=
mbsc
;
}
}
static
MXBeanLookup
lookupFor
(
MBeanServerConnection
mbsc
)
{
static
MXBeanLookup
lookupFor
(
MBeanServerConnection
mbsc
,
String
prefix
)
{
synchronized
(
mbscToLookup
)
{
if
(
prefix
==
null
)
WeakReference
<
MXBeanLookup
>
weakLookup
=
mbscToLookup
.
get
(
mbsc
);
return
Plain
.
lookupFor
(
mbsc
);
MXBeanLookup
lookup
=
(
weakLookup
==
null
)
?
null
:
weakLookup
.
get
();
else
if
(
lookup
==
null
)
{
return
new
Prefix
(
mbsc
,
prefix
);
lookup
=
new
MXBeanLookup
(
mbsc
);
}
mbscToLookup
.
put
(
mbsc
,
new
WeakReference
<
MXBeanLookup
>(
lookup
));
abstract
<
T
>
T
objectNameToMXBean
(
ObjectName
name
,
Class
<
T
>
type
)
throws
InvalidObjectException
;
abstract
ObjectName
mxbeanToObjectName
(
Object
mxbean
)
throws
OpenDataException
;
static
class
Plain
extends
MXBeanLookup
{
Plain
(
MBeanServerConnection
mbsc
)
{
super
(
mbsc
);
}
static
Plain
lookupFor
(
MBeanServerConnection
mbsc
)
{
synchronized
(
mbscToLookup
)
{
WeakReference
<
Plain
>
weakLookup
=
mbscToLookup
.
get
(
mbsc
);
Plain
lookup
=
(
weakLookup
==
null
)
?
null
:
weakLookup
.
get
();
if
(
lookup
==
null
)
{
lookup
=
new
Plain
(
mbsc
);
mbscToLookup
.
put
(
mbsc
,
new
WeakReference
<
Plain
>(
lookup
));
}
return
lookup
;
}
}
return
lookup
;
}
}
}
synchronized
<
T
>
T
objectNameToMXBean
(
ObjectName
name
,
Class
<
T
>
type
)
{
@Override
WeakReference
<
Object
>
wr
=
objectNameToProxy
.
get
(
name
);
synchronized
<
T
>
T
objectNameToMXBean
(
ObjectName
name
,
Class
<
T
>
type
)
{
if
(
wr
!=
null
)
{
WeakReference
<
Object
>
wr
=
objectNameToProxy
.
get
(
name
);
Object
proxy
=
wr
.
get
();
if
(
wr
!=
null
)
{
if
(
type
.
isInstance
(
proxy
))
Object
proxy
=
wr
.
get
();
return
type
.
cast
(
proxy
);
if
(
type
.
isInstance
(
proxy
))
return
type
.
cast
(
proxy
);
}
T
proxy
=
JMX
.
newMXBeanProxy
(
mbsc
,
name
,
type
);
objectNameToProxy
.
put
(
name
,
new
WeakReference
<
Object
>(
proxy
));
return
proxy
;
}
@Override
synchronized
ObjectName
mxbeanToObjectName
(
Object
mxbean
)
throws
OpenDataException
{
String
wrong
;
if
(
mxbean
instanceof
Proxy
)
{
InvocationHandler
ih
=
Proxy
.
getInvocationHandler
(
mxbean
);
if
(
ih
instanceof
MBeanServerInvocationHandler
)
{
MBeanServerInvocationHandler
mbsih
=
(
MBeanServerInvocationHandler
)
ih
;
if
(
mbsih
.
getMBeanServerConnection
().
equals
(
mbsc
))
return
mbsih
.
getObjectName
();
else
wrong
=
"proxy for a different MBeanServer"
;
}
else
wrong
=
"not a JMX proxy"
;
}
else
{
ObjectName
name
=
mxbeanToObjectName
.
get
(
mxbean
);
if
(
name
!=
null
)
return
name
;
wrong
=
"not an MXBean registered in this MBeanServer"
;
}
String
s
=
(
mxbean
==
null
)
?
"null"
:
"object of type "
+
mxbean
.
getClass
().
getName
();
throw
new
OpenDataException
(
"Could not convert "
+
s
+
" to an ObjectName: "
+
wrong
);
// Message will be strange if mxbean is null but it is not
// supposed to be.
}
synchronized
void
addReference
(
ObjectName
name
,
Object
mxbean
)
throws
InstanceAlreadyExistsException
{
ObjectName
existing
=
mxbeanToObjectName
.
get
(
mxbean
);
if
(
existing
!=
null
)
{
String
multiname
=
AccessController
.
doPrivileged
(
new
GetPropertyAction
(
"jmx.mxbean.multiname"
));
if
(!
"true"
.
equalsIgnoreCase
(
multiname
))
{
throw
new
InstanceAlreadyExistsException
(
"MXBean already registered with name "
+
existing
);
}
}
mxbeanToObjectName
.
put
(
mxbean
,
name
);
}
synchronized
boolean
removeReference
(
ObjectName
name
,
Object
mxbean
)
{
if
(
name
.
equals
(
mxbeanToObjectName
.
get
(
mxbean
)))
{
mxbeanToObjectName
.
remove
(
mxbean
);
return
true
;
}
else
return
false
;
/* removeReference can be called when the above condition fails,
* notably if you try to register the same MXBean twice.
*/
}
}
T
proxy
=
JMX
.
newMXBeanProxy
(
mbsc
,
name
,
type
);
objectNameToProxy
.
put
(
name
,
new
WeakReference
<
Object
>(
proxy
));
private
final
WeakIdentityHashMap
<
Object
,
ObjectName
>
return
proxy
;
mxbeanToObjectName
=
WeakIdentityHashMap
.
make
();
private
final
Map
<
ObjectName
,
WeakReference
<
Object
>>
objectNameToProxy
=
newMap
();
private
static
WeakIdentityHashMap
<
MBeanServerConnection
,
WeakReference
<
Plain
>>
mbscToLookup
=
WeakIdentityHashMap
.
make
();
}
}
synchronized
ObjectName
mxbeanToObjectName
(
Object
mxbean
)
{
private
static
class
Prefix
extends
MXBeanLookup
{
if
(
mxbean
instanceof
Proxy
)
{
private
final
String
prefix
;
InvocationHandler
ih
=
Proxy
.
getInvocationHandler
(
mxbean
);
if
(
ih
instanceof
MBeanServerInvocationHandler
)
{
Prefix
(
MBeanServerConnection
mbsc
,
String
prefix
)
{
MBeanServerInvocationHandler
mbsih
=
super
(
mbsc
);
(
MBeanServerInvocationHandler
)
ih
;
this
.
prefix
=
prefix
;
if
(
mbsih
.
getMBeanServerConnection
().
equals
(
mbsc
))
}
return
mbsih
.
getObjectName
();
@Override
<
T
>
T
objectNameToMXBean
(
ObjectName
name
,
Class
<
T
>
type
)
throws
InvalidObjectException
{
String
domain
=
prefix
+
name
.
getDomain
();
try
{
name
=
switchDomain
(
domain
,
name
);
}
catch
(
MalformedObjectNameException
e
)
{
throw
EnvHelp
.
initCause
(
new
InvalidObjectException
(
e
.
getMessage
()),
e
);
}
return
JMX
.
newMXBeanProxy
(
mbsc
,
name
,
type
);
}
@Override
ObjectName
mxbeanToObjectName
(
Object
mxbean
)
throws
OpenDataException
{
ObjectName
name
=
proxyToObjectName
(
mxbean
);
String
domain
=
name
.
getDomain
();
if
(!
domain
.
startsWith
(
prefix
))
{
throw
new
OpenDataException
(
"Proxy's name does not start with "
+
prefix
+
": "
+
name
);
}
}
return
null
;
try
{
}
else
name
=
switchDomain
(
domain
.
substring
(
prefix
.
length
()),
name
);
return
mxbeanToObjectName
.
get
(
mxbean
);
}
catch
(
MalformedObjectNameException
e
)
{
throw
EnvHelp
.
initCause
(
new
OpenDataException
(
e
.
getMessage
()),
e
);
}
return
name
;
}
}
ObjectName
proxyToObjectName
(
Object
proxy
)
{
InvocationHandler
ih
=
Proxy
.
getInvocationHandler
(
proxy
);
if
(
ih
instanceof
MBeanServerInvocationHandler
)
{
MBeanServerInvocationHandler
mbsih
=
(
MBeanServerInvocationHandler
)
ih
;
if
(
mbsih
.
getMBeanServerConnection
().
equals
(
mbsc
))
return
mbsih
.
getObjectName
();
}
return
null
;
}
static
MXBeanLookup
getLookup
()
{
return
currentLookup
.
get
();
}
}
s
ynchronized
void
addReference
(
ObjectName
name
,
Object
mxbean
)
{
s
tatic
void
setLookup
(
MXBeanLookup
lookup
)
{
mxbeanToObjectName
.
put
(
mxbean
,
name
);
currentLookup
.
set
(
lookup
);
}
}
synchronized
boolean
removeReference
(
ObjectName
name
,
Object
mxbean
)
{
// Method temporarily added until we have ObjectName.switchDomain in the
if
(
name
.
equals
(
mxbeanToObjectName
.
get
(
mxbean
)))
{
// public API. Note that this method DOES NOT PRESERVE the order of
mxbeanToObjectName
.
remove
(
mxbean
);
// keys in the ObjectName so it must not be used in the final release.
return
true
;
static
ObjectName
switchDomain
(
String
domain
,
ObjectName
name
)
}
else
throws
MalformedObjectNameException
{
return
false
;
return
new
ObjectName
(
domain
,
name
.
getKeyPropertyList
());
/* removeReference can be called when the above condition fails,
* notably if you try to register the same MXBean twice.
*/
}
}
private
final
MBeanServerConnection
mbsc
;
private
static
final
ThreadLocal
<
MXBeanLookup
>
currentLookup
=
private
final
WeakIdentityHashMap
<
Object
,
ObjectName
>
new
ThreadLocal
<
MXBeanLookup
>();
mxbeanToObjectName
=
WeakIdentityHashMap
.
make
();
private
final
Map
<
ObjectName
,
WeakReference
<
Object
>>
final
MBeanServerConnection
mbsc
;
objectNameToProxy
=
newMap
();
private
static
WeakIdentityHashMap
<
MBeanServerConnection
,
WeakReference
<
MXBeanLookup
>>
mbscToLookup
=
WeakIdentityHashMap
.
make
();
}
}
src/share/classes/com/sun/jmx/mbeanserver/MXBeanProxy.java
浏览文件 @
ae942eac
...
@@ -27,14 +27,15 @@ package com.sun.jmx.mbeanserver;
...
@@ -27,14 +27,15 @@ package com.sun.jmx.mbeanserver;
import
static
com
.
sun
.
jmx
.
mbeanserver
.
Util
.*;
import
static
com
.
sun
.
jmx
.
mbeanserver
.
Util
.*;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.Map
;
import
java.util.Map
;
import
javax.management.Attribute
;
import
javax.management.Attribute
;
import
javax.management.MBeanServerConnection
;
import
javax.management.MBeanServerConnection
;
import
javax.management.MalformedObjectNameException
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.ObjectName
;
import
javax.management.ObjectName
;
import
javax.management.openmbean.MXBeanMappingFactory
;
/**
/**
<p>Helper class for an {@link InvocationHandler} that forwards methods from an
<p>Helper class for an {@link InvocationHandler} that forwards methods from an
...
@@ -46,8 +47,7 @@ import javax.management.ObjectName;
...
@@ -46,8 +47,7 @@ import javax.management.ObjectName;
@since 1.6
@since 1.6
*/
*/
public
class
MXBeanProxy
{
public
class
MXBeanProxy
{
public
MXBeanProxy
(
Class
<?>
mxbeanInterface
)
public
MXBeanProxy
(
Class
<?>
mxbeanInterface
,
MXBeanMappingFactory
factory
)
{
throws
IllegalArgumentException
{
if
(
mxbeanInterface
==
null
)
if
(
mxbeanInterface
==
null
)
throw
new
IllegalArgumentException
(
"Null parameter"
);
throw
new
IllegalArgumentException
(
"Null parameter"
);
...
@@ -55,14 +55,15 @@ public class MXBeanProxy {
...
@@ -55,14 +55,15 @@ public class MXBeanProxy {
final
MBeanAnalyzer
<
ConvertingMethod
>
analyzer
;
final
MBeanAnalyzer
<
ConvertingMethod
>
analyzer
;
try
{
try
{
analyzer
=
analyzer
=
MXBeanIntrospector
.
getInstance
().
getAnalyzer
(
mxbeanInterface
);
MXBeanIntrospector
.
getInstance
(
factory
).
getAnalyzer
(
mxbeanInterface
);
}
catch
(
NotCompliantMBeanException
e
)
{
}
catch
(
NotCompliantMBeanException
e
)
{
throw
new
IllegalArgumentException
(
e
);
throw
new
IllegalArgumentException
(
e
);
}
}
analyzer
.
visit
(
new
Visitor
());
analyzer
.
visit
(
new
Visitor
());
}
}
private
class
Visitor
implements
MBeanAnalyzer
.
MBeanVisitor
<
ConvertingMethod
>
{
private
class
Visitor
implements
MBeanAnalyzer
.
MBeanVisitor
<
ConvertingMethod
,
RuntimeException
>
{
public
void
visitAttribute
(
String
attributeName
,
public
void
visitAttribute
(
String
attributeName
,
ConvertingMethod
getter
,
ConvertingMethod
getter
,
ConvertingMethod
setter
)
{
ConvertingMethod
setter
)
{
...
@@ -160,10 +161,29 @@ public class MXBeanProxy {
...
@@ -160,10 +161,29 @@ public class MXBeanProxy {
Handler
handler
=
handlerMap
.
get
(
method
);
Handler
handler
=
handlerMap
.
get
(
method
);
ConvertingMethod
cm
=
handler
.
getConvertingMethod
();
ConvertingMethod
cm
=
handler
.
getConvertingMethod
();
MXBeanLookup
lookup
=
MXBeanLookup
.
lookupFor
(
mbsc
);
String
prefix
=
extractPrefix
(
name
);
Object
[]
openArgs
=
cm
.
toOpenParameters
(
lookup
,
args
);
MXBeanLookup
lookup
=
MXBeanLookup
.
lookupFor
(
mbsc
,
prefix
);
Object
result
=
handler
.
invoke
(
mbsc
,
name
,
openArgs
);
MXBeanLookup
oldLookup
=
MXBeanLookup
.
getLookup
();
return
cm
.
fromOpenReturnValue
(
lookup
,
result
);
try
{
MXBeanLookup
.
setLookup
(
lookup
);
Object
[]
openArgs
=
cm
.
toOpenParameters
(
lookup
,
args
);
Object
result
=
handler
.
invoke
(
mbsc
,
name
,
openArgs
);
return
cm
.
fromOpenReturnValue
(
lookup
,
result
);
}
finally
{
MXBeanLookup
.
setLookup
(
oldLookup
);
}
}
private
static
String
extractPrefix
(
ObjectName
name
)
throws
MalformedObjectNameException
{
String
domain
=
name
.
getDomain
();
int
slashslash
=
domain
.
lastIndexOf
(
"//"
);
if
(
slashslash
>
0
&&
domain
.
charAt
(
slashslash
-
1
)
==
'/'
)
slashslash
--;
if
(
slashslash
>=
0
)
return
domain
.
substring
(
0
,
slashslash
+
2
);
else
return
null
;
}
}
private
final
Map
<
Method
,
Handler
>
handlerMap
=
newMap
();
private
final
Map
<
Method
,
Handler
>
handlerMap
=
newMap
();
...
...
src/share/classes/com/sun/jmx/mbeanserver/MXBeanSupport.java
浏览文件 @
ae942eac
...
@@ -35,6 +35,8 @@ import javax.management.JMX;
...
@@ -35,6 +35,8 @@ import javax.management.JMX;
import
javax.management.MBeanServer
;
import
javax.management.MBeanServer
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.ObjectName
;
import
javax.management.ObjectName
;
import
javax.management.openmbean.MXBeanMappingFactory
;
import
javax.management.openmbean.MXBeanMappingFactoryClass
;
/**
/**
* Base class for MXBeans.
* Base class for MXBeans.
...
@@ -61,14 +63,16 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
...
@@ -61,14 +63,16 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
if it does not implement the class {@code mxbeanInterface} or if
if it does not implement the class {@code mxbeanInterface} or if
that class is not a valid MXBean interface.
that class is not a valid MXBean interface.
*/
*/
public
<
T
>
MXBeanSupport
(
T
resource
,
Class
<
T
>
mxbeanInterface
)
public
<
T
>
MXBeanSupport
(
T
resource
,
Class
<
T
>
mxbeanInterface
,
MXBeanMappingFactory
mappingFactory
)
throws
NotCompliantMBeanException
{
throws
NotCompliantMBeanException
{
super
(
resource
,
mxbeanInterface
);
super
(
resource
,
mxbeanInterface
,
mappingFactory
);
}
}
@Override
@Override
MBeanIntrospector
<
ConvertingMethod
>
getMBeanIntrospector
()
{
MBeanIntrospector
<
ConvertingMethod
>
return
MXBeanIntrospector
.
getInstance
();
getMBeanIntrospector
(
MXBeanMappingFactory
mappingFactory
)
{
return
MXBeanIntrospector
.
getInstance
(
mappingFactory
);
}
}
@Override
@Override
...
@@ -76,8 +80,7 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
...
@@ -76,8 +80,7 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
return
mxbeanLookup
;
return
mxbeanLookup
;
}
}
static
Class
<?>
findMXBeanInterface
(
Class
<?>
resourceClass
)
static
<
T
>
Class
<?
super
T
>
findMXBeanInterface
(
Class
<
T
>
resourceClass
)
{
throws
IllegalArgumentException
{
if
(
resourceClass
==
null
)
if
(
resourceClass
==
null
)
throw
new
IllegalArgumentException
(
"Null resource class"
);
throw
new
IllegalArgumentException
(
"Null resource class"
);
final
Set
<
Class
<?>>
intfs
=
transitiveInterfaces
(
resourceClass
);
final
Set
<
Class
<?>>
intfs
=
transitiveInterfaces
(
resourceClass
);
...
@@ -104,7 +107,7 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
...
@@ -104,7 +107,7 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
throw
new
IllegalArgumentException
(
msg
);
throw
new
IllegalArgumentException
(
msg
);
}
}
if
(
candidates
.
iterator
().
hasNext
())
{
if
(
candidates
.
iterator
().
hasNext
())
{
return
candidates
.
iterator
().
next
(
);
return
Util
.
cast
(
candidates
.
iterator
().
next
()
);
}
else
{
}
else
{
final
String
msg
=
final
String
msg
=
"Class "
+
resourceClass
.
getName
()
+
"Class "
+
resourceClass
.
getName
()
+
...
@@ -116,7 +119,7 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
...
@@ -116,7 +119,7 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
/* Return all interfaces inherited by this class, directly or
/* Return all interfaces inherited by this class, directly or
* indirectly through the parent class and interfaces.
* indirectly through the parent class and interfaces.
*/
*/
private
static
Set
<
Class
<?>>
transitiveInterfaces
(
Class
c
)
{
private
static
Set
<
Class
<?>>
transitiveInterfaces
(
Class
<?>
c
)
{
Set
<
Class
<?>>
set
=
newSet
();
Set
<
Class
<?>>
set
=
newSet
();
transitiveInterfaces
(
c
,
set
);
transitiveInterfaces
(
c
,
set
);
return
set
;
return
set
;
...
@@ -127,7 +130,7 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
...
@@ -127,7 +130,7 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
if
(
c
.
isInterface
())
if
(
c
.
isInterface
())
intfs
.
add
(
c
);
intfs
.
add
(
c
);
transitiveInterfaces
(
c
.
getSuperclass
(),
intfs
);
transitiveInterfaces
(
c
.
getSuperclass
(),
intfs
);
for
(
Class
sup
:
c
.
getInterfaces
())
for
(
Class
<?>
sup
:
c
.
getInterfaces
())
transitiveInterfaces
(
sup
,
intfs
);
transitiveInterfaces
(
sup
,
intfs
);
}
}
...
@@ -157,12 +160,7 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
...
@@ -157,12 +160,7 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
// eventually we could have some logic to supply a default name
// eventually we could have some logic to supply a default name
synchronized
(
lock
)
{
synchronized
(
lock
)
{
if
(
this
.
objectName
!=
null
)
{
this
.
mxbeanLookup
=
MXBeanLookup
.
Plain
.
lookupFor
(
server
);
final
String
msg
=
"MXBean already registered with name "
+
this
.
objectName
;
throw
new
InstanceAlreadyExistsException
(
msg
);
}
this
.
mxbeanLookup
=
MXBeanLookup
.
lookupFor
(
server
);
this
.
mxbeanLookup
.
addReference
(
name
,
getResource
());
this
.
mxbeanLookup
.
addReference
(
name
,
getResource
());
this
.
objectName
=
name
;
this
.
objectName
=
name
;
}
}
...
@@ -171,12 +169,20 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
...
@@ -171,12 +169,20 @@ public class MXBeanSupport extends MBeanSupport<ConvertingMethod> {
@Override
@Override
public
void
unregister
()
{
public
void
unregister
()
{
synchronized
(
lock
)
{
synchronized
(
lock
)
{
if
(
mxbeanLookup
.
removeReference
(
objectName
,
getResource
()))
if
(
mxbeanLookup
!=
null
)
{
objectName
=
null
;
if
(
mxbeanLookup
.
removeReference
(
objectName
,
getResource
()))
objectName
=
null
;
}
// XXX: need to revisit the whole register/unregister logic in
// the face of wrapping. The mxbeanLookup!=null test is a hack.
// If you wrap an MXBean in a MyWrapperMBean and register it,
// the lookup table should contain the wrapped object. But that
// implies that MyWrapperMBean calls register, which today it
// can't within the public API.
}
}
}
}
private
final
Object
lock
=
new
Object
();
// for mxbeanLookup and objectName
private
Object
lock
=
new
Object
();
// for mxbeanLookup and objectName
private
MXBeanLookup
.
Plain
mxbeanLookup
;
private
MXBeanLookup
mxbeanLookup
;
private
ObjectName
objectName
;
private
ObjectName
objectName
;
}
}
src/share/classes/com/sun/jmx/mbeanserver/NotificationMBeanSupport.java
浏览文件 @
ae942eac
...
@@ -30,6 +30,7 @@ import java.util.ArrayList;
...
@@ -30,6 +30,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.Notification
;
import
javax.management.Notification
;
import
javax.management.openmbean.MXBeanMappingFactory
;
/**
/**
* <p>A variant of {@code StandardMBeanSupport} where the only
* <p>A variant of {@code StandardMBeanSupport} where the only
...
@@ -48,7 +49,7 @@ public class NotificationMBeanSupport extends StandardMBeanSupport {
...
@@ -48,7 +49,7 @@ public class NotificationMBeanSupport extends StandardMBeanSupport {
}
}
@Override
@Override
MBeanIntrospector
<
Method
>
getMBeanIntrospector
()
{
MBeanIntrospector
<
Method
>
getMBeanIntrospector
(
MXBeanMappingFactory
ignored
)
{
return
introspector
;
return
introspector
;
}
}
...
...
src/share/classes/com/sun/jmx/mbeanserver/PerInterface.java
浏览文件 @
ae942eac
...
@@ -231,7 +231,7 @@ final class PerInterface<M> {
...
@@ -231,7 +231,7 @@ final class PerInterface<M> {
/**
/**
* Visitor that sets up the method maps (operations, getters, setters).
* Visitor that sets up the method maps (operations, getters, setters).
*/
*/
private
class
InitMaps
implements
MBeanAnalyzer
.
MBeanVisitor
<
M
>
{
private
class
InitMaps
implements
MBeanAnalyzer
.
MBeanVisitor
<
M
,
RuntimeException
>
{
public
void
visitAttribute
(
String
attributeName
,
public
void
visitAttribute
(
String
attributeName
,
M
getter
,
M
getter
,
M
setter
)
{
M
setter
)
{
...
...
src/share/classes/com/sun/jmx/mbeanserver/StandardMBeanSupport.java
浏览文件 @
ae942eac
...
@@ -25,14 +25,13 @@
...
@@ -25,14 +25,13 @@
package
com.sun.jmx.mbeanserver
;
package
com.sun.jmx.mbeanserver
;
import
static
com
.
sun
.
jmx
.
mbeanserver
.
Util
.*;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
javax.management.MBeanInfo
;
import
javax.management.MBeanInfo
;
import
javax.management.MBeanServer
;
import
javax.management.MBeanServer
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.NotCompliantMBeanException
;
import
javax.management.ObjectName
;
import
javax.management.ObjectName
;
import
javax.management.openmbean.MXBeanMappingFactory
;
/**
/**
* Base class for Standard MBeans.
* Base class for Standard MBeans.
...
@@ -61,11 +60,11 @@ public class StandardMBeanSupport extends MBeanSupport<Method> {
...
@@ -61,11 +60,11 @@ public class StandardMBeanSupport extends MBeanSupport<Method> {
*/
*/
public
<
T
>
StandardMBeanSupport
(
T
resource
,
Class
<
T
>
mbeanInterface
)
public
<
T
>
StandardMBeanSupport
(
T
resource
,
Class
<
T
>
mbeanInterface
)
throws
NotCompliantMBeanException
{
throws
NotCompliantMBeanException
{
super
(
resource
,
mbeanInterface
);
super
(
resource
,
mbeanInterface
,
(
MXBeanMappingFactory
)
null
);
}
}
@Override
@Override
MBeanIntrospector
<
Method
>
getMBeanIntrospector
()
{
MBeanIntrospector
<
Method
>
getMBeanIntrospector
(
MXBeanMappingFactory
ignored
)
{
return
StandardMBeanIntrospector
.
getInstance
();
return
StandardMBeanIntrospector
.
getInstance
();
}
}
...
...
src/share/classes/javax/management/JMX.java
浏览文件 @
ae942eac
...
@@ -26,8 +26,17 @@
...
@@ -26,8 +26,17 @@
package
javax.management
;
package
javax.management
;
import
com.sun.jmx.mbeanserver.Introspector
;
import
com.sun.jmx.mbeanserver.Introspector
;
import
com.sun.jmx.remote.util.ClassLogger
;
import
java.beans.BeanInfo
;
import
java.beans.PropertyDescriptor
;
import
java.io.Serializable
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Proxy
;
import
java.lang.reflect.Proxy
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
javax.management.openmbean.MXBeanMappingFactory
;
/**
/**
* Static methods from the JMX API. There are no instances of this class.
* Static methods from the JMX API. There are no instances of this class.
...
@@ -39,6 +48,8 @@ public class JMX {
...
@@ -39,6 +48,8 @@ public class JMX {
* this class.
* this class.
*/
*/
static
final
JMX
proof
=
new
JMX
();
static
final
JMX
proof
=
new
JMX
();
private
static
final
ClassLogger
logger
=
new
ClassLogger
(
"javax.management.misc"
,
"JMX"
);
private
JMX
()
{}
private
JMX
()
{}
...
@@ -84,6 +95,14 @@ public class JMX {
...
@@ -84,6 +95,14 @@ public class JMX {
*/
*/
public
static
final
String
MXBEAN_FIELD
=
"mxbean"
;
public
static
final
String
MXBEAN_FIELD
=
"mxbean"
;
/**
* The name of the
* <a href="Descriptor.html#mxbeanMappingFactoryClass">{@code
* mxbeanMappingFactoryClass}</a> field.
*/
public
static
final
String
MXBEAN_MAPPING_FACTORY_CLASS_FIELD
=
"mxbeanMappingFactoryClass"
;
/**
/**
* The name of the <a href="Descriptor.html#openType">{@code
* The name of the <a href="Descriptor.html#openType">{@code
* openType}</a> field.
* openType}</a> field.
...
@@ -96,6 +115,264 @@ public class JMX {
...
@@ -96,6 +115,264 @@ public class JMX {
*/
*/
public
static
final
String
ORIGINAL_TYPE_FIELD
=
"originalType"
;
public
static
final
String
ORIGINAL_TYPE_FIELD
=
"originalType"
;
/**
* <p>Options to apply to an MBean proxy or to an instance of {@link
* StandardMBean}.</p>
*
* <p>For example, to specify a custom {@link MXBeanMappingFactory}
* for a {@code StandardMBean}, you might write this:</p>
*
* <pre>
* MXBeanMappingFactory factory = new MyMXBeanMappingFactory();
* JMX.MBeanOptions opts = new JMX.MBeanOptions();
* opts.setMXBeanMappingFactory(factory);
* StandardMBean mbean = new StandardMBean(impl, intf, opts);
* </pre>
*
* @see javax.management.JMX.ProxyOptions
*/
public
static
class
MBeanOptions
implements
Serializable
,
Cloneable
{
private
static
final
long
serialVersionUID
=
-
6380842449318177843L
;
static
final
MBeanOptions
MXBEAN
=
new
MBeanOptions
();
static
{
MXBEAN
.
setMXBeanMappingFactory
(
MXBeanMappingFactory
.
DEFAULT
);
}
private
MXBeanMappingFactory
mappingFactory
;
/**
* <p>Construct an {@code MBeanOptions} object where all options have
* their default values.</p>
*/
public
MBeanOptions
()
{}
@Override
public
MBeanOptions
clone
()
{
try
{
return
(
MBeanOptions
)
super
.
clone
();
}
catch
(
CloneNotSupportedException
e
)
{
throw
new
AssertionError
(
e
);
}
}
/**
* <p>True if this is an MXBean proxy or a StandardMBean instance
* that is an MXBean. The default value is false.</p>
*
* <p>This method is equivalent to {@link #getMXBeanMappingFactory()
* this.getMXBeanMappingFactory()}{@code != null}.</p>
*
* @return true if this is an MXBean proxy or a StandardMBean instance
* that is an MXBean.
*/
public
boolean
isMXBean
()
{
return
(
this
.
mappingFactory
!=
null
);
}
/**
* <p>The mappings between Java types and Open Types to be used in
* an MXBean proxy or a StandardMBean instance that is an MXBean,
* or null if this instance is not for an MXBean.
* The default value is null.</p>
*
* @return the mappings to be used in this proxy or StandardMBean,
* or null if this instance is not for an MXBean.
*/
public
MXBeanMappingFactory
getMXBeanMappingFactory
()
{
return
mappingFactory
;
}
/**
* <p>Set the {@link #getMXBeanMappingFactory() MXBeanMappingFactory} to
* the given value. The value should be null if this instance is not
* for an MXBean. If this instance is for an MXBean, the value should
* usually be either a custom mapping factory, or
* {@link MXBeanMappingFactory#forInterface
* MXBeanMappingFactory.forInterface}{@code (mxbeanInterface)}
* which signifies
* that the {@linkplain MXBeanMappingFactory#DEFAULT default} mapping
* factory should be used unless an {@code @}{@link
* javax.management.openmbean.MXBeanMappingFactoryClass
* MXBeanMappingFactoryClass} annotation on {@code mxbeanInterface}
* specifies otherwise.</p>
*
* <p>Examples:</p>
* <pre>
* MBeanOptions opts = new MBeanOptions();
* opts.setMXBeanMappingFactory(myMappingFactory);
* MyMXBean proxy = JMX.newMBeanProxy(
* mbeanServerConnection, objectName, MyMXBean.class, opts);
*
* // ...or...
*
* MBeanOptions opts = new MBeanOptions();
* MXBeanMappingFactory defaultFactoryForMyMXBean =
* MXBeanMappingFactory.forInterface(MyMXBean.class);
* opts.setMXBeanMappingFactory(defaultFactoryForMyMXBean);
* MyMXBean proxy = JMX.newMBeanProxy(
* mbeanServerConnection, objectName, MyMXBean.class, opts);
* </pre>
*
* @param f the new value. If null, this instance is not for an
* MXBean.
*/
public
void
setMXBeanMappingFactory
(
MXBeanMappingFactory
f
)
{
this
.
mappingFactory
=
f
;
}
/* To maximise object sharing, classes in this package can replace
* a private MBeanOptions with no MXBeanMappingFactory with one
* of these shared instances. But they must be EXTREMELY careful
* never to give out the shared instances to user code, which could
* modify them.
*/
private
static
final
MBeanOptions
[]
CANONICALS
=
{
new
MBeanOptions
(),
MXBEAN
,
};
// Overridden in local subclasses:
MBeanOptions
[]
canonicals
()
{
return
CANONICALS
;
}
// This is only used by the logic for canonical instances.
// Overridden in local subclasses:
boolean
same
(
MBeanOptions
opt
)
{
return
(
opt
.
mappingFactory
==
mappingFactory
);
}
final
MBeanOptions
canonical
()
{
for
(
MBeanOptions
opt
:
canonicals
())
{
if
(
opt
.
getClass
()
==
this
.
getClass
()
&&
same
(
opt
))
return
opt
;
}
return
this
;
}
final
MBeanOptions
uncanonical
()
{
for
(
MBeanOptions
opt
:
canonicals
())
{
if
(
this
==
opt
)
return
clone
();
}
return
this
;
}
private
Map
<
String
,
Object
>
toMap
()
{
Map
<
String
,
Object
>
map
=
new
TreeMap
<
String
,
Object
>();
try
{
BeanInfo
bi
=
java
.
beans
.
Introspector
.
getBeanInfo
(
getClass
());
PropertyDescriptor
[]
pds
=
bi
.
getPropertyDescriptors
();
for
(
PropertyDescriptor
pd
:
pds
)
{
String
name
=
pd
.
getName
();
if
(
name
.
equals
(
"class"
))
continue
;
Method
get
=
pd
.
getReadMethod
();
if
(
get
!=
null
)
map
.
put
(
name
,
get
.
invoke
(
this
));
}
}
catch
(
Exception
e
)
{
Throwable
t
=
e
;
if
(
t
instanceof
InvocationTargetException
)
t
=
t
.
getCause
();
map
.
put
(
"Exception"
,
t
);
}
return
map
;
}
@Override
public
String
toString
()
{
return
getClass
().
getSimpleName
()
+
toMap
();
// For example "MBeanOptions{MXBean=true, <etc>}".
}
/**
* <p>Indicates whether some other object is "equal to" this one. The
* result is true if and only if the other object is also an instance
* of MBeanOptions or a subclass, and has the same properties with
* the same values.</p>
* @return {@inheritDoc}
*/
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
obj
==
this
)
return
true
;
if
(
obj
==
null
||
obj
.
getClass
()
!=
this
.
getClass
())
return
false
;
return
toMap
().
equals
(((
MBeanOptions
)
obj
).
toMap
());
}
@Override
public
int
hashCode
()
{
return
toMap
().
hashCode
();
}
}
/**
* <p>Options to apply to an MBean proxy.</p>
*
* @see #newMBeanProxy
*/
public
static
class
ProxyOptions
extends
MBeanOptions
{
private
static
final
long
serialVersionUID
=
7238804866098386559L
;
private
boolean
notificationEmitter
;
/**
* <p>Construct a {@code ProxyOptions} object where all options have
* their default values.</p>
*/
public
ProxyOptions
()
{}
@Override
public
ProxyOptions
clone
()
{
return
(
ProxyOptions
)
super
.
clone
();
}
/**
* <p>Defines whether the returned proxy should
* implement {@link NotificationEmitter}. The default value is false.</p>
*
* @return true if this proxy will be a NotificationEmitter.
*
* @see JMX#newMBeanProxy(MBeanServerConnection, ObjectName, Class,
* MBeanOptions)
*/
public
boolean
isNotificationEmitter
()
{
return
this
.
notificationEmitter
;
}
/**
* <p>Set the {@link #isNotificationEmitter NotificationEmitter} option to
* the given value.</p>
* @param emitter the new value.
*/
public
void
setNotificationEmitter
(
boolean
emitter
)
{
this
.
notificationEmitter
=
emitter
;
}
// Canonical objects for each of (MXBean,!MXBean) x (Emitter,!Emitter)
private
static
final
ProxyOptions
[]
CANONICALS
=
{
new
ProxyOptions
(),
new
ProxyOptions
(),
new
ProxyOptions
(),
new
ProxyOptions
(),
};
static
{
CANONICALS
[
1
].
setMXBeanMappingFactory
(
MXBeanMappingFactory
.
DEFAULT
);
CANONICALS
[
2
].
setNotificationEmitter
(
true
);
CANONICALS
[
3
].
setMXBeanMappingFactory
(
MXBeanMappingFactory
.
DEFAULT
);
CANONICALS
[
3
].
setNotificationEmitter
(
true
);
}
@Override
MBeanOptions
[]
canonicals
()
{
return
CANONICALS
;
}
@Override
boolean
same
(
MBeanOptions
opt
)
{
return
(
super
.
same
(
opt
)
&&
opt
instanceof
ProxyOptions
&&
((
ProxyOptions
)
opt
).
notificationEmitter
==
notificationEmitter
);
}
}
/**
/**
* <p>Make a proxy for a Standard MBean in a local or remote
* <p>Make a proxy for a Standard MBean in a local or remote
* MBean Server.</p>
* MBean Server.</p>
...
@@ -172,7 +449,7 @@ public class JMX {
...
@@ -172,7 +449,7 @@ public class JMX {
*
*
* <p>This method behaves the same as {@link
* <p>This method behaves the same as {@link
* #newMBeanProxy(MBeanServerConnection, ObjectName, Class)}, but
* #newMBeanProxy(MBeanServerConnection, ObjectName, Class)}, but
* additionally, if {@code notification
Broadcas
ter} is {@code
* additionally, if {@code notification
Emit
ter} is {@code
* true}, then the MBean is assumed to be a {@link
* true}, then the MBean is assumed to be a {@link
* NotificationBroadcaster} or {@link NotificationEmitter} and the
* NotificationBroadcaster} or {@link NotificationEmitter} and the
* returned proxy will implement {@link NotificationEmitter} as
* returned proxy will implement {@link NotificationEmitter} as
...
@@ -189,25 +466,21 @@ public class JMX {
...
@@ -189,25 +466,21 @@ public class JMX {
* {@code connection} to forward to.
* {@code connection} to forward to.
* @param interfaceClass the management interface that the MBean
* @param interfaceClass the management interface that the MBean
* exports, which will also be implemented by the returned proxy.
* exports, which will also be implemented by the returned proxy.
* @param notification
Broadcas
ter make the returned proxy
* @param notification
Emit
ter make the returned proxy
* implement {@link NotificationEmitter} by forwarding its methods
* implement {@link NotificationEmitter} by forwarding its methods
* via {@code connection}.
* via {@code connection}.
*
* @param <T> allows the compiler to know that if the {@code
* @param <T> allows the compiler to know that if the {@code
* interfaceClass} parameter is {@code MyMBean.class}, for
* interfaceClass} parameter is {@code MyMBean.class}, for
* example, then the return type is {@code MyMBean}.
* example, then the return type is {@code MyMBean}.
*
* @return the new proxy instance.
* @return the new proxy instance.
*/
*/
public
static
<
T
>
T
newMBeanProxy
(
MBeanServerConnection
connection
,
public
static
<
T
>
T
newMBeanProxy
(
MBeanServerConnection
connection
,
ObjectName
objectName
,
ObjectName
objectName
,
Class
<
T
>
interfaceClass
,
Class
<
T
>
interfaceClass
,
boolean
notificationBroadcaster
)
{
boolean
notificationEmitter
)
{
return
MBeanServerInvocationHandler
.
newProxyInstance
(
ProxyOptions
opts
=
new
ProxyOptions
();
connection
,
opts
.
setNotificationEmitter
(
notificationEmitter
);
objectName
,
return
newMBeanProxy
(
connection
,
objectName
,
interfaceClass
,
opts
);
interfaceClass
,
notificationBroadcaster
);
}
}
/**
/**
...
@@ -314,7 +587,7 @@ public class JMX {
...
@@ -314,7 +587,7 @@ public class JMX {
*
*
* <p>This method behaves the same as {@link
* <p>This method behaves the same as {@link
* #newMXBeanProxy(MBeanServerConnection, ObjectName, Class)}, but
* #newMXBeanProxy(MBeanServerConnection, ObjectName, Class)}, but
* additionally, if {@code notification
Broadcas
ter} is {@code
* additionally, if {@code notification
Emit
ter} is {@code
* true}, then the MXBean is assumed to be a {@link
* true}, then the MXBean is assumed to be a {@link
* NotificationBroadcaster} or {@link NotificationEmitter} and the
* NotificationBroadcaster} or {@link NotificationEmitter} and the
* returned proxy will implement {@link NotificationEmitter} as
* returned proxy will implement {@link NotificationEmitter} as
...
@@ -331,31 +604,105 @@ public class JMX {
...
@@ -331,31 +604,105 @@ public class JMX {
* {@code connection} to forward to.
* {@code connection} to forward to.
* @param interfaceClass the MXBean interface,
* @param interfaceClass the MXBean interface,
* which will also be implemented by the returned proxy.
* which will also be implemented by the returned proxy.
* @param notification
Broadcas
ter make the returned proxy
* @param notification
Emit
ter make the returned proxy
* implement {@link NotificationEmitter} by forwarding its methods
* implement {@link NotificationEmitter} by forwarding its methods
* via {@code connection}.
* via {@code connection}.
*
* @param <T> allows the compiler to know that if the {@code
* @param <T> allows the compiler to know that if the {@code
* interfaceClass} parameter is {@code MyMXBean.class}, for
* interfaceClass} parameter is {@code MyMXBean.class}, for
* example, then the return type is {@code MyMXBean}.
* example, then the return type is {@code MyMXBean}.
*
* @return the new proxy instance.
* @return the new proxy instance.
*/
*/
public
static
<
T
>
T
newMXBeanProxy
(
MBeanServerConnection
connection
,
public
static
<
T
>
T
newMXBeanProxy
(
MBeanServerConnection
connection
,
ObjectName
objectName
,
ObjectName
objectName
,
Class
<
T
>
interfaceClass
,
Class
<
T
>
interfaceClass
,
boolean
notificationBroadcaster
)
{
boolean
notificationEmitter
)
{
// Check interface for MXBean compliance
ProxyOptions
opts
=
new
ProxyOptions
();
//
MXBeanMappingFactory
f
=
MXBeanMappingFactory
.
forInterface
(
interfaceClass
);
opts
.
setMXBeanMappingFactory
(
f
);
opts
.
setNotificationEmitter
(
notificationEmitter
);
return
newMBeanProxy
(
connection
,
objectName
,
interfaceClass
,
opts
);
}
/**
* <p>Make a proxy for a Standard MBean or MXBean in a local or remote MBean
* Server that may also support the methods of {@link
* NotificationEmitter} and (for an MXBean) that may define custom MXBean
* type mappings.</p>
*
* <p>This method behaves the same as
* {@link #newMBeanProxy(MBeanServerConnection, ObjectName, Class)} or
* {@link #newMXBeanProxy(MBeanServerConnection, ObjectName, Class)},
* according as {@code opts.isMXBean()} is respectively false or true; but
* with the following changes based on {@code opts}.</p>
*
* <ul>
* <li>If {@code opts.isNotificationEmitter()} is {@code
* true}, then the MBean is assumed to be a {@link
* NotificationBroadcaster} or {@link NotificationEmitter} and the
* returned proxy will implement {@link NotificationEmitter} as
* well as {@code interfaceClass}. A call to {@link
* NotificationBroadcaster#addNotificationListener} on the proxy
* will result in a call to {@link
* MBeanServerConnection#addNotificationListener(ObjectName,
* NotificationListener, NotificationFilter, Object)}, and
* likewise for the other methods of {@link
* NotificationBroadcaster} and {@link NotificationEmitter}.</li>
*
* <li>If {@code opts.getMXBeanMappingFactory()} is not null,
* then the mappings it defines will be applied to convert between
* arbitrary Java types and Open Types.</li>
* </ul>
*
* @param connection the MBean server to forward to.
* @param objectName the name of the MBean within
* {@code connection} to forward to.
* @param interfaceClass the Standard MBean or MXBean interface,
* which will also be implemented by the returned proxy.
* @param opts the options to apply for this proxy. Can be null,
* in which case default options are applied.
* @param <T> allows the compiler to know that if the {@code
* interfaceClass} parameter is {@code MyMXBean.class}, for
* example, then the return type is {@code MyMXBean}.
* @return the new proxy instance.
*
* @throws IllegalArgumentException if {@code interfaceClass} is not a
* valid MXBean interface.
*/
public
static
<
T
>
T
newMBeanProxy
(
MBeanServerConnection
connection
,
ObjectName
objectName
,
Class
<
T
>
interfaceClass
,
MBeanOptions
opts
)
{
try
{
try
{
Introspector
.
testComplianceMXBeanInterface
(
interfaceClas
s
);
return
newMBeanProxy2
(
connection
,
objectName
,
interfaceClass
,
opt
s
);
}
catch
(
NotCompliantMBeanException
e
)
{
}
catch
(
NotCompliantMBeanException
e
)
{
throw
new
IllegalArgumentException
(
e
);
throw
new
IllegalArgumentException
(
e
);
}
}
}
private
static
<
T
>
T
newMBeanProxy2
(
MBeanServerConnection
connection
,
ObjectName
objectName
,
Class
<
T
>
interfaceClass
,
MBeanOptions
opts
)
throws
NotCompliantMBeanException
{
if
(
opts
==
null
)
opts
=
new
MBeanOptions
();
boolean
notificationEmitter
=
opts
instanceof
ProxyOptions
&&
((
ProxyOptions
)
opts
).
isNotificationEmitter
();
MXBeanMappingFactory
mappingFactory
=
opts
.
getMXBeanMappingFactory
();
if
(
mappingFactory
!=
null
)
{
// Check interface for MXBean compliance
Introspector
.
testComplianceMXBeanInterface
(
interfaceClass
,
mappingFactory
);
}
InvocationHandler
handler
=
new
MBeanServerInvocationHandler
(
InvocationHandler
handler
=
new
MBeanServerInvocationHandler
(
connection
,
objectName
,
true
);
connection
,
objectName
,
opts
);
final
Class
[]
interfaces
;
final
Class
[]
interfaces
;
if
(
notification
Broadcas
ter
)
{
if
(
notification
Emit
ter
)
{
interfaces
=
interfaces
=
new
Class
<?>[]
{
interfaceClass
,
NotificationEmitter
.
class
};
new
Class
<?>[]
{
interfaceClass
,
NotificationEmitter
.
class
};
}
else
}
else
...
...
src/share/classes/javax/management/MBeanServerInvocationHandler.java
浏览文件 @
ae942eac
...
@@ -33,6 +33,9 @@ import java.lang.reflect.Method;
...
@@ -33,6 +33,9 @@ import java.lang.reflect.Method;
import
java.lang.reflect.Proxy
;
import
java.lang.reflect.Proxy
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.WeakHashMap
;
import
java.util.WeakHashMap
;
import
javax.management.openmbean.MXBeanMappingFactory
;
import
static
javax
.
management
.
JMX
.
MBeanOptions
;
/**
/**
* <p>{@link InvocationHandler} that forwards methods in an MBean's
* <p>{@link InvocationHandler} that forwards methods in an MBean's
...
@@ -111,7 +114,7 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
...
@@ -111,7 +114,7 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
public
MBeanServerInvocationHandler
(
MBeanServerConnection
connection
,
public
MBeanServerInvocationHandler
(
MBeanServerConnection
connection
,
ObjectName
objectName
)
{
ObjectName
objectName
)
{
this
(
connection
,
objectName
,
false
);
this
(
connection
,
objectName
,
null
);
}
}
/**
/**
...
@@ -138,6 +141,14 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
...
@@ -138,6 +141,14 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
public
MBeanServerInvocationHandler
(
MBeanServerConnection
connection
,
public
MBeanServerInvocationHandler
(
MBeanServerConnection
connection
,
ObjectName
objectName
,
ObjectName
objectName
,
boolean
isMXBean
)
{
boolean
isMXBean
)
{
this
(
connection
,
objectName
,
isMXBean
?
MBeanOptions
.
MXBEAN
:
null
);
}
public
MBeanServerInvocationHandler
(
MBeanServerConnection
connection
,
ObjectName
objectName
,
MBeanOptions
options
)
{
if
(
options
==
null
)
options
=
new
MBeanOptions
();
if
(
connection
==
null
)
{
if
(
connection
==
null
)
{
throw
new
IllegalArgumentException
(
"Null connection"
);
throw
new
IllegalArgumentException
(
"Null connection"
);
}
}
...
@@ -146,7 +157,7 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
...
@@ -146,7 +157,7 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
}
}
this
.
connection
=
connection
;
this
.
connection
=
connection
;
this
.
objectName
=
objectName
;
this
.
objectName
=
objectName
;
this
.
isMXBean
=
isMXBean
;
this
.
options
=
options
.
canonical
()
;
}
}
/**
/**
...
@@ -182,7 +193,16 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
...
@@ -182,7 +193,16 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
* @since 1.6
* @since 1.6
*/
*/
public
boolean
isMXBean
()
{
public
boolean
isMXBean
()
{
return
isMXBean
;
return
options
.
isMXBean
();
}
/**
* <p>Return the {@link MBeanOptions} used for this proxy.</p>
*
* @return the MBeanOptions.
*/
public
MBeanOptions
getMBeanOptions
()
{
return
options
.
uncanonical
();
}
}
/**
/**
...
@@ -260,7 +280,7 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
...
@@ -260,7 +280,7 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
return
doLocally
(
proxy
,
method
,
args
);
return
doLocally
(
proxy
,
method
,
args
);
try
{
try
{
if
(
isMXBean
)
{
if
(
isMXBean
()
)
{
MXBeanProxy
p
=
findMXBeanProxy
(
methodClass
);
MXBeanProxy
p
=
findMXBeanProxy
(
methodClass
);
return
p
.
invoke
(
connection
,
objectName
,
method
,
args
);
return
p
.
invoke
(
connection
,
objectName
,
method
,
args
);
}
else
{
}
else
{
...
@@ -326,21 +346,34 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
...
@@ -326,21 +346,34 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
*/
*/
}
}
private
static
MXBeanProxy
findMXBeanProxy
(
Class
<?>
mxbeanInterface
)
{
private
MXBeanProxy
findMXBeanProxy
(
Class
<?>
mxbeanInterface
)
{
MXBeanMappingFactory
mappingFactory
=
options
.
getMXBeanMappingFactory
();
synchronized
(
mxbeanProxies
)
{
synchronized
(
mxbeanProxies
)
{
WeakReference
<
MXBeanProxy
>
proxyRef
=
ClassToProxy
classToProxy
=
mxbeanProxies
.
get
(
mappingFactory
);
mxbeanProxies
.
get
(
mxbeanInterface
);
if
(
classToProxy
==
null
)
{
MXBeanProxy
p
=
(
proxyRef
==
null
)
?
null
:
proxyRef
.
get
();
classToProxy
=
new
ClassToProxy
();
if
(
p
==
null
)
{
mxbeanProxies
.
put
(
mappingFactory
,
classToProxy
);
p
=
new
MXBeanProxy
(
mxbeanInterface
);
mxbeanProxies
.
put
(
mxbeanInterface
,
new
WeakReference
<
MXBeanProxy
>(
p
));
}
}
WeakReference
<
MXBeanProxy
>
wr
=
classToProxy
.
get
(
mxbeanInterface
);
MXBeanProxy
p
;
if
(
wr
!=
null
)
{
p
=
wr
.
get
();
if
(
p
!=
null
)
return
p
;
}
p
=
new
MXBeanProxy
(
mxbeanInterface
,
mappingFactory
);
classToProxy
.
put
(
mxbeanInterface
,
new
WeakReference
<
MXBeanProxy
>(
p
));
return
p
;
return
p
;
}
}
}
}
private
static
final
WeakHashMap
<
Class
<?>,
WeakReference
<
MXBeanProxy
>>
private
static
final
WeakHashMap
<
MXBeanMappingFactory
,
ClassToProxy
>
mxbeanProxies
=
new
WeakHashMap
<
Class
<?>,
WeakReference
<
MXBeanProxy
>>();
mxbeanProxies
=
newWeakHashMap
();
private
static
class
ClassToProxy
extends
WeakHashMap
<
Class
<?>,
WeakReference
<
MXBeanProxy
>>
{}
private
static
<
K
,
V
>
WeakHashMap
<
K
,
V
>
newWeakHashMap
()
{
return
new
WeakHashMap
<
K
,
V
>();
}
private
Object
invokeBroadcasterMethod
(
Object
proxy
,
Method
method
,
private
Object
invokeBroadcasterMethod
(
Object
proxy
,
Method
method
,
Object
[]
args
)
throws
Exception
{
Object
[]
args
)
throws
Exception
{
...
@@ -453,7 +486,7 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
...
@@ -453,7 +486,7 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
objectName
.
equals
(
handler
.
objectName
)
&&
objectName
.
equals
(
handler
.
objectName
)
&&
proxy
.
getClass
().
equals
(
args
[
0
].
getClass
());
proxy
.
getClass
().
equals
(
args
[
0
].
getClass
());
}
else
if
(
methodName
.
equals
(
"toString"
))
{
}
else
if
(
methodName
.
equals
(
"toString"
))
{
return
(
isMXBean
?
"MX"
:
"M"
)
+
"BeanProxy("
+
return
(
isMXBean
()
?
"MX"
:
"M"
)
+
"BeanProxy("
+
connection
+
"["
+
objectName
+
"])"
;
connection
+
"["
+
objectName
+
"])"
;
}
else
if
(
methodName
.
equals
(
"hashCode"
))
{
}
else
if
(
methodName
.
equals
(
"hashCode"
))
{
return
objectName
.
hashCode
()+
connection
.
hashCode
();
return
objectName
.
hashCode
()+
connection
.
hashCode
();
...
@@ -484,5 +517,5 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
...
@@ -484,5 +517,5 @@ public class MBeanServerInvocationHandler implements InvocationHandler {
private
final
MBeanServerConnection
connection
;
private
final
MBeanServerConnection
connection
;
private
final
ObjectName
objectName
;
private
final
ObjectName
objectName
;
private
final
boolean
isMXBean
;
private
final
MBeanOptions
options
;
}
}
src/share/classes/javax/management/MXBean.java
浏览文件 @
ae942eac
...
@@ -44,6 +44,10 @@ import javax.management.openmbean.CompositeDataInvocationHandler;
...
@@ -44,6 +44,10 @@ import javax.management.openmbean.CompositeDataInvocationHandler;
import
javax.management.openmbean.CompositeDataSupport
;
import
javax.management.openmbean.CompositeDataSupport
;
import
javax.management.openmbean.CompositeDataView
;
import
javax.management.openmbean.CompositeDataView
;
import
javax.management.openmbean.CompositeType
;
import
javax.management.openmbean.CompositeType
;
import
javax.management.openmbean.MXBeanMapping
;
import
javax.management.openmbean.MXBeanMappingClass
;
import
javax.management.openmbean.MXBeanMappingFactory
;
import
javax.management.openmbean.MXBeanMappingFactoryClass
;
import
javax.management.openmbean.OpenDataException
;
import
javax.management.openmbean.OpenDataException
;
import
javax.management.openmbean.OpenMBeanInfo
;
import
javax.management.openmbean.OpenMBeanInfo
;
import
javax.management.openmbean.OpenType
;
import
javax.management.openmbean.OpenType
;
...
@@ -78,7 +82,7 @@ import javax.management.openmbean.TabularType;
...
@@ -78,7 +82,7 @@ import javax.management.openmbean.TabularType;
public interface MisleadingMXBean {}
public interface MisleadingMXBean {}
</pre>
</pre>
<h3
><a name="MXBean-spec">MXBean specification</a>
</h3>
<h3
id="MXBean-spec">MXBean specification
</h3>
<p>The MXBean concept provides a simple way to code an MBean
<p>The MXBean concept provides a simple way to code an MBean
that only references a predefined set of types, the ones defined
that only references a predefined set of types, the ones defined
...
@@ -314,7 +318,7 @@ public class MemoryPool
...
@@ -314,7 +318,7 @@ public class MemoryPool
</table>
</table>
<h2
><a name="mxbean-def">Definition of an MXBean</a>
</h2>
<h2
id="mxbean-def">Definition of an MXBean
</h2>
<p>An MXBean is a kind of MBean. An MXBean object can be
<p>An MXBean is a kind of MBean. An MXBean object can be
registered directly in the MBean Server, or it can be used as an
registered directly in the MBean Server, or it can be used as an
...
@@ -367,7 +371,7 @@ public class MemoryPool
...
@@ -367,7 +371,7 @@ public class MemoryPool
above rules will produce an exception.</p>
above rules will produce an exception.</p>
<h2
><a name="naming-conv">Naming conventions</a>
</h2>
<h2
id="naming-conv">Naming conventions
</h2>
<p>The same naming conventions are applied to the methods in an
<p>The same naming conventions are applied to the methods in an
MXBean as in a Standard MBean:</p>
MXBean as in a Standard MBean:</p>
...
@@ -413,7 +417,7 @@ public class MemoryPool
...
@@ -413,7 +417,7 @@ public class MemoryPool
read-only or write-only respectively.</p>
read-only or write-only respectively.</p>
<h2
><a name="mapping-rules">Type mapping rules</a>
</h2>
<h2
id="mapping-rules">Type mapping rules
</h2>
<p>An MXBean is a kind of Open MBean, as defined by the {@link
<p>An MXBean is a kind of Open MBean, as defined by the {@link
javax.management.openmbean} package. This means that the types of
javax.management.openmbean} package. This means that the types of
...
@@ -475,7 +479,11 @@ public class MemoryPool
...
@@ -475,7 +479,11 @@ public class MemoryPool
from type <em>opendata(J)</em> to type <em>J</em>, a null value is
from type <em>opendata(J)</em> to type <em>J</em>, a null value is
mapped to a null value.</p>
mapped to a null value.</p>
<p>The following table summarizes the type mapping rules.</p>
<p>In addition to the default type mapping rules, you can specify
custom type mappings, as described <a
href="#custom">below</a>.</p>
<p>The following table summarizes the default type mapping rules.</p>
<table border="1" cellpadding="5">
<table border="1" cellpadding="5">
<tr>
<tr>
...
@@ -658,7 +666,7 @@ TabularType tabularType =
...
@@ -658,7 +666,7 @@ TabularType tabularType =
TabularData} that serializes as {@code TabularDataSupport}.</p>
TabularData} that serializes as {@code TabularDataSupport}.</p>
<h3
><a name="mxbean-map">Mappings for MXBean interfaces</a>
</h3>
<h3
id="mxbean-map">Mappings for MXBean interfaces
</h3>
<p>An MXBean interface, or a type referenced within an MXBean
<p>An MXBean interface, or a type referenced within an MXBean
interface, can reference another MXBean interface, <em>J</em>.
interface, can reference another MXBean interface, <em>J</em>.
...
@@ -747,7 +755,7 @@ public interface ModuleMXBean {
...
@@ -747,7 +755,7 @@ public interface ModuleMXBean {
general, notably because it does not work well for MBeans that are
general, notably because it does not work well for MBeans that are
{@link NotificationBroadcaster}s.</p>
{@link NotificationBroadcaster}s.</p>
<h3
><a name="composite-map">Mappings for other types</a>
</h3>
<h3
id="composite-map">Mappings for other types
</h3>
<p>Given a Java class or interface <em>J</em> that does not match the other
<p>Given a Java class or interface <em>J</em> that does not match the other
rules in the table above, the MXBean framework will attempt to map
rules in the table above, the MXBean framework will attempt to map
...
@@ -1035,6 +1043,76 @@ public interface Node {
...
@@ -1035,6 +1043,76 @@ public interface Node {
}
}
</pre>
</pre>
<p>Alternatively, you can define a custom mapping for your recursive
type; see the next section.</p>
<h3 id="custom">Custom MXBean type mappings</h3>
<p>You can augment or replace the default type mappings described
above with custom mappings. An example appears in the
documentation for {@link MXBeanMapping}.</p>
<p>If an MXBean uses custom mappings, then an MXBean proxy for
that MXBean must use the same mappings for correct behavior.
This requires more careful synchronization between client and
server than is necessary with the default mappings. For example
it typically requires the client to have the same implementation
of any {@link MXBeanMapping} subclasses as the server. For this
reason, custom mappings should be avoided if possible.</p>
<p>Every MXBean has an associated {@link MXBeanMappingFactory}.
Call this <code><em>f</em></code>. Then every type that appears
in that MXBean has an associated {@link MXBeanMapping}
determined by <code><em>f</em></code>. If the type is
<code><em>J</em></code>, say, then the mapping is {@link
MXBeanMappingFactory#mappingForType
<em>f</em>.mappingForType}<code>(<em>J</em>,
<em>f</em>)</code>.</p>
<p>The {@code MXBeanMappingFactory} <code><em>f</em></code> for an
MXBean is determined as follows.</p>
<ul>
<li><p>If an {@link JMX.MBeanOptions} argument is supplied to
the {@link StandardMBean} constructor that makes an MXBean,
or to the {@link JMX#newMXBeanProxy JMX.newMXBeanProxy}
method, and the {@code MBeanOptions} object defines a non-null
{@code MXBeanMappingFactory}, then that is the value of
<code><em>f</em></code>.</p></li>
<li><p>Otherwise, if the MXBean interface has an {@link
MXBeanMappingFactoryClass} annotation, then that annotation
must identify a subclass of {@code MXBeanMappingFactory}
with a no-argument constructor. Then
<code><em>f</em></code> is the result of calling this
constructor. If the class does not have a no-argument
constructor, or if calling the constructor produces an
exception, then the MXBean is invalid and an attempt to
register it in the MBean Server will produce a {@link
NotCompliantMBeanException}.</p>
<p>This annotation is not inherited from any parent
interfaces. If an MXBean interface has this annotation,
then usually any MXBean subinterfaces must repeat the same
annotation for correct behavior.</p></li>
<li><p>Otherwise, if the package in which the MXBean interface
appears has an {@code MXBeanMappingFactoryClass} annotation,
then <code><em>f</em></code> is determined as if that
annotation appeared on the MXBean interface.</p></li>
<li><p>Otherwise, <code><em>f</em></code> is the default mapping
factory, {@link MXBeanMappingFactory#DEFAULT}.</p></li>
</ul>
<p>The default mapping factory recognizes the {@link
MXBeanMappingClass} annotation on a class or interface. If
<code><em>J</em></code> is a class or interface that has such an
annotation, then the {@code MXBeanMapping} for
<code><em>J</em></code> produced by the default mapping factory
will be determined by the value of the annotation as described
in its {@linkplain MXBeanMappingClass documentation}.</p>
<h3>MBeanInfo contents for an MXBean</h3>
<h3>MBeanInfo contents for an MXBean</h3>
<p>An MXBean is a type of Open MBean. However, for compatibility
<p>An MXBean is a type of Open MBean. However, for compatibility
...
@@ -1091,7 +1169,7 @@ public interface Node {
...
@@ -1091,7 +1169,7 @@ public interface Node {
{@code mxbean} whose value is the string "{@code true}".</p>
{@code mxbean} whose value is the string "{@code true}".</p>
<h3
><a name="type-names">Type Names</a>
</h3>
<h3
id="type-names">Type Names
</h3>
<p>Sometimes the unmapped type <em>T</em> of a method parameter or
<p>Sometimes the unmapped type <em>T</em> of a method parameter or
return value in an MXBean must be represented as a string. If
return value in an MXBean must be represented as a string. If
...
@@ -1163,6 +1241,8 @@ public interface Node {
...
@@ -1163,6 +1241,8 @@ public interface Node {
appropriate), or <em>C</em> is true of <em>e</em>.{@link
appropriate), or <em>C</em> is true of <em>e</em>.{@link
Throwable#getCause() getCause()}".</p>
Throwable#getCause() getCause()}".</p>
@see MXBeanMapping
@since 1.6
@since 1.6
*/
*/
...
...
src/share/classes/javax/management/StandardMBean.java
浏览文件 @
ae942eac
...
@@ -25,22 +25,19 @@
...
@@ -25,22 +25,19 @@
package
javax.management
;
package
javax.management
;
import
static
com
.
sun
.
jmx
.
defaults
.
JmxProperties
.
MISC_LOGGER
;
import
com.sun.jmx.mbeanserver.DescriptorCache
;
import
com.sun.jmx.mbeanserver.DescriptorCache
;
import
com.sun.jmx.mbeanserver.Introspector
;
import
com.sun.jmx.mbeanserver.Introspector
;
import
com.sun.jmx.mbeanserver.MBeanSupport
;
import
com.sun.jmx.mbeanserver.MBeanSupport
;
import
com.sun.jmx.mbeanserver.MXBeanSupport
;
import
com.sun.jmx.mbeanserver.MXBeanSupport
;
import
com.sun.jmx.mbeanserver.StandardMBeanSupport
;
import
com.sun.jmx.mbeanserver.StandardMBeanSupport
;
import
com.sun.jmx.mbeanserver.Util
;
import
com.sun.jmx.mbeanserver.Util
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.security.AccessController
;
import
java.security.AccessController
;
import
java.security.PrivilegedAction
;
import
java.security.PrivilegedAction
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.WeakHashMap
;
import
java.util.WeakHashMap
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
javax.management.openmbean.MXBeanMappingFactory
;
import
javax.management.openmbean.OpenMBeanAttributeInfo
;
import
javax.management.openmbean.OpenMBeanAttributeInfo
;
import
javax.management.openmbean.OpenMBeanAttributeInfoSupport
;
import
javax.management.openmbean.OpenMBeanAttributeInfoSupport
;
import
javax.management.openmbean.OpenMBeanConstructorInfo
;
import
javax.management.openmbean.OpenMBeanConstructorInfo
;
...
@@ -50,6 +47,9 @@ import javax.management.openmbean.OpenMBeanOperationInfoSupport;
...
@@ -50,6 +47,9 @@ import javax.management.openmbean.OpenMBeanOperationInfoSupport;
import
javax.management.openmbean.OpenMBeanParameterInfo
;
import
javax.management.openmbean.OpenMBeanParameterInfo
;
import
javax.management.openmbean.OpenMBeanParameterInfoSupport
;
import
javax.management.openmbean.OpenMBeanParameterInfoSupport
;
import
static
com
.
sun
.
jmx
.
defaults
.
JmxProperties
.
MISC_LOGGER
;
import
static
javax
.
management
.
JMX
.
MBeanOptions
;
/**
/**
* <p>An MBean whose management interface is determined by reflection
* <p>An MBean whose management interface is determined by reflection
* on a Java interface.</p>
* on a Java interface.</p>
...
@@ -140,6 +140,11 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -140,6 +140,11 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
**/
**/
private
volatile
MBeanInfo
cachedMBeanInfo
;
private
volatile
MBeanInfo
cachedMBeanInfo
;
/**
* The MBeanOptions for this StandardMBean.
**/
private
MBeanOptions
options
;
/**
/**
* Make a DynamicMBean out of <var>implementation</var>, using the
* Make a DynamicMBean out of <var>implementation</var>, using the
* specified <var>mbeanInterface</var> class.
* specified <var>mbeanInterface</var> class.
...
@@ -155,12 +160,14 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -155,12 +160,14 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
* implementation is allowed. If null implementation is allowed,
* implementation is allowed. If null implementation is allowed,
* and a null implementation is passed, then the implementation
* and a null implementation is passed, then the implementation
* is assumed to be <var>this</var>.
* is assumed to be <var>this</var>.
* @param options MBeanOptions to apply to this instance.
* @exception IllegalArgumentException if the given
* @exception IllegalArgumentException if the given
* <var>implementation</var> is null, and null is not allowed.
* <var>implementation</var> is null, and null is not allowed.
**/
**/
@SuppressWarnings
(
"unchecked"
)
// cast to T
private
<
T
>
void
construct
(
T
implementation
,
Class
<
T
>
mbeanInterface
,
private
<
T
>
void
construct
(
T
implementation
,
Class
<
T
>
mbeanInterface
,
boolean
nullImplementationAllowed
,
boolean
nullImplementationAllowed
,
boolean
isMXBean
)
MBeanOptions
options
)
throws
NotCompliantMBeanException
{
throws
NotCompliantMBeanException
{
if
(
implementation
==
null
)
{
if
(
implementation
==
null
)
{
// Have to use (T)this rather than mbeanInterface.cast(this)
// Have to use (T)this rather than mbeanInterface.cast(this)
...
@@ -169,20 +176,23 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -169,20 +176,23 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
implementation
=
Util
.<
T
>
cast
(
this
);
implementation
=
Util
.<
T
>
cast
(
this
);
else
throw
new
IllegalArgumentException
(
"implementation is null"
);
else
throw
new
IllegalArgumentException
(
"implementation is null"
);
}
}
if
(
isMXBean
)
{
if
(
options
==
null
)
if
(
mbeanInterface
==
null
)
{
options
=
new
MBeanOptions
();
mbeanInterface
=
Util
.
cast
(
Introspector
.
getMXBeanInterface
(
MXBeanMappingFactory
mappingFactory
=
options
.
getMXBeanMappingFactory
();
implementation
.
getClass
()));
boolean
mx
=
(
mappingFactory
!=
null
);
}
if
(
mbeanInterface
==
null
)
{
this
.
mbean
=
new
MXBeanSupport
(
implementation
,
mbeanInterface
);
mbeanInterface
=
Util
.
cast
(
Introspector
.
getStandardOrMXBeanInterface
(
implementation
.
getClass
(),
mx
));
}
if
(
mx
)
{
this
.
mbean
=
new
MXBeanSupport
(
implementation
,
mbeanInterface
,
mappingFactory
);
}
else
{
}
else
{
if
(
mbeanInterface
==
null
)
{
mbeanInterface
=
Util
.
cast
(
Introspector
.
getStandardMBeanInterface
(
implementation
.
getClass
()));
}
this
.
mbean
=
this
.
mbean
=
new
StandardMBeanSupport
(
implementation
,
mbeanInterface
);
new
StandardMBeanSupport
(
implementation
,
mbeanInterface
);
}
}
this
.
options
=
options
.
canonical
();
}
}
/**
/**
...
@@ -211,14 +221,14 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -211,14 +221,14 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
**/
**/
public
<
T
>
StandardMBean
(
T
implementation
,
Class
<
T
>
mbeanInterface
)
public
<
T
>
StandardMBean
(
T
implementation
,
Class
<
T
>
mbeanInterface
)
throws
NotCompliantMBeanException
{
throws
NotCompliantMBeanException
{
construct
(
implementation
,
mbeanInterface
,
false
,
false
);
construct
(
implementation
,
mbeanInterface
,
false
,
null
);
}
}
/**
/**
* <p>Make a DynamicMBean out of <var>this</var>, using the specified
* <p>Make a DynamicMBean out of <var>this</var>, using the specified
* <var>mbeanInterface</var> class.</p>
* <var>mbeanInterface</var> class.</p>
*
*
* <p>Call {@link #StandardMBean(java.lang.Object, java.lang.Class)
* <p>Call
s
{@link #StandardMBean(java.lang.Object, java.lang.Class)
* this(this,mbeanInterface)}.
* this(this,mbeanInterface)}.
* This constructor is reserved to subclasses.</p>
* This constructor is reserved to subclasses.</p>
*
*
...
@@ -231,13 +241,14 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -231,13 +241,14 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
**/
**/
protected
StandardMBean
(
Class
<?>
mbeanInterface
)
protected
StandardMBean
(
Class
<?>
mbeanInterface
)
throws
NotCompliantMBeanException
{
throws
NotCompliantMBeanException
{
construct
(
null
,
mbeanInterface
,
true
,
false
);
construct
(
null
,
mbeanInterface
,
true
,
null
);
}
}
/**
/**
* <p>Make a DynamicMBean out of the object
* <p>Make a DynamicMBean out of the object
* <var>implementation</var>, using the specified
* <var>implementation</var>, using the specified
* <var>mbeanInterface</var> class. This constructor can be used
* <var>mbeanInterface</var> class, and choosing whether the
* resultant MBean is an MXBean. This constructor can be used
* to make either Standard MBeans or MXBeans. Unlike the
* to make either Standard MBeans or MXBeans. Unlike the
* constructor {@link #StandardMBean(Object, Class)}, it
* constructor {@link #StandardMBean(Object, Class)}, it
* does not throw NotCompliantMBeanException.</p>
* does not throw NotCompliantMBeanException.</p>
...
@@ -267,7 +278,17 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -267,7 +278,17 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
public
<
T
>
StandardMBean
(
T
implementation
,
Class
<
T
>
mbeanInterface
,
public
<
T
>
StandardMBean
(
T
implementation
,
Class
<
T
>
mbeanInterface
,
boolean
isMXBean
)
{
boolean
isMXBean
)
{
try
{
try
{
construct
(
implementation
,
mbeanInterface
,
false
,
isMXBean
);
MBeanOptions
opts
=
new
MBeanOptions
();
if
(
mbeanInterface
==
null
)
{
mbeanInterface
=
Util
.
cast
(
Introspector
.
getStandardOrMXBeanInterface
(
implementation
.
getClass
(),
isMXBean
));
}
if
(
isMXBean
)
{
MXBeanMappingFactory
f
=
MXBeanMappingFactory
.
forInterface
(
mbeanInterface
);
opts
.
setMXBeanMappingFactory
(
f
);
}
construct
(
implementation
,
mbeanInterface
,
false
,
opts
);
}
catch
(
NotCompliantMBeanException
e
)
{
}
catch
(
NotCompliantMBeanException
e
)
{
throw
new
IllegalArgumentException
(
e
);
throw
new
IllegalArgumentException
(
e
);
}
}
...
@@ -275,12 +296,13 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -275,12 +296,13 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
/**
/**
* <p>Make a DynamicMBean out of <var>this</var>, using the specified
* <p>Make a DynamicMBean out of <var>this</var>, using the specified
* <var>mbeanInterface</var> class. This constructor can be used
* <var>mbeanInterface</var> class, and choosing whether the resulting
* MBean is an MXBean. This constructor can be used
* to make either Standard MBeans or MXBeans. Unlike the
* to make either Standard MBeans or MXBeans. Unlike the
* constructor {@link #StandardMBean(Object, Class)}, it
* constructor {@link #StandardMBean(Object, Class)}, it
* does not throw NotCompliantMBeanException.</p>
* does not throw NotCompliantMBeanException.</p>
*
*
* <p>Call {@link #StandardMBean(java.lang.Object, java.lang.Class, boolean)
* <p>Call
s
{@link #StandardMBean(java.lang.Object, java.lang.Class, boolean)
* this(this, mbeanInterface, isMXBean)}.
* this(this, mbeanInterface, isMXBean)}.
* This constructor is reserved to subclasses.</p>
* This constructor is reserved to subclasses.</p>
*
*
...
@@ -297,7 +319,77 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -297,7 +319,77 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
**/
**/
protected
StandardMBean
(
Class
<?>
mbeanInterface
,
boolean
isMXBean
)
{
protected
StandardMBean
(
Class
<?>
mbeanInterface
,
boolean
isMXBean
)
{
try
{
try
{
construct
(
null
,
mbeanInterface
,
true
,
isMXBean
);
MBeanOptions
opts
=
new
MBeanOptions
();
if
(
mbeanInterface
==
null
)
{
mbeanInterface
=
Introspector
.
getStandardOrMXBeanInterface
(
getClass
(),
isMXBean
);
}
if
(
isMXBean
)
{
MXBeanMappingFactory
f
=
MXBeanMappingFactory
.
forInterface
(
mbeanInterface
);
opts
.
setMXBeanMappingFactory
(
f
);
}
construct
(
null
,
mbeanInterface
,
true
,
opts
);
}
catch
(
NotCompliantMBeanException
e
)
{
throw
new
IllegalArgumentException
(
e
);
}
}
/**
* <p>Make a DynamicMBean out of the object
* <var>implementation</var>, using the specified
* <var>mbeanInterface</var> class and the specified options.</p>
*
* @param implementation The implementation of this MBean.
* @param mbeanInterface The Management Interface exported by this
* MBean's implementation. If <code>null</code>, then this
* object will use standard JMX design pattern to determine
* the management interface associated with the given
* implementation.
* @param options MBeanOptions that control the operation of the resulting
* MBean, as documented in the {@link MBeanOptions} class.
* @param <T> Allows the compiler to check
* that {@code implementation} does indeed implement the class
* described by {@code mbeanInterface}. The compiler can only
* check this if {@code mbeanInterface} is a class literal such
* as {@code MyMBean.class}.
*
* @exception IllegalArgumentException if the given
* <var>implementation</var> is null, or if the <var>mbeanInterface</var>
* does not follow JMX design patterns for Management Interfaces, or
* if the given <var>implementation</var> does not implement the
* specified interface.
**/
public
<
T
>
StandardMBean
(
T
implementation
,
Class
<
T
>
mbeanInterface
,
MBeanOptions
options
)
{
try
{
construct
(
implementation
,
mbeanInterface
,
false
,
options
);
}
catch
(
NotCompliantMBeanException
e
)
{
throw
new
IllegalArgumentException
(
e
);
}
}
/**
* <p>Make a DynamicMBean out of <var>this</var>, using the specified
* <var>mbeanInterface</var> class and the specified options.</p>
*
* <p>Calls {@link #StandardMBean(Object, Class, JMX.MBeanOptions)
* this(this,mbeanInterface,options)}.
* This constructor is reserved to subclasses.</p>
*
* @param mbeanInterface The Management Interface exported by this
* MBean.
* @param options MBeanOptions that control the operation of the resulting
* MBean, as documented in the {@link MBeanOptions} class.
*
* @exception IllegalArgumentException if the <var>mbeanInterface</var>
* does not follow JMX design patterns for Management Interfaces, or
* if <var>this</var> does not implement the specified interface.
**/
protected
StandardMBean
(
Class
<?>
mbeanInterface
,
MBeanOptions
options
)
{
try
{
construct
(
null
,
mbeanInterface
,
true
,
options
);
}
catch
(
NotCompliantMBeanException
e
)
{
}
catch
(
NotCompliantMBeanException
e
)
{
throw
new
IllegalArgumentException
(
e
);
throw
new
IllegalArgumentException
(
e
);
}
}
...
@@ -326,13 +418,19 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -326,13 +418,19 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
if
(
implementation
==
null
)
if
(
implementation
==
null
)
throw
new
IllegalArgumentException
(
"implementation is null"
);
throw
new
IllegalArgumentException
(
"implementation is null"
);
setImplementation2
(
implementation
);
}
if
(
isMXBean
())
{
private
<
T
>
void
setImplementation2
(
T
implementation
)
throws
NotCompliantMBeanException
{
Class
<?
super
T
>
intf
=
Util
.
cast
(
getMBeanInterface
());
if
(
this
.
mbean
.
isMXBean
())
{
this
.
mbean
=
new
MXBeanSupport
(
implementation
,
this
.
mbean
=
new
MXBeanSupport
(
implementation
,
Util
.<
Class
<
Object
>>
cast
(
getMBeanInterface
()));
intf
,
options
.
getMXBeanMappingFactory
());
}
else
{
}
else
{
this
.
mbean
=
new
StandardMBeanSupport
(
implementation
,
this
.
mbean
=
new
StandardMBeanSupport
(
implementation
,
intf
);
Util
.<
Class
<
Object
>>
cast
(
getMBeanInterface
()));
}
}
}
}
...
@@ -362,6 +460,19 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -362,6 +460,19 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
return
mbean
.
getResource
().
getClass
();
return
mbean
.
getResource
().
getClass
();
}
}
/**
* Return the MBeanOptions that were specified or implied for this StandardMBean
* instance. If an MBeanOptions object was supplied when this StandardMBean
* instance was constructed, and if that object has not been modified in the
* meantime, then the returned object will be equal to that object, although
* it might not be the same object.
* @return The MBeanOptions that were specified or implied for this StandardMBean
* instance.
*/
public
MBeanOptions
getOptions
()
{
return
options
.
uncanonical
();
}
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// From the DynamicMBean interface.
// From the DynamicMBean interface.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
...
@@ -726,7 +837,7 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -726,7 +837,7 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
* @return the MBeanNotificationInfo[] for the new MBeanInfo.
* @return the MBeanNotificationInfo[] for the new MBeanInfo.
**/
**/
MBeanNotificationInfo
[]
getNotifications
(
MBeanInfo
info
)
{
MBeanNotificationInfo
[]
getNotifications
(
MBeanInfo
info
)
{
return
null
;
return
info
.
getNotifications
()
;
}
}
/**
/**
...
@@ -1234,5 +1345,4 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
...
@@ -1234,5 +1345,4 @@ public class StandardMBean implements DynamicMBean, MBeanRegistration {
return
true
;
return
true
;
}
}
}
}
}
}
src/share/classes/javax/management/openmbean/CompositeDataInvocationHandler.java
浏览文件 @
ae942eac
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
package
javax.management.openmbean
;
package
javax.management.openmbean
;
import
com.sun.jmx.mbeanserver.MXBeanLookup
;
import
com.sun.jmx.mbeanserver.MXBeanLookup
;
import
com.sun.jmx.mbeanserver.
OpenConverter
;
import
com.sun.jmx.mbeanserver.
DefaultMXBeanMappingFactory
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Proxy
;
import
java.lang.reflect.Proxy
;
...
@@ -115,7 +115,12 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
...
@@ -115,7 +115,12 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
is null.
is null.
*/
*/
public
CompositeDataInvocationHandler
(
CompositeData
compositeData
)
{
public
CompositeDataInvocationHandler
(
CompositeData
compositeData
)
{
this
(
compositeData
,
null
);
this
(
compositeData
,
MXBeanMappingFactory
.
DEFAULT
);
}
public
CompositeDataInvocationHandler
(
CompositeData
compositeData
,
MXBeanMappingFactory
mappingFactory
)
{
this
(
compositeData
,
mappingFactory
,
null
);
}
}
/**
/**
...
@@ -134,11 +139,13 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
...
@@ -134,11 +139,13 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
is null.
is null.
*/
*/
CompositeDataInvocationHandler
(
CompositeData
compositeData
,
CompositeDataInvocationHandler
(
CompositeData
compositeData
,
MXBeanMappingFactory
mappingFactory
,
MXBeanLookup
lookup
)
{
MXBeanLookup
lookup
)
{
if
(
compositeData
==
null
)
if
(
compositeData
==
null
)
throw
new
IllegalArgumentException
(
"compositeData"
);
throw
new
IllegalArgumentException
(
"compositeData"
);
this
.
compositeData
=
compositeData
;
this
.
compositeData
=
compositeData
;
this
.
lookup
=
lookup
;
this
.
lookup
=
lookup
;
this
.
mappingFactory
=
mappingFactory
;
}
}
/**
/**
...
@@ -176,7 +183,7 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
...
@@ -176,7 +183,7 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
}
}
}
}
String
propertyName
=
OpenConverter
.
propertyName
(
method
);
String
propertyName
=
DefaultMXBeanMappingFactory
.
propertyName
(
method
);
if
(
propertyName
==
null
)
{
if
(
propertyName
==
null
)
{
throw
new
IllegalArgumentException
(
"Method is not getter: "
+
throw
new
IllegalArgumentException
(
"Method is not getter: "
+
method
.
getName
());
method
.
getName
());
...
@@ -185,7 +192,7 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
...
@@ -185,7 +192,7 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
if
(
compositeData
.
containsKey
(
propertyName
))
if
(
compositeData
.
containsKey
(
propertyName
))
openValue
=
compositeData
.
get
(
propertyName
);
openValue
=
compositeData
.
get
(
propertyName
);
else
{
else
{
String
decap
=
OpenConverter
.
decapitalize
(
propertyName
);
String
decap
=
DefaultMXBeanMappingFactory
.
decapitalize
(
propertyName
);
if
(
compositeData
.
containsKey
(
decap
))
if
(
compositeData
.
containsKey
(
decap
))
openValue
=
compositeData
.
get
(
decap
);
openValue
=
compositeData
.
get
(
decap
);
else
{
else
{
...
@@ -196,9 +203,10 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
...
@@ -196,9 +203,10 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
throw
new
IllegalArgumentException
(
msg
);
throw
new
IllegalArgumentException
(
msg
);
}
}
}
}
OpenConverter
converter
=
MXBeanMapping
mapping
=
OpenConverter
.
toConverter
(
method
.
getGenericReturnType
());
mappingFactory
.
mappingForType
(
method
.
getGenericReturnType
(),
return
converter
.
fromOpenValue
(
lookup
,
openValue
);
MXBeanMappingFactory
.
DEFAULT
);
return
mapping
.
fromOpenValue
(
openValue
);
}
}
/* This method is called when equals(Object) is
/* This method is called when equals(Object) is
...
@@ -242,4 +250,5 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
...
@@ -242,4 +250,5 @@ public class CompositeDataInvocationHandler implements InvocationHandler {
private
final
CompositeData
compositeData
;
private
final
CompositeData
compositeData
;
private
final
MXBeanLookup
lookup
;
private
final
MXBeanLookup
lookup
;
private
final
MXBeanMappingFactory
mappingFactory
;
}
}
src/share/classes/javax/management/openmbean/CompositeType.java
浏览文件 @
ae942eac
...
@@ -159,8 +159,8 @@ public class CompositeType extends OpenType<CompositeData> {
...
@@ -159,8 +159,8 @@ public class CompositeType extends OpenType<CompositeData> {
}
}
private
static
void
checkForNullElement
(
Object
[]
arg
,
String
argName
)
{
private
static
void
checkForNullElement
(
Object
[]
arg
,
String
argName
)
{
if
(
(
arg
==
null
)
||
(
arg
.
length
==
0
)
)
{
if
(
arg
==
null
)
{
throw
new
IllegalArgumentException
(
"Argument "
+
argName
+
"[] cannot be null
or empty
."
);
throw
new
IllegalArgumentException
(
"Argument "
+
argName
+
"[] cannot be null."
);
}
}
for
(
int
i
=
0
;
i
<
arg
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
arg
.
length
;
i
++)
{
if
(
arg
[
i
]
==
null
)
{
if
(
arg
[
i
]
==
null
)
{
...
...
src/share/classes/javax/management/openmbean/MXBeanMapping.java
0 → 100644
浏览文件 @
ae942eac
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package
javax.management.openmbean
;
import
java.io.InvalidObjectException
;
import
java.lang.reflect.Type
;
/**
* <p>A custom mapping between Java types and Open types for use in MXBeans.
* To define such a mapping, subclass this class and define at least the
* {@link #fromOpenValue fromOpenValue} and {@link #toOpenValue toOpenValue}
* methods, and optionally the {@link #checkReconstructible} method.
* Then either use an {@link MXBeanMappingClass} annotation on your custom
* Java types, or include this MXBeanMapping in an
* {@link MXBeanMappingFactory}.</p>
*
* <p>For example, suppose we have a class {@code MyLinkedList}, which looks
* like this:</p>
*
* <pre>
* public class MyLinkedList {
* public MyLinkedList(String name, MyLinkedList next) {...}
* public String getName() {...}
* public MyLinkedList getNext() {...}
* }
* </pre>
*
* <p>This is not a valid type for MXBeans, because it contains a
* self-referential property "next" defined by the {@code getNext()}
* method. MXBeans do not support recursive types. So we would like
* to specify a mapping for {@code MyLinkedList} explicitly. When an
* MXBean interface contains {@code MyLinkedList}, that will be mapped
* into a {@code String[]}, which is a valid Open Type.</p>
*
* <p>To define this mapping, we first subclass {@code MXBeanMapping}:</p>
*
* <pre>
* public class MyLinkedListMapping extends MXBeanMapping {
* public MyLinkedListMapping(Type type) throws OpenDataException {
* super(MyLinkedList.class, ArrayType.getArrayType(SimpleType.STRING));
* if (type != MyLinkedList.class)
* throw new OpenDataException("Mapping only valid for MyLinkedList");
* }
*
* {@literal @Override}
* public Object fromOpenValue(Object openValue) throws InvalidObjectException {
* String[] array = (String[]) openValue;
* MyLinkedList list = null;
* for (int i = array.length - 1; i >= 0; i--)
* list = new MyLinkedList(array[i], list);
* return list;
* }
*
* {@literal @Override}
* public Object toOpenValue(Object javaValue) throws OpenDataException {
* ArrayList<String> array = new ArrayList<String>();
* for (MyLinkedList list = (MyLinkedList) javaValue; list != null;
* list = list.getNext())
* array.add(list.getName());
* return array.toArray(new String[0]);
* }
* }
* </pre>
*
* <p>The call to the superclass constructor specifies what the
* original Java type is ({@code MyLinkedList.class}) and what Open
* Type it is mapped to ({@code
* ArrayType.getArrayType(SimpleType.STRING)}). The {@code
* fromOpenValue} method says how we go from the Open Type ({@code
* String[]}) to the Java type ({@code MyLinkedList}), and the {@code
* toOpenValue} method says how we go from the Java type to the Open
* Type.</p>
*
* <p>With this mapping defined, we can annotate the {@code MyLinkedList}
* class appropriately:</p>
*
* <pre>
* {@literal @MXBeanMappingClass}(MyLinkedListMapping.class)
* public class MyLinkedList {...}
* </pre>
*
* <p>Now we can use {@code MyLinkedList} in an MXBean interface and it
* will work.</p>
*
* <p>If we are unable to modify the {@code MyLinkedList} class,
* we can define an {@link MXBeanMappingFactory}. See the documentation
* of that class for further details.</p>
*/
public
abstract
class
MXBeanMapping
{
private
final
Type
javaType
;
private
final
OpenType
<?>
openType
;
private
final
Class
<?>
openClass
;
/**
* <p>Construct a mapping between the given Java type and the given
* Open Type.</p>
*
* @param javaType the Java type (for example, {@code MyLinkedList}).
* @param openType the Open Type (for example, {@code
* ArrayType.getArrayType(SimpleType.STRING)})
*
* @throws NullPointerException if either argument is null.
*/
protected
MXBeanMapping
(
Type
javaType
,
OpenType
<?>
openType
)
{
if
(
javaType
==
null
||
openType
==
null
)
throw
new
NullPointerException
(
"Null argument"
);
this
.
javaType
=
javaType
;
this
.
openType
=
openType
;
this
.
openClass
=
makeOpenClass
(
javaType
,
openType
);
}
/**
* <p>The Java type that was supplied to the constructor.</p>
* @return the Java type that was supplied to the constructor.
*/
public
final
Type
getJavaType
()
{
return
javaType
;
}
/**
* <p>The Open Type that was supplied to the constructor.</p>
* @return the Open Type that was supplied to the constructor.
*/
public
final
OpenType
<?>
getOpenType
()
{
return
openType
;
}
/**
* <p>The Java class that corresponds to instances of the
* {@linkplain #getOpenType() Open Type} for this mapping.</p>
* @return the Java class that corresponds to instances of the
* Open Type for this mapping.
* @see OpenType#getClassName
*/
public
final
Class
<?>
getOpenClass
()
{
return
openClass
;
}
private
static
Class
<?>
makeOpenClass
(
Type
javaType
,
OpenType
<?>
openType
)
{
if
(
javaType
instanceof
Class
<?>
&&
((
Class
<?>)
javaType
).
isPrimitive
())
return
(
Class
<?>)
javaType
;
try
{
String
className
=
OpenType
.
validClassName
(
openType
.
getClassName
());
return
Class
.
forName
(
className
,
false
,
null
);
}
catch
(
ClassNotFoundException
e
)
{
throw
new
RuntimeException
(
e
);
// should not happen
}
catch
(
OpenDataException
e
)
{
throw
new
IllegalArgumentException
(
"Bad OpenType: "
+
openType
,
e
);
}
}
/**
* <p>Convert an instance of the Open Type into the Java type.
* @param openValue the value to be converted.
* @return the converted value.
* @throws InvalidObjectException if the value cannot be converted.
*/
public
abstract
Object
fromOpenValue
(
Object
openValue
)
throws
InvalidObjectException
;
/**
* <p>Convert an instance of the Java type into the Open Type.
* @param javaValue the value to be converted.
* @return the converted value.
* @throws OpenDataException if the value cannot be converted.
*/
public
abstract
Object
toOpenValue
(
Object
javaValue
)
throws
OpenDataException
;
/**
* <p>Throw an appropriate InvalidObjectException if we will not
* be able to convert back from the open data to the original Java
* object. The {@link #fromOpenValue fromOpenValue} throws an
* exception if a given open data value cannot be converted. This
* method throws an exception if <em>no</em> open data values can
* be converted. The default implementation of this method never
* throws an exception. Subclasses can override it as
* appropriate.</p>
* @throws InvalidObjectException if {@code fromOpenValue} will throw
* an exception no matter what its argument is.
*/
public
void
checkReconstructible
()
throws
InvalidObjectException
{}
}
src/share/classes/javax/management/openmbean/MXBeanMappingClass.java
0 → 100644
浏览文件 @
ae942eac
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package
javax.management.openmbean
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
javax.management.NotCompliantMBeanException
;
/**
* Specifies the MXBean mapping to be used for this Java type.
* @see MXBeanMapping
*/
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
TYPE
)
@Documented
@Inherited
public
@interface
MXBeanMappingClass
{
/**
* <p>The {@link MXBeanMapping} class to be used to map the
* annotated type. This class must have a public constructor with
* a single argument of type {@link java.lang.reflect.Type}. The
* constructor will be called with the annotated type as an
* argument. See the {@code MXBeanMapping} documentation
* for an example.</p>
*
* <p>If the {@code MXBeanMapping} cannot in fact handle that
* type, the constructor should throw an {@link
* OpenDataException}. If the constructor throws this or any other
* exception then an MXBean in which the annotated type appears is
* invalid, and registering it in the MBean Server will produce a
* {@link NotCompliantMBeanException}.
*/
public
Class
<?
extends
MXBeanMapping
>
value
();
}
src/share/classes/javax/management/openmbean/MXBeanMappingFactory.java
0 → 100644
浏览文件 @
ae942eac
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package
javax.management.openmbean
;
import
com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory
;
import
java.lang.reflect.Type
;
/**
* <p>Defines how types are mapped for a given MXBean or set of MXBeans.
* An {@code MXBeanMappingFactory} can be specified either through the
* {@link MXBeanMappingFactoryClass} annotation, or through the
* {@link javax.management.JMX.MBeanOptions JMX.MBeanOptions} argument to a
* {@link javax.management.StandardMBean StandardMBean} constructor or MXBean
* proxy.</p>
*
* <p>An {@code MXBeanMappingFactory} must return an {@code MXBeanMapping}
* for any Java type that appears in the MXBeans that the factory is being
* used for. Usually it does that by handling any custom types, and
* forwarding everything else to the {@linkplain #DEFAULT default mapping
* factory}.</p>
*
* <p>Consider the {@code MyLinkedList} example from the {@link MXBeanMapping}
* documentation. If we are unable to change the {@code MyLinkedList} class
* to add an {@link MXBeanMappingClass} annotation, we could achieve the same
* effect by defining {@code MyLinkedListMappingFactory} as follows:</p>
*
* <pre>
* public class MyLinkedListMappingFactory implements MXBeanMappingFactory {
* public MyLinkedListMappingFactory() {}
*
* public MXBeanMapping mappingForType(Type t, MXBeanMappingFactory f)
* throws OpenDataException {
* if (t == MyLinkedList.class)
* return new MyLinkedListMapping(t);
* else
* return MXBeanMappingFactory.DEFAULT.mappingForType(t, f);
* }
* }
* </pre>
*
* <p>The mapping factory handles only the {@code MyLinkedList} class.
* Every other type is forwarded to the default mapping factory.
* This includes types such as {@code MyLinkedList[]} and
* {@code List<MyLinkedList>}; the default mapping factory will recursively
* invoke {@code MyLinkedListMappingFactory} to map the contained
* {@code MyLinkedList} type.</p>
*
* <p>Once we have defined {@code MyLinkedListMappingFactory}, we can use
* it in an MXBean interface like this:</p>
*
* <pre>
* {@literal @MXBeanMappingFactoryClass}(MyLinkedListMappingFactory.class)
* public interface SomethingMXBean {
* public MyLinkedList getSomething();
* }
* </pre>
*
* <p>Alternatively we can annotate the package that {@code SomethingMXBean}
* appears in, or we can supply the factory to a {@link
* javax.management.StandardMBean StandardMBean} constructor or MXBean
* proxy.</p>
*/
public
abstract
class
MXBeanMappingFactory
{
/**
* <p>Construct an instance of this class.</p>
*/
protected
MXBeanMappingFactory
()
{}
/**
* <p>Mapping factory that applies the default rules for MXBean
* mappings, as described in the <a
* href="../MXBean.html#MXBean-spec">MXBean specification</a>.</p>
*/
public
static
final
MXBeanMappingFactory
DEFAULT
=
new
DefaultMXBeanMappingFactory
();
/**
* <p>Determine the appropriate MXBeanMappingFactory to use for the given
* MXBean interface, based on its annotations. If the interface has an
* {@link MXBeanMappingFactoryClass @MXBeanMappingFactoryClass} annotation,
* that is used to determine the MXBeanMappingFactory. Otherwise, if the
* package containing the interface has such an annotation, that is used.
* Otherwise the MXBeanMappingFactory is the {@linkplain #DEFAULT default}
* one.</p>
*
* @param intf the MXBean interface for which to determine the
* MXBeanMappingFactory.
*
* @return the MXBeanMappingFactory for the given MXBean interface.
*
* @throws IllegalArgumentException if {@code intf} is null, or if an
* exception occurs while trying constructing an MXBeanMappingFactory
* based on an annotation. In the second case, the exception will appear
* in the {@linkplain Throwable#getCause() cause chain} of the
* {@code IllegalArgumentException}.
*/
public
static
MXBeanMappingFactory
forInterface
(
Class
<?>
intf
)
{
if
(
intf
==
null
)
throw
new
IllegalArgumentException
(
"Null interface"
);
MXBeanMappingFactoryClass
annot
=
intf
.
getAnnotation
(
MXBeanMappingFactoryClass
.
class
);
if
(
annot
==
null
)
{
Package
p
=
intf
.
getPackage
();
if
(
p
!=
null
)
annot
=
p
.
getAnnotation
(
MXBeanMappingFactoryClass
.
class
);
}
if
(
annot
==
null
)
return
MXBeanMappingFactory
.
DEFAULT
;
Class
<?
extends
MXBeanMappingFactory
>
factoryClass
=
annot
.
value
();
try
{
return
annot
.
value
().
newInstance
();
}
catch
(
Exception
e
)
{
throw
new
IllegalArgumentException
(
"Could not instantiate MXBeanMappingFactory "
+
factoryClass
.
getName
()
+
" from @MXBeanMappingFactoryClass"
,
e
);
}
}
/**
* <p>Return the mapping for the given Java type. Typically, a
* mapping factory will return mappings for types it handles, and
* forward other types to another mapping factory, most often
* the {@linkplain #DEFAULT default one}.</p>
* @param t the Java type to be mapped.
* @param f the original mapping factory that was consulted to do
* the mapping. A mapping factory should pass this parameter intact
* if it forwards a type to another mapping factory. In the example,
* this is how {@code MyLinkedListMappingFactory} works for types
* like {@code MyLinkedList[]} and {@code List<MyLinkedList>}.
* @return the mapping for the given type.
* @throws OpenDataException if this type cannot be mapped. This
* exception is appropriate if the factory is supposed to handle
* all types of this sort (for example, all linked lists), but
* cannot handle this particular type.
*/
public
abstract
MXBeanMapping
mappingForType
(
Type
t
,
MXBeanMappingFactory
f
)
throws
OpenDataException
;
}
src/share/classes/javax/management/openmbean/MXBeanMappingFactoryClass.java
0 → 100644
浏览文件 @
ae942eac
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package
javax.management.openmbean
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* <p>Specifies the MXBean mapping factory to be used for Java types
* in an MXBean interface, or in all MXBean interfaces in a package.</p>
*
* <p>Applying a mapping factory to all Java types in an MXBean interface
* looks like this:</p>
*
* <pre>
* {@literal @MXBeanMappingFactoryClass}(MyLinkedListMappingFactory.class)
* public interface SomethingMXBean {
* public MyLinkedList getSomething();
* }
* </pre>
*
* <p>Applying a mapping factory to all Java types in all MXBean interfaces
* in a package, say {@code com.example.mxbeans}, looks like this. In the
* package source directory, create a file called {@code package-info.java}
* with these contents:</p>
*
* <pre>
* {@literal @MXBeanMappingFactoryClass}(MyLinkedListMappingFactory.class)
* package com.example.mxbeans;
* </pre>
*
* @see MXBeanMappingFactory
*/
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
({
ElementType
.
TYPE
,
ElementType
.
PACKAGE
})
@Documented
@Inherited
public
@interface
MXBeanMappingFactoryClass
{
/**
* <p>The {@link MXBeanMappingFactory} class to be used to map
* types in the annotated interface or package. This class must
* have a public constructor with no arguments. See the {@code
* MXBeanMappingFactory} documentation for an example.</p>
*/
public
Class
<?
extends
MXBeanMappingFactory
>
value
();
}
src/share/classes/javax/management/openmbean/OpenType.java
浏览文件 @
ae942eac
...
@@ -219,7 +219,7 @@ public abstract class OpenType<T> implements Serializable {
...
@@ -219,7 +219,7 @@ public abstract class OpenType<T> implements Serializable {
});
});
}
}
private
static
String
validClassName
(
String
className
)
throws
OpenDataException
{
static
String
validClassName
(
String
className
)
throws
OpenDataException
{
className
=
valid
(
"className"
,
className
);
className
=
valid
(
"className"
,
className
);
// Check if className describes an array class, and determines its elements' class name.
// Check if className describes an array class, and determines its elements' class name.
...
...
test/javax/management/mxbean/CustomTypeTest.java
0 → 100644
浏览文件 @
ae942eac
此差异已折叠。
点击以展开。
test/javax/management/mxbean/customtypes/CustomLongMXBean.java
0 → 100644
浏览文件 @
ae942eac
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
// CustomLongMXBean.java - see CustomTypeTest
package
customtypes
;
import
javax.management.openmbean.MXBeanMappingFactoryClass
;
@MXBeanMappingFactoryClass
(
IntegerIsLongFactory
.
class
)
public
interface
CustomLongMXBean
extends
CustomMXBean
{}
src/share/classes/javax/management/ToQueryString
.java
→
test/javax/management/mxbean/customtypes/CustomMXBean
.java
浏览文件 @
ae942eac
/*
/*
* Copyright 200
8
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 200
7
Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* published by the Free Software Foundation.
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
...
@@ -23,16 +21,10 @@
...
@@ -23,16 +21,10 @@
* have any questions.
* have any questions.
*/
*/
package
javax.management
;
// CustomMXBean.java - see CustomTypeTest
/* QueryExp classes can extend this to get non-default treatment for
package
customtypes
;
* Query.toString(q). We're reluctant to change the public toString()
* methods of the classes because people might be parsing them, even
public
interface
CustomMXBean
{
* though that's rather fragile. But Query.toString(q) has no such
public
Integer
getX
();
* constraint so it can use the new toQueryString() method defined here.
*/
class
ToQueryString
{
String
toQueryString
()
{
return
toString
();
}
}
}
test/javax/management/mxbean/customtypes/IntegerIsLongFactory.java
0 → 100644
浏览文件 @
ae942eac
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
// IntegerIsLongFactory.java - see CustomTypeTest
package
customtypes
;
import
java.io.InvalidObjectException
;
import
java.lang.reflect.Type
;
import
javax.management.openmbean.MXBeanMapping
;
import
javax.management.openmbean.MXBeanMappingFactory
;
import
javax.management.openmbean.OpenDataException
;
import
javax.management.openmbean.SimpleType
;
public
class
IntegerIsLongFactory
implements
MXBeanMappingFactory
{
public
MXBeanMapping
forType
(
Type
t
,
MXBeanMappingFactory
f
)
throws
OpenDataException
{
if
(
t
==
Integer
.
class
)
return
IntegerIsLongMapping
;
else
return
MXBeanMappingFactory
.
DEFAULT
.
forType
(
t
,
f
);
}
private
static
final
MXBeanMapping
IntegerIsLongMapping
=
new
IntegerIsLongMapping
();
private
static
class
IntegerIsLongMapping
extends
MXBeanMapping
{
IntegerIsLongMapping
()
{
super
(
Integer
.
class
,
SimpleType
.
STRING
);
}
public
Object
fromOpenValue
(
Object
openValue
)
throws
InvalidObjectException
{
try
{
return
(
Long
)
openValue
;
}
catch
(
Exception
e
)
{
InvalidObjectException
ioe
=
new
InvalidObjectException
(
"oops"
);
ioe
.
initCause
(
e
);
throw
ioe
;
}
}
public
Object
toOpenValue
(
Object
javaValue
)
throws
OpenDataException
{
try
{
Integer
i
=
(
Integer
)
javaValue
;
return
new
Long
((
int
)
i
);
}
catch
(
Exception
e
)
{
OpenDataException
ode
=
new
OpenDataException
(
"oops"
);
ode
.
initCause
(
e
);
throw
ode
;
}
}
}
}
test/javax/management/mxbean/customtypes/IntegerIsStringFactory.java
0 → 100644
浏览文件 @
ae942eac
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
// IntegerIsStringFactory.java - see CustomTypeTest
package
customtypes
;
import
java.io.InvalidObjectException
;
import
java.lang.reflect.Type
;
import
javax.management.openmbean.MXBeanMapping
;
import
javax.management.openmbean.MXBeanMappingFactory
;
import
javax.management.openmbean.OpenDataException
;
import
javax.management.openmbean.SimpleType
;
public
class
IntegerIsStringFactory
extends
MXBeanMappingFactory
{
@Override
public
MXBeanMapping
mappingForType
(
Type
t
,
MXBeanMappingFactory
f
)
throws
OpenDataException
{
if
(
t
==
Integer
.
class
)
return
integerIsStringMapping
;
else
return
MXBeanMappingFactory
.
DEFAULT
.
mappingForType
(
t
,
f
);
}
private
static
final
MXBeanMapping
integerIsStringMapping
=
new
IntegerIsStringMapping
();
private
static
class
IntegerIsStringMapping
extends
MXBeanMapping
{
IntegerIsStringMapping
()
{
super
(
Integer
.
class
,
SimpleType
.
STRING
);
}
public
Object
fromOpenValue
(
Object
openValue
)
throws
InvalidObjectException
{
try
{
String
s
=
(
String
)
openValue
;
return
Integer
.
parseInt
(
s
);
}
catch
(
Exception
e
)
{
InvalidObjectException
ioe
=
new
InvalidObjectException
(
"oops"
);
ioe
.
initCause
(
e
);
throw
ioe
;
}
}
public
Object
toOpenValue
(
Object
javaValue
)
throws
OpenDataException
{
try
{
Integer
i
=
(
Integer
)
javaValue
;
return
i
.
toString
();
}
catch
(
Exception
e
)
{
OpenDataException
ode
=
new
OpenDataException
(
"oops"
);
ode
.
initCause
(
e
);
throw
ode
;
}
}
}
}
test/javax/management/mxbean/customtypes/package-info.java
0 → 100644
浏览文件 @
ae942eac
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
// package-info.java - test package annotations for custom types
@javax
.
management
.
openmbean
.
MXBeanMappingFactoryClass
(
IntegerIsStringFactory
.
class
)
package
customtypes
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录