Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Meiracle
spring-framework
提交
8d6d6be3
S
spring-framework
项目概览
Meiracle
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8d6d6be3
编写于
12月 11, 2013
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MBean registration happens in a fully synchronized fashion for consistent results
Issue: SPR-11002
上级
1b4e02b1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
62 addition
and
43 deletion
+62
-43
spring-context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java
...springframework/jmx/support/MBeanRegistrationSupport.java
+62
-43
未找到文件。
spring-context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java
浏览文件 @
8d6d6be3
...
...
@@ -16,7 +16,6 @@
package
org.springframework.jmx.support
;
import
java.util.Collections
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
import
javax.management.InstanceAlreadyExistsException
;
...
...
@@ -113,7 +112,7 @@ public class MBeanRegistrationSupport {
/**
* The beans that have been registered by this exporter.
*/
private
final
Set
<
ObjectName
>
registeredBeans
=
Collections
.
synchronizedSet
(
new
LinkedHashSet
<
ObjectName
>()
);
private
final
Set
<
ObjectName
>
registeredBeans
=
new
LinkedHashSet
<
ObjectName
>(
);
/**
* The policy used when registering an MBean and finding that it already exists.
...
...
@@ -188,40 +187,45 @@ public class MBeanRegistrationSupport {
* @throws JMException if the registration failed
*/
protected
void
doRegister
(
Object
mbean
,
ObjectName
objectName
)
throws
JMException
{
ObjectInstance
registeredBean
=
null
;
try
{
registeredBean
=
this
.
server
.
registerMBean
(
mbean
,
objectName
);
}
catch
(
InstanceAlreadyExistsException
ex
)
{
if
(
this
.
registrationPolicy
==
RegistrationPolicy
.
IGNORE_EXISTING
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Ignoring existing MBean at ["
+
objectName
+
"]"
);
}
ObjectName
actualObjectName
;
synchronized
(
this
.
registeredBeans
)
{
ObjectInstance
registeredBean
=
null
;
try
{
registeredBean
=
this
.
server
.
registerMBean
(
mbean
,
objectName
);
}
else
if
(
this
.
registrationPolicy
==
RegistrationPolicy
.
REPLACE_EXISTING
)
{
try
{
catch
(
InstanceAlreadyExistsException
ex
)
{
if
(
this
.
registrationPolicy
==
RegistrationPolicy
.
IGNORE_EXISTING
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Replacing existing MBean at ["
+
objectName
+
"]"
);
logger
.
debug
(
"Ignoring existing MBean at ["
+
objectName
+
"]"
);
}
}
else
if
(
this
.
registrationPolicy
==
RegistrationPolicy
.
REPLACE_EXISTING
)
{
try
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Replacing existing MBean at ["
+
objectName
+
"]"
);
}
this
.
server
.
unregisterMBean
(
objectName
);
registeredBean
=
this
.
server
.
registerMBean
(
mbean
,
objectName
);
}
catch
(
InstanceNotFoundException
ex2
)
{
logger
.
error
(
"Unable to replace existing MBean at ["
+
objectName
+
"]"
,
ex2
);
throw
ex
;
}
this
.
server
.
unregisterMBean
(
objectName
);
registeredBean
=
this
.
server
.
registerMBean
(
mbean
,
objectName
);
}
catch
(
InstanceNotFoundException
ex2
)
{
logger
.
error
(
"Unable to replace existing MBean at ["
+
objectName
+
"]"
,
ex2
);
else
{
throw
ex
;
}
}
else
{
throw
ex
;
// Track registration and notify listeners.
actualObjectName
=
(
registeredBean
!=
null
?
registeredBean
.
getObjectName
()
:
null
);
if
(
actualObjectName
==
null
)
{
actualObjectName
=
objectName
;
}
this
.
registeredBeans
.
add
(
actualObjectName
);
}
// Track registration and notify listeners.
ObjectName
actualObjectName
=
(
registeredBean
!=
null
?
registeredBean
.
getObjectName
()
:
null
);
if
(
actualObjectName
==
null
)
{
actualObjectName
=
objectName
;
}
this
.
registeredBeans
.
add
(
actualObjectName
);
onRegister
(
actualObjectName
,
mbean
);
}
...
...
@@ -229,7 +233,11 @@ public class MBeanRegistrationSupport {
* Unregisters all beans that have been registered by an instance of this class.
*/
protected
void
unregisterBeans
()
{
for
(
ObjectName
objectName
:
new
LinkedHashSet
<
ObjectName
>(
this
.
registeredBeans
))
{
Set
<
ObjectName
>
snapshot
;
synchronized
(
this
.
registeredBeans
)
{
snapshot
=
new
LinkedHashSet
<
ObjectName
>(
this
.
registeredBeans
);
}
for
(
ObjectName
objectName
:
snapshot
)
{
doUnregister
(
objectName
);
}
}
...
...
@@ -239,32 +247,43 @@ public class MBeanRegistrationSupport {
* @param objectName the suggested ObjectName for the MBean
*/
protected
void
doUnregister
(
ObjectName
objectName
)
{
try
{
// MBean might already have been unregistered by an external process.
if
(
this
.
server
.
isRegistered
(
objectName
))
{
this
.
server
.
unregisterMBean
(
objectName
);
onUnregister
(
objectName
);
}
else
{
if
(
logger
.
isWarnEnabled
())
{
logger
.
warn
(
"Could not unregister MBean ["
+
objectName
+
"] as said MBean "
+
"is not registered (perhaps already unregistered by an external process)"
);
boolean
actuallyUnregistered
=
false
;
synchronized
(
this
.
registeredBeans
)
{
if
(
this
.
registeredBeans
.
remove
(
objectName
))
{
try
{
// MBean might already have been unregistered by an external process
if
(
this
.
server
.
isRegistered
(
objectName
))
{
this
.
server
.
unregisterMBean
(
objectName
);
actuallyUnregistered
=
true
;
}
else
{
if
(
logger
.
isWarnEnabled
())
{
logger
.
warn
(
"Could not unregister MBean ["
+
objectName
+
"] as said MBean "
+
"is not registered (perhaps already unregistered by an external process)"
);
}
}
}
catch
(
JMException
ex
)
{
if
(
logger
.
isErrorEnabled
())
{
logger
.
error
(
"Could not unregister MBean ["
+
objectName
+
"]"
,
ex
);
}
}
}
}
catch
(
JMException
ex
)
{
if
(
logger
.
isErrorEnabled
())
{
logger
.
error
(
"Could not unregister MBean ["
+
objectName
+
"]"
,
ex
);
}
if
(
actuallyUnregistered
)
{
onUnregister
(
objectName
);
}
this
.
registeredBeans
.
remove
(
objectName
);
}
/**
* Return the {@link ObjectName ObjectNames} of all registered beans.
*/
protected
final
ObjectName
[]
getRegisteredObjectNames
()
{
return
this
.
registeredBeans
.
toArray
(
new
ObjectName
[
this
.
registeredBeans
.
size
()]);
synchronized
(
this
.
registeredBeans
)
{
return
this
.
registeredBeans
.
toArray
(
new
ObjectName
[
this
.
registeredBeans
.
size
()]);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录