jmx例子一则

  • C4_615995
    了解作者
  • 11.9KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-02 01:12
    上传日期
博文链接:https://aga.iteye.com/blog/209568
JmxEgs.rar
内容介绍
package com.cxz.dynamic; import java.lang.reflect.Constructor; import java.util.Iterator; import javax.management.Attribute; import javax.management.AttributeList; import javax.management.AttributeNotFoundException; import javax.management.DynamicMBean; import javax.management.InvalidAttributeValueException; import javax.management.MBeanAttributeInfo; import javax.management.MBeanConstructorInfo; import javax.management.MBeanException; import javax.management.MBeanInfo; import javax.management.MBeanNotificationInfo; import javax.management.MBeanOperationInfo; import javax.management.MBeanParameterInfo; import javax.management.ReflectionException; public class HelloDynamic implements DynamicMBean { private String name = null; private MBeanInfo mBeanInfo = null; private String className = null; private String description = null; private MBeanAttributeInfo[] attributes = null; private MBeanConstructorInfo[] constructors = null; private MBeanOperationInfo[] operations = null; MBeanNotificationInfo[] mBeanNotificationInfoArray = null; public HelloDynamic() { init(); buildDynamicMBean(); } private void buildDynamicMBean() { Constructor[] thisConstructors = this.getClass().getConstructors(); // create the constructors. constructors[0] = new MBeanConstructorInfo( "HelloDynamic(): Constructs a HelloDynamic object", thisConstructors[0]); // define the attribute of a mbean and its getter/setter attributes[0] = new MBeanAttributeInfo("Name", "java.lang.String", "Name:name string.", true, true, false); MBeanParameterInfo[] params = null; // Define the operation array. operations[0] = new MBeanOperationInfo("print", "print(): print the name", params, "void", MBeanOperationInfo.INFO); // Dynamically create an instance of a MBean. // Includes:attributes, constructors, operations, notifications mBeanInfo = new MBeanInfo(className, description, attributes, constructors, operations, mBeanNotificationInfoArray); } private void init() { className = this.getClass().getName(); description = "Simple implementation of a dynamic MBean."; attributes = new MBeanAttributeInfo[1]; constructors = new MBeanConstructorInfo[1]; operations = new MBeanOperationInfo[1]; mBeanNotificationInfoArray = new MBeanNotificationInfo[1]; } /** * Add a new operation to the MBean Dynamically */ private void dynamicAddOperation() { init(); operations = new MBeanOperationInfo[2]; buildDynamicMBean(); operations[1] = new MBeanOperationInfo("print1", "print1(): print the name", null, "void", MBeanOperationInfo.INFO); mBeanInfo = new MBeanInfo(className, description, attributes, constructors, operations, mBeanNotificationInfoArray); } public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { if (attribute == null) { return null; } else if ("Name".equals(attribute)) { return name; } else { return null; } } public AttributeList getAttributes(String[] attributeNames) { if (attributes == null) { return null; } else { AttributeList resultList = new AttributeList(); if (attributes.length == 0) { return resultList; } else { for (int i = 0; i < attributeNames.length; i++) { try { Object value = getAttribute(attributeNames[i]); resultList.add(new Attribute(attributeNames[i], value)); } catch (Exception ex) { ex.printStackTrace(); } } } return resultList; } } public MBeanInfo getMBeanInfo() { return mBeanInfo; } public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException { if (actionName.equals("print")) { System.out.println("Hello, " + name + ", this is HelloDynamic!"); dynamicAddOperation(); } else if (actionName.equals("print1")) { System.out.println("This is the dynamic operation"); } else { throw new ReflectionException(new NoSuchMethodException( actionName), "Cannot find the operation " + actionName + " in " + className); } return null; } public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { if (attribute == null) { return; } else { String name = attribute.getName(); Object value = attribute.getValue(); try { if (name.equals("Name")) { if (value == null) { name = null; } else if ((Class.forName("java.lang.String")) .isAssignableFrom(value.getClass())) { this.name = (String) value; } } } catch (Exception ex) { ex.printStackTrace(); } } } public AttributeList setAttributes(AttributeList attributes) { if (attributes == null) return null; AttributeList resultList = new AttributeList(); if (attributes.isEmpty()) { return resultList; } for (Iterator i = attributes.iterator(); i.hasNext();) { Attribute attr = (Attribute) i.next(); try { setAttribute(attr); String name = attr.getName(); Object value = getAttribute(name); resultList.add(new Attribute(name, value)); } catch (Exception ex) { ex.printStackTrace(); } } return resultList; } }
评论
    相关推荐
    • nodejs http-server开启https的证书
      https证书文件,nodejs http-server开启https的证书,可以直接在本地启动https的协议,方便部署和使用。
    • http https 切换
      http https切换代码,能够实现网站在传输信息的过程中不易遭人盗取
    • Http2Https-crx插件
      将书签中的http转换为https 害怕用https书签替换旧的http书签? 随着许多网站迁移到https,旧的http书签使星标图像为空。 搜索并转换为https! ****************************************************** ***********...
    • levelweb:通过 httphttps 的 LevelDB
      Leveldb 通过httphttps 。 用法 var http = require ( 'http' ) ; var levelweb = require ( 'levelweb' ) ; var db = require ( 'level' ) ( './db' ) ; var opts = { prefix : '/' } ; // // like this... // ...
    • LocomotiveCMS https to http-crx插件
      语言:English 将登录网址从https替换为http以进行开发 此扩展程序供使用机车cms开发应用程序时供个人使用。 为了易于在开发模式下使用,此扩展程序将https登录网址替换为http
    • timed-out:超时HTTPHTTPS请求
      超时HTTP / HTTPS请求 ESOCKETTIMEDOUT ClientRequest时,发出错误code属性等于ETIMEDOUT或ESOCKETTIMEDOUT错误对象。 用法 import http from 'node:http' ; import timedOut from 'timed-out' ; const request = ...
    • http:https的镜像
      框架HTTP
    • https镜像
      scp镜 SCP基金会部分界面https //
    • CookieIsolator:分离 HTTPHTTPS cookie
      松散隔离:HTTP cookie 只能在 HTTP 通道中发送,而 HTTPS cookie 可以在 HTTP(不带安全标志)和 HTTPS 通道中发送。 严格隔离:HTTP cookie 和 HTTPS cookie 只能分别在 HTTPHTTPS 通道中发送。 Ext Secure...
    • https协议
      NULL 博文链接:https://willwen.iteye.com/blog/1988199