Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
e0bb8382
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
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,发现更多精彩内容 >>
提交
e0bb8382
编写于
8月 26, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MBeanServerFactoryBean returns JDK 1.5 platform MBeanServer for agent id "" (SPR-5909)
上级
8fb53c80
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
44 addition
and
25 deletion
+44
-25
org.springframework.context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java
...rg/springframework/jmx/access/MBeanClientInterceptor.java
+1
-0
org.springframework.context/src/main/java/org/springframework/jmx/access/NotificationListenerRegistrar.java
...ngframework/jmx/access/NotificationListenerRegistrar.java
+2
-1
org.springframework.context/src/main/java/org/springframework/jmx/support/JmxUtils.java
...c/main/java/org/springframework/jmx/support/JmxUtils.java
+15
-12
org.springframework.context/src/main/java/org/springframework/jmx/support/MBeanServerFactoryBean.java
...g/springframework/jmx/support/MBeanServerFactoryBean.java
+1
-0
org.springframework.context/src/test/java/org/springframework/jmx/support/MBeanServerFactoryBeanTests.java
...ingframework/jmx/support/MBeanServerFactoryBeanTests.java
+25
-12
未找到文件。
org.springframework.context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java
浏览文件 @
e0bb8382
...
...
@@ -161,6 +161,7 @@ public class MBeanClientInterceptor
* attempt being made to locate the attendant MBeanServer, unless
* the {@link #setServiceUrl "serviceUrl"} property has been set.
* @see javax.management.MBeanServerFactory#findMBeanServer(String)
* <p>Specifying the empty String indicates the platform MBeanServer.
*/
public
void
setAgentId
(
String
agentId
)
{
this
.
agentId
=
agentId
;
...
...
org.springframework.context/src/main/java/org/springframework/jmx/access/NotificationListenerRegistrar.java
浏览文件 @
e0bb8382
/*
* Copyright 2002-200
8
the original author or authors.
* Copyright 2002-200
9
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -105,6 +105,7 @@ public class NotificationListenerRegistrar extends NotificationListenerHolder
* attempt being made to locate the attendant MBeanServer, unless
* the {@link #setServiceUrl "serviceUrl"} property has been set.
* @see javax.management.MBeanServerFactory#findMBeanServer(String)
* <p>Specifying the empty String indicates the platform MBeanServer.
*/
public
void
setAgentId
(
String
agentId
)
{
this
.
agentId
=
agentId
;
...
...
org.springframework.context/src/main/java/org/springframework/jmx/support/JmxUtils.java
浏览文件 @
e0bb8382
...
...
@@ -91,28 +91,31 @@ public abstract class JmxUtils {
* <code>MBeanServer</code> can be found. Logs a warning if more than one
* <code>MBeanServer</code> found, returning the first one from the list.
* @param agentId the agent identifier of the MBeanServer to retrieve.
* If this parameter is <code>null</code>, all registered MBeanServers are
*
consider
ed.
* If this parameter is <code>null</code>, all registered MBeanServers are
considered.
*
If the empty String is given, the platform MBeanServer will be return
ed.
* @return the <code>MBeanServer</code> if found
* @throws org.springframework.jmx.MBeanServerNotFoundException
* if no <code>MBeanServer</code> could be found
* @see javax.management.MBeanServerFactory#findMBeanServer(String)
*/
public
static
MBeanServer
locateMBeanServer
(
String
agentId
)
throws
MBeanServerNotFoundException
{
List
servers
=
MBeanServerFactory
.
findMBeanServer
(
agentId
);
MBeanServer
server
=
null
;
if
(
servers
!=
null
&&
servers
.
size
()
>
0
)
{
// Check to see if an MBeanServer is registered.
if
(
servers
.
size
()
>
1
&&
logger
.
isWarnEnabled
())
{
logger
.
warn
(
"Found more than one MBeanServer instance"
+
(
agentId
!=
null
?
" with agent id ["
+
agentId
+
"]"
:
""
)
+
". Returning first from list."
);
// null means any registered server, but "" specifically means the platform server
if
(!
""
.
equals
(
agentId
))
{
List
<
MBeanServer
>
servers
=
MBeanServerFactory
.
findMBeanServer
(
agentId
);
if
(
servers
!=
null
&&
servers
.
size
()
>
0
)
{
// Check to see if an MBeanServer is registered.
if
(
servers
.
size
()
>
1
&&
logger
.
isWarnEnabled
())
{
logger
.
warn
(
"Found more than one MBeanServer instance"
+
(
agentId
!=
null
?
" with agent id ["
+
agentId
+
"]"
:
""
)
+
". Returning first from list."
);
}
server
=
servers
.
get
(
0
);
}
server
=
(
MBeanServer
)
servers
.
get
(
0
);
}
if
(
server
==
null
&&
agentId
==
null
)
{
if
(
server
==
null
&&
!
StringUtils
.
hasLength
(
agentId
)
)
{
// Attempt to load the PlatformMBeanServer.
try
{
server
=
ManagementFactory
.
getPlatformMBeanServer
();
...
...
org.springframework.context/src/main/java/org/springframework/jmx/support/MBeanServerFactoryBean.java
浏览文件 @
e0bb8382
...
...
@@ -84,6 +84,7 @@ public class MBeanServerFactoryBean implements FactoryBean<MBeanServer>, Initial
* and (importantly) if said MBeanServer cannot be located no
* attempt will be made to create a new MBeanServer (and an
* MBeanServerNotFoundException will be thrown at resolution time).
* <p>Specifying the empty String indicates the platform MBeanServer.
* @see javax.management.MBeanServerFactory#findMBeanServer(String)
*/
public
void
setAgentId
(
String
agentId
)
{
...
...
org.springframework.context/src/test/java/org/springframework/jmx/support/MBeanServerFactoryBeanTests.java
浏览文件 @
e0bb8382
/*
* Copyright 2002-200
5
the original author or authors.
* Copyright 2002-200
9
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
...
...
@@ -17,7 +17,7 @@
package
org.springframework.jmx.support
;
import
java.util.List
;
import
java.lang.management.ManagementFactory
;
import
javax.management.MBeanServer
;
import
javax.management.MBeanServerFactory
;
...
...
@@ -25,6 +25,7 @@ import junit.framework.TestCase;
/**
* @author Rob Harrop
* @author Juergen Hoeller
*/
public
class
MBeanServerFactoryBeanTests
extends
TestCase
{
...
...
@@ -32,7 +33,7 @@ public class MBeanServerFactoryBeanTests extends TestCase {
MBeanServerFactoryBean
bean
=
new
MBeanServerFactoryBean
();
bean
.
afterPropertiesSet
();
try
{
MBeanServer
server
=
(
MBeanServer
)
bean
.
getObject
();
MBeanServer
server
=
bean
.
getObject
();
assertNotNull
(
"The MBeanServer should not be null"
,
server
);
}
finally
{
...
...
@@ -45,7 +46,7 @@ public class MBeanServerFactoryBeanTests extends TestCase {
bean
.
setDefaultDomain
(
"foo"
);
bean
.
afterPropertiesSet
();
try
{
MBeanServer
server
=
(
MBeanServer
)
bean
.
getObject
();
MBeanServer
server
=
bean
.
getObject
();
assertEquals
(
"The default domain should be foo"
,
"foo"
,
server
.
getDefaultDomain
());
}
finally
{
...
...
@@ -60,7 +61,7 @@ public class MBeanServerFactoryBeanTests extends TestCase {
bean
.
setLocateExistingServerIfPossible
(
true
);
bean
.
afterPropertiesSet
();
try
{
MBeanServer
otherServer
=
(
MBeanServer
)
bean
.
getObject
();
MBeanServer
otherServer
=
bean
.
getObject
();
assertSame
(
"Existing MBeanServer not located"
,
server
,
otherServer
);
}
finally
{
...
...
@@ -72,12 +73,24 @@ public class MBeanServerFactoryBeanTests extends TestCase {
}
}
public
void
testWithLocateExistingAnd
NoExisting
Server
()
{
public
void
testWithLocateExistingAnd
FallbackToPlatform
Server
()
{
MBeanServerFactoryBean
bean
=
new
MBeanServerFactoryBean
();
bean
.
setLocateExistingServerIfPossible
(
true
);
bean
.
afterPropertiesSet
();
try
{
assertNotNull
(
"MBeanServer not created"
,
bean
.
getObject
());
assertSame
(
ManagementFactory
.
getPlatformMBeanServer
(),
bean
.
getObject
());
}
finally
{
bean
.
destroy
();
}
}
public
void
testWithEmptyAgentIdAndFallbackToPlatformServer
()
{
MBeanServerFactoryBean
bean
=
new
MBeanServerFactoryBean
();
bean
.
setAgentId
(
""
);
bean
.
afterPropertiesSet
();
try
{
assertSame
(
ManagementFactory
.
getPlatformMBeanServer
(),
bean
.
getObject
());
}
finally
{
bean
.
destroy
();
...
...
@@ -98,12 +111,12 @@ public class MBeanServerFactoryBeanTests extends TestCase {
bean
.
afterPropertiesSet
();
try
{
MBeanServer
server
=
(
MBeanServer
)
bean
.
getObject
();
List
servers
=
MBeanServerFactory
.
findMBeanServer
(
null
);
MBeanServer
server
=
bean
.
getObject
();
List
<
MBeanServer
>
servers
=
MBeanServerFactory
.
findMBeanServer
(
null
);
boolean
found
=
false
;
for
(
int
x
=
0
;
x
<
servers
.
size
();
x
++
)
{
if
(
servers
.
get
(
x
)
==
server
)
{
for
(
MBeanServer
candidate
:
servers
)
{
if
(
candidate
==
server
)
{
found
=
true
;
break
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录