@SuppressWarnings("unchecked")
public ObjectName registerMBean(Object managedResource, ObjectName objectName)
{
Object mbean;
if (isMBean(managedResource.getClass()))
{
mbean = managedResource;
}
else
{
mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
}
ObjectName actualObjectName = objectName;
try
{
doRegister(mbean, actualObjectName);
}
catch (JMException e)
{
throw new RuntimeException(e);
}
return actualObjectName;
}
java类javax.management.JMException的实例源码
DynamicMBeanExporter.java 文件源码
项目:alfresco-repository
阅读 19
收藏 0
点赞 0
评论 0
MBeanRegistry.java 文件源码
项目:fuck_zookeeper
阅读 24
收藏 0
点赞 0
评论 0
/**
* Registers a new MBean with the platform MBean server.
* @param bean the bean being registered
* @param parent if not null, the new bean will be registered as a child
* node of this parent.
*/
public void register(ZKMBeanInfo bean, ZKMBeanInfo parent)
throws JMException
{
assert bean != null;
String path = null;
if (parent != null) {
path = mapBean2Path.get(parent);
assert path != null;
}
path = makeFullPath(path, parent);
if(bean.isHidden())
return;
ObjectName oname = makeObjectName(path, bean);
try {
mBeanServer.registerMBean(bean, oname);
mapBean2Path.put(bean, path);
mapName2Bean.put(bean.getName(), bean);
} catch (JMException e) {
LOG.warn("Failed to register MBean " + bean.getName());
throw e;
}
}
ZooKeeperServerMain.java 文件源码
项目:fuck_zookeeper
阅读 23
收藏 0
点赞 0
评论 0
protected void initializeAndRun(String[] args)
throws ConfigException, IOException
{
try {
ManagedUtil.registerLog4jMBeans();
} catch (JMException e) {
LOG.warn("Unable to register log4j JMX control", e);
}
//再次解析配置文件(我也是醉了呀,又解析一遍!!!,写这段的人你出来我保证不打你)
ServerConfig config = new ServerConfig();
if (args.length == 1) {
config.parse(args[0]);
} else {
config.parse(args);
}
runFromConfig(config);
}
MBeanClientInterceptor.java 文件源码
项目:lams
阅读 35
收藏 0
点赞 0
评论 0
/**
* Routes a method invocation (not a property get/set) to the corresponding
* operation on the managed resource.
* @param method the method corresponding to operation on the managed resource.
* @param args the invocation arguments
* @return the value returned by the method invocation.
*/
private Object invokeOperation(Method method, Object[] args) throws JMException, IOException {
MethodCacheKey key = new MethodCacheKey(method.getName(), method.getParameterTypes());
MBeanOperationInfo info = this.allowedOperations.get(key);
if (info == null) {
throw new InvalidInvocationException("Operation '" + method.getName() +
"' is not exposed on the management interface");
}
String[] signature = null;
synchronized (this.signatureCache) {
signature = this.signatureCache.get(method);
if (signature == null) {
signature = JmxUtils.getMethodSignature(method);
this.signatureCache.put(method, signature);
}
}
return this.serverToUse.invoke(this.objectName, method.getName(), args, signature);
}
MBeanExporter.java 文件源码
项目:lams
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void registerManagedResource(Object managedResource, ObjectName objectName) throws MBeanExportException {
Assert.notNull(managedResource, "Managed resource must not be null");
Assert.notNull(objectName, "ObjectName must not be null");
try {
if (isMBean(managedResource.getClass())) {
doRegister(managedResource, objectName);
}
else {
ModelMBean mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
doRegister(mbean, objectName);
injectNotificationPublisherIfNecessary(managedResource, mbean, objectName);
}
}
catch (JMException ex) {
throw new UnableToRegisterMBeanException(
"Unable to register MBean [" + managedResource + "] with object name [" + objectName + "]", ex);
}
}
MBeanExporter.java 文件源码
项目:lams
阅读 24
收藏 0
点赞 0
评论 0
/**
* Build an adapted MBean for the given bean instance, if possible.
* <p>The default implementation builds a JMX 1.2 StandardMBean
* for the target's MBean/MXBean interface in case of an AOP proxy,
* delegating the interface's management operations to the proxy.
* @param bean the original bean instance
* @return the adapted MBean, or {@code null} if not possible
*/
@SuppressWarnings("unchecked")
protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException {
Class<?> targetClass = AopUtils.getTargetClass(bean);
if (targetClass != bean.getClass()) {
Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass);
if (ifc != null) {
if (!ifc.isInstance(bean)) {
throw new NotCompliantMBeanException("Managed bean [" + bean +
"] has a target class with an MXBean interface but does not expose it in the proxy");
}
return new StandardMBean(bean, ((Class<Object>) ifc), true);
}
else {
ifc = JmxUtils.getMBeanInterface(targetClass);
if (ifc != null) {
if (!ifc.isInstance(bean)) {
throw new NotCompliantMBeanException("Managed bean [" + bean +
"] has a target class with an MBean interface but does not expose it in the proxy");
}
return new StandardMBean(bean, ((Class<Object>) ifc));
}
}
}
return null;
}
CommonSpider.java 文件源码
项目:Gather-Platform
阅读 19
收藏 0
点赞 0
评论 0
/**
* 测试爬虫模板
*
* @param info
* @return
*/
public List<Webpage> testSpiderInfo(SpiderInfo info) throws JMException {
final ResultItemsCollectorPipeline resultItemsCollectorPipeline = new ResultItemsCollectorPipeline();
final String uuid = UUID.randomUUID().toString();
Task task = taskManager.initTask(uuid, info.getDomain(), info.getCallbackURL(), "spiderInfoId=" + info.getId() + "&spiderUUID=" + uuid);
task.addExtraInfo("spiderInfo", info);
QueueScheduler queueScheduler = new QueueScheduler();
MySpider spider = (MySpider) makeSpider(info, task)
.addPipeline(resultItemsCollectorPipeline)
.setScheduler(queueScheduler);
spider.startUrls(info.getStartURL());
//慎用爬虫监控,可能导致内存泄露
// spiderMonitor.register(spider);
spiderMap.put(uuid, spider);
taskManager.getTaskById(uuid).setState(State.RUNNING);
spider.run();
List<Webpage> webpageList = Lists.newLinkedList();
resultItemsCollectorPipeline.getCollected().forEach(resultItems -> webpageList.add(CommonWebpagePipeline.convertResultItems2Webpage(resultItems)));
return webpageList;
}
MBeanRegistry.java 文件源码
项目:https-github.com-apache-zookeeper
阅读 26
收藏 0
点赞 0
评论 0
/**
* Registers a new MBean with the platform MBean server.
* @param bean the bean being registered
* @param parent if not null, the new bean will be registered as a child
* node of this parent.
*/
public void register(ZKMBeanInfo bean, ZKMBeanInfo parent)
throws JMException
{
assert bean != null;
String path = null;
if (parent != null) {
path = mapBean2Path.get(parent);
assert path != null;
}
path = makeFullPath(path, parent);
if(bean.isHidden())
return;
ObjectName oname = makeObjectName(path, bean);
try {
synchronized (LOCK) {
mBeanServer.registerMBean(bean, oname);
mapBean2Path.put(bean, path);
}
} catch (JMException e) {
LOG.warn("Failed to register MBean " + bean.getName());
throw e;
}
}
ZooKeeperServerMain.java 文件源码
项目:https-github.com-apache-zookeeper
阅读 22
收藏 0
点赞 0
评论 0
protected void initializeAndRun(String[] args)
throws ConfigException, IOException, AdminServerException
{
try {
ManagedUtil.registerLog4jMBeans();
} catch (JMException e) {
LOG.warn("Unable to register log4j JMX control", e);
}
ServerConfig config = new ServerConfig();
if (args.length == 1) {
config.parse(args[0]);
} else {
config.parse(args);
}
runFromConfig(config);
}
CacheManagementDUnitTest.java 文件源码
项目:monarch
阅读 22
收藏 0
点赞 0
评论 0
public static void startManager() {
MemberMXBean bean = getManagementService().getMemberMXBean();
// When the cache is created if jmx-manager is true then we create the manager.
// So it may already exist when we get here.
if (!bean.isManagerCreated()) {
if (!bean.createManager()) {
fail("Could not create Manager");
} else if (!bean.isManagerCreated()) {
fail("Should have been a manager after createManager returned true.");
}
}
ManagerMXBean mngrBean = getManagementService().getManagerMXBean();
try {
mngrBean.start();
} catch (JMException e) {
fail("Could not start Manager " + e);
}
assertTrue(mngrBean.isRunning());
assertTrue(getManagementService().isManager());
assertTrue(bean.isManager());
}
ScanManager.java 文件源码
项目:jdk8u-jdk
阅读 32
收藏 0
点赞 0
评论 0
private void applyConfiguration(ScanManagerConfig bean)
throws IOException, JMException {
if (bean == null) return;
if (!sequencer.tryAcquire()) {
throw new IllegalStateException("Can't acquire lock");
}
try {
unregisterScanners();
final DirectoryScannerConfig[] scans = bean.getScanList();
if (scans == null) return;
for (DirectoryScannerConfig scan : scans) {
addDirectoryScanner(scan);
}
log.setConfig(bean.getInitialResultLogConfig());
} finally {
sequencer.release();
}
}
MBeanRegistry.java 文件源码
项目:ZooKeeper
阅读 23
收藏 0
点赞 0
评论 0
/**
* Registers a new MBean with the platform MBean server.
* @param bean the bean being registered
* @param parent if not null, the new bean will be registered as a child
* node of this parent.
*/
public void register(ZKMBeanInfo bean, ZKMBeanInfo parent)
throws JMException
{
assert bean != null;
String path = null;
if (parent != null) {
path = mapBean2Path.get(parent);
assert path != null;
}
path = makeFullPath(path, parent);
if(bean.isHidden())
return;
ObjectName oname = makeObjectName(path, bean);
try {
mBeanServer.registerMBean(bean, oname);
mapBean2Path.put(bean, path);
mapName2Bean.put(bean.getName(), bean);
} catch (JMException e) {
LOG.warn("Failed to register MBean " + bean.getName());
throw e;
}
}
ZooKeeperServerMain.java 文件源码
项目:ZooKeeper
阅读 25
收藏 0
点赞 0
评论 0
protected void initializeAndRun(String[] args)
throws ConfigException, IOException
{
try {
ManagedUtil.registerLog4jMBeans();
} catch (JMException e) {
LOG.warn("Unable to register log4j JMX control", e);
}
ServerConfig config = new ServerConfig();
if (args.length == 1) {
config.parse(args[0]);
} else {
config.parse(args);
}
runFromConfig(config);
}
AnnotatedStandardMBean.java 文件源码
项目:metrics-tomcat
阅读 24
收藏 0
点赞 0
评论 0
@SuppressWarnings({
"unchecked", "rawtypes"
})
public static String registerMBean(final Object object) throws JMException {
final ObjectName objectName = generateMBeanName(object.getClass());
final MBeanServer context = ManagementFactory.getPlatformMBeanServer();
final String mbeanName = object.getClass().getName() + "MBean";
for (final Class c : object.getClass().getInterfaces()) {
if (mbeanName.equals(c.getName())) {
context.registerMBean(new AnnotatedStandardMBean(object, c), objectName);
return objectName.getCanonicalName();
}
}
context.registerMBean(object, objectName);
return objectName.getCanonicalName();
}
SegmentRunner.java 文件源码
项目:cassandra-reaper
阅读 35
收藏 0
点赞 0
评论 0
private void handlePotentialStuckRepairs(LazyInitializer<Set<String>> busyHosts, String hostName)
throws ConcurrentException {
if (!busyHosts.get().contains(hostName) && context.storage instanceof IDistributedStorage) {
try (JmxProxy hostProxy
= context.jmxConnectionFactory.connect(hostName, context.config.getJmxConnectionTimeoutInSeconds())) {
// We double check that repair is still running there before actually canceling repairs
if (hostProxy.isRepairRunning()) {
LOG.warn(
"A host ({}) reported that it is involved in a repair, but there is no record "
+ "of any ongoing repair involving the host. Sending command to abort all repairs "
+ "on the host.",
hostName);
hostProxy.cancelAllRepairs();
hostProxy.close();
}
} catch (ReaperException | RuntimeException | InterruptedException | JMException e) {
LOG.debug("failed to cancel repairs on host {}", hostName, e);
}
}
}
MBeanRegistry.java 文件源码
项目:zookeeper
阅读 20
收藏 0
点赞 0
评论 0
/**
* Registers a new MBean with the platform MBean server.
* @param bean the bean being registered
* @param parent if not null, the new bean will be registered as a child
* node of this parent.
*/
public void register(ZKMBeanInfo bean, ZKMBeanInfo parent)
throws JMException
{
assert bean != null;
String path = null;
if (parent != null) {
path = mapBean2Path.get(parent);
assert path != null;
}
path = makeFullPath(path, parent);
if(bean.isHidden())
return;
ObjectName oname = makeObjectName(path, bean);
try {
mBeanServer.registerMBean(bean, oname);
mapBean2Path.put(bean, path);
mapName2Bean.put(bean.getName(), bean);
} catch (JMException e) {
LOG.warn("Failed to register MBean " + bean.getName());
throw e;
}
}
CommonsSpiderService.java 文件源码
项目:spider
阅读 20
收藏 0
点赞 0
评论 0
/**
* 根据爬虫模板ID批量启动任务
*
* @param spiderInfoIdList 爬虫模板ID列表
* @return 任务id列表
*/
public ResultListBundle<String> startAll(List<String> spiderInfoIdList) {
return bundleBuilder.listBundle(spiderInfoIdList.toString(), () -> {
List<String> taskIdList = Lists.newArrayList();
for (String id : spiderInfoIdList) {
try {
SpiderInfo info = spiderInfoService.getById(id).getResult();
String taskId = commonSpider.start(info);
taskIdList.add(taskId);
} catch (JMException e) {
LOG.error("启动任务ID{}出错,{}", id, e);
}
}
return taskIdList;
});
}
ZooKeeperServerMain.java 文件源码
项目:SecureKeeper
阅读 28
收藏 0
点赞 0
评论 0
protected void initializeAndRun(String[] args)
throws ConfigException, IOException, AdminServerException
{
try {
ManagedUtil.registerLog4jMBeans();
} catch (JMException e) {
LOG.warn("Unable to register log4j JMX control", e);
}
ServerConfig config = new ServerConfig();
if (args.length == 1) {
config.parse(args[0]);
} else {
config.parse(args);
}
runFromConfig(config);
}
MBeanClientInterceptor.java 文件源码
项目:spring4-understanding
阅读 31
收藏 0
点赞 0
评论 0
/**
* Routes a method invocation (not a property get/set) to the corresponding
* operation on the managed resource.
* @param method the method corresponding to operation on the managed resource.
* @param args the invocation arguments
* @return the value returned by the method invocation.
*/
private Object invokeOperation(Method method, Object[] args) throws JMException, IOException {
MethodCacheKey key = new MethodCacheKey(method.getName(), method.getParameterTypes());
MBeanOperationInfo info = this.allowedOperations.get(key);
if (info == null) {
throw new InvalidInvocationException("Operation '" + method.getName() +
"' is not exposed on the management interface");
}
String[] signature = null;
synchronized (this.signatureCache) {
signature = this.signatureCache.get(method);
if (signature == null) {
signature = JmxUtils.getMethodSignature(method);
this.signatureCache.put(method, signature);
}
}
return this.serverToUse.invoke(this.objectName, method.getName(), args, signature);
}
MBeanExporter.java 文件源码
项目:spring4-understanding
阅读 26
收藏 0
点赞 0
评论 0
@Override
public void registerManagedResource(Object managedResource, ObjectName objectName) throws MBeanExportException {
Assert.notNull(managedResource, "Managed resource must not be null");
Assert.notNull(objectName, "ObjectName must not be null");
try {
if (isMBean(managedResource.getClass())) {
doRegister(managedResource, objectName);
}
else {
ModelMBean mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
doRegister(mbean, objectName);
injectNotificationPublisherIfNecessary(managedResource, mbean, objectName);
}
}
catch (JMException ex) {
throw new UnableToRegisterMBeanException(
"Unable to register MBean [" + managedResource + "] with object name [" + objectName + "]", ex);
}
}
ZooKeeperServerMain.java 文件源码
项目:zookeeper
阅读 23
收藏 0
点赞 0
评论 0
protected void initializeAndRun(String[] args)
throws ConfigException, IOException
{
try {
ManagedUtil.registerLog4jMBeans();
} catch (JMException e) {
LOG.warn("Unable to register log4j JMX control", e);
}
ServerConfig config = new ServerConfig();
if (args.length == 1) {
config.parse(args[0]);
} else {
config.parse(args);
}
runFromConfig(config);
}
MBeanRegistry.java 文件源码
项目:StreamProcessingInfrastructure
阅读 27
收藏 0
点赞 0
评论 0
/**
* Registers a new MBean with the platform MBean server.
* @param bean the bean being registered
* @param parent if not null, the new bean will be registered as a child
* node of this parent.
*/
public void register(ZKMBeanInfo bean, ZKMBeanInfo parent)
throws JMException
{
assert bean != null;
String path = null;
if (parent != null) {
path = mapBean2Path.get(parent);
assert path != null;
}
path = makeFullPath(path, parent);
if(bean.isHidden())
return;
ObjectName oname = makeObjectName(path, bean);
try {
mBeanServer.registerMBean(bean, oname);
mapBean2Path.put(bean, path);
mapName2Bean.put(bean.getName(), bean);
} catch (JMException e) {
LOG.warn("Failed to register MBean " + bean.getName());
throw e;
}
}
MBeanExporter.java 文件源码
项目:spring
阅读 29
收藏 0
点赞 0
评论 0
/**
* Build an adapted MBean for the given bean instance, if possible.
* <p>The default implementation builds a JMX 1.2 StandardMBean
* for the target's MBean/MXBean interface in case of an AOP proxy,
* delegating the interface's management operations to the proxy.
* @param bean the original bean instance
* @return the adapted MBean, or {@code null} if not possible
*/
@SuppressWarnings("unchecked")
protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException {
Class<?> targetClass = AopUtils.getTargetClass(bean);
if (targetClass != bean.getClass()) {
Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass);
if (ifc != null) {
if (!ifc.isInstance(bean)) {
throw new NotCompliantMBeanException("Managed bean [" + bean +
"] has a target class with an MXBean interface but does not expose it in the proxy");
}
return new StandardMBean(bean, ((Class<Object>) ifc), true);
}
else {
ifc = JmxUtils.getMBeanInterface(targetClass);
if (ifc != null) {
if (!ifc.isInstance(bean)) {
throw new NotCompliantMBeanException("Managed bean [" + bean +
"] has a target class with an MBean interface but does not expose it in the proxy");
}
return new StandardMBean(bean, ((Class<Object>) ifc));
}
}
}
return null;
}
MBeanRegistry.java 文件源码
项目:bigstreams
阅读 25
收藏 0
点赞 0
评论 0
/**
* Registers a new MBean with the platform MBean server.
* @param bean the bean being registered
* @param parent if not null, the new bean will be registered as a child
* node of this parent.
*/
public void register(ZKMBeanInfo bean, ZKMBeanInfo parent)
throws JMException
{
assert bean != null;
String path = null;
if (parent != null) {
path = mapBean2Path.get(parent);
assert path != null;
}
path = makeFullPath(path, parent);
mapBean2Path.put(bean, path);
mapName2Bean.put(bean.getName(), bean);
if(bean.isHidden())
return;
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName oname = makeObjectName(path, bean);
try {
mbs.registerMBean(bean, oname);
} catch (JMException e) {
LOG.warn("Failed to register MBean " + bean.getName());
throw e;
}
}
TestSupport.java 文件源码
项目:Camel
阅读 27
收藏 0
点赞 0
评论 0
public static QuickfixjEngine createEngine(boolean lazy) throws ConfigError, FieldConvertError, IOException, JMException {
SessionID sessionID = new SessionID("FIX.4.4:SENDER->TARGET");
MessageStoreFactory mockMessageStoreFactory = Mockito.mock(MessageStoreFactory.class);
MessageStore mockMessageStore = Mockito.mock(MessageStore.class);
Mockito.when(mockMessageStore.getCreationTime()).thenReturn(new Date());
Mockito.when(mockMessageStoreFactory.create(sessionID)).thenReturn(mockMessageStore);
SessionSettings settings = new SessionSettings();
settings.setLong(sessionID, Session.SETTING_HEARTBTINT, 10);
settings.setString(sessionID, Session.SETTING_START_TIME, "00:00:00");
settings.setString(sessionID, Session.SETTING_END_TIME, "00:00:00");
settings.setString(sessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE);
settings.setLong(sessionID, Acceptor.SETTING_SOCKET_ACCEPT_PORT, 8000);
settings.setBool(sessionID, Session.SETTING_USE_DATA_DICTIONARY, false);
return new QuickfixjEngine("", settings,
mockMessageStoreFactory,
Mockito.mock(LogFactory.class),
Mockito.mock(MessageFactory.class), lazy);
}
ZooKeeperServerMain.java 文件源码
项目:bigstreams
阅读 23
收藏 0
点赞 0
评论 0
protected void initializeAndRun(String[] args)
throws ConfigException, IOException
{
try {
ManagedUtil.registerLog4jMBeans();
} catch (JMException e) {
LOG.warn("Unable to register log4j JMX control", e);
}
ServerConfig config = new ServerConfig();
if (args.length == 1) {
config.parse(args[0]);
} else {
config.parse(args);
}
runFromConfig(config);
}
MBeanClientInterceptor.java 文件源码
项目:my-spring-cache-redis
阅读 32
收藏 0
点赞 0
评论 0
/**
* Routes a method invocation (not a property get/set) to the corresponding
* operation on the managed resource.
* @param method the method corresponding to operation on the managed resource.
* @param args the invocation arguments
* @return the value returned by the method invocation.
*/
private Object invokeOperation(Method method, Object[] args) throws JMException, IOException {
MethodCacheKey key = new MethodCacheKey(method.getName(), method.getParameterTypes());
MBeanOperationInfo info = this.allowedOperations.get(key);
if (info == null) {
throw new InvalidInvocationException("Operation '" + method.getName() +
"' is not exposed on the management interface");
}
String[] signature = null;
synchronized (this.signatureCache) {
signature = this.signatureCache.get(method);
if (signature == null) {
signature = JmxUtils.getMethodSignature(method);
this.signatureCache.put(method, signature);
}
}
return this.serverToUse.invoke(this.objectName, method.getName(), args, signature);
}
FolderMBean.java 文件源码
项目:Pogamut3
阅读 23
收藏 0
点赞 0
评论 0
/**
* Export this folder to a JMX MBeanServer.
* @param mBeanServer MBeanServer where this folder will be registered
* @param domain domain under which the folder will appear, eg. "MyDomain"
* @throws javax.management.JMException
*/
public void registerFolderHierarchyInJMX(MBeanServer mBeanServer, String domain, String path) throws JMException, IntrospectionException {
// register this folder
ObjectName objectName = ObjectName.getInstance(domain + ":type=" + path + ",name=" + folder.getName());
mBeanServer.registerMBean(this, objectName);
// register all subfolders
for (Folder f : folder.getFolders()) {
new FolderMBean(f).registerFolderHierarchyInJMX(mBeanServer, domain, path + "." + folder.getName());
}
}
JmxDumpUtil.java 文件源码
项目:alfresco-repository
阅读 21
收藏 0
点赞 0
评论 0
/**
* Dumps a local or remote MBeanServer's entire object tree for support purposes. Nested arrays and CompositeData
* objects in MBean attribute values are handled.
*
* @param connection
* the server connection (or server itself)
* @param out
* PrintWriter to write the output to
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void dumpConnection(MBeanServerConnection connection, PrintWriter out) throws IOException
{
JmxDumpUtil.showStartBanner(out);
// Get all the object names
Set<ObjectName> objectNames = connection.queryNames(null, null);
// Sort the names (don't assume ObjectName implements Comparable in JDK 1.5)
Set<ObjectName> newObjectNames = new TreeSet<ObjectName>(new Comparator<ObjectName>()
{
public int compare(ObjectName o1, ObjectName o2)
{
return o1.toString().compareTo(o2.toString());
}
});
newObjectNames.addAll(objectNames);
objectNames = newObjectNames;
// Dump each MBean
for (ObjectName objectName : objectNames)
{
try
{
printMBeanInfo(connection, objectName, out);
}
catch (JMException e)
{
// Sometimes beans can disappear while we are examining them
}
}
}
JmxDumpUtil.java 文件源码
项目:alfresco-repository
阅读 21
收藏 0
点赞 0
评论 0
/**
* Dumps the details of a single MBean.
*
* @param connection
* the server connection (or server itself)
* @param objectName
* the object name
* @param out
* PrintWriter to write the output to
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws JMException
* Signals a JMX error
*/
private static void printMBeanInfo(MBeanServerConnection connection, ObjectName objectName, PrintWriter out)
throws IOException, JMException
{
Map<String, Object> attributes = new TreeMap<String, Object>();
MBeanInfo info = connection.getMBeanInfo(objectName);
attributes.put("** Object Name", objectName.toString());
attributes.put("** Object Type", info.getClassName());
for (MBeanAttributeInfo element : info.getAttributes())
{
Object value;
if (element.isReadable())
{
try
{
value = connection.getAttribute(objectName, element.getName());
}
catch (Exception e)
{
value = JmxDumpUtil.PROTECTED_VALUE;
}
}
else
{
value = JmxDumpUtil.PROTECTED_VALUE;
}
attributes.put(element.getName(), value);
}
if (objectName.getCanonicalName().equals("Alfresco:Name=SystemProperties"))
{
String osName = (String) attributes.get(OS_NAME);
if (osName != null && osName.toLowerCase().startsWith("linux"))
{
attributes.put(OS_NAME, updateOSNameAttributeForLinux(osName));
}
}
tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, 0);
}