private void buildDynamicMBeanInfo() { Constructor[] constructors = this.getClass().getConstructors(); dConstructors[0] = new MBeanConstructorInfo( "HierarchyDynamicMBean(): Constructs a HierarchyDynamicMBean instance", constructors[0]); vAttributes.add(new MBeanAttributeInfo(THRESHOLD, "java.lang.String", "The \"threshold\" state of the hiearchy.", true, true, false)); MBeanParameterInfo[] params = new MBeanParameterInfo[1]; params[0] = new MBeanParameterInfo("name", "java.lang.String", "Create a logger MBean" ); dOperations[0] = new MBeanOperationInfo("addLoggerMBean", "addLoggerMBean(): add a loggerMBean", params , "javax.management.ObjectName", MBeanOperationInfo.ACTION); }
if (attrInfo.length > 0) { for (int i = 0; i < attrInfo.length; i++) { log.info(" ** NAME: \t" + attrInfo[i].getName()); log.info(" DESCR: \t" + attrInfo[i].getDescription()); log.info(" TYPE: \t" + attrInfo[i].getType() + "\tREAD: " + attrInfo[i].isReadable() + "\tWRITE: " + attrInfo[i].isWritable()); MBeanConstructorInfo[] constrInfo = info.getConstructors(); for (int i = 0; i < constrInfo.length; i++) { log.info(" ** NAME: \t" + constrInfo[i].getName()); log.info(" DESCR: \t" + constrInfo[i].getDescription()); log.info(" PARAM: \t" + constrInfo[i].getSignature().length + " parameter(s)"); if (opInfo.length > 0) { for (int i = 0; i < opInfo.length; i++) { log.info(" ** NAME: \t" + opInfo[i].getName()); log.info(" DESCR: \t" + opInfo[i].getDescription()); log.info(" PARAM: \t" + opInfo[i].getSignature().length + " parameter(s)");
MBeanInfo info = mbsc.getMBeanInfo(name); for (MBeanAttributeInfo mbinfo : info.getAttributes()) { Object batchSize = mbsc.getAttribute(name, mbinfo.getName()); System.out.println(mbinfo.getName() + "\t" + batchSize); System.out.println(info.getDescription()); for (MBeanConstructorInfo i : info.getConstructors()) { System.out.println(i.getDescription()); System.out.println(i.getName()); for (MBeanParameterInfo pi : i.getSignature()) { System.out.println(pi.getDescription()); System.out.println(pi.getName()); System.out.println(pi.getType()); System.out.println(oi.getDescription()); System.out.println(oi.getName()); System.out.println(oi.getReturnType()); for (MBeanParameterInfo pi : oi.getSignature()) { System.out.println(pi.getDescription()); Object batchSize = mbsc.getAttribute(name, mbinfo.getName()); System.out.println(mbinfo.getName() + "\t" + batchSize); System.out.println("isIs: " + mbinfo.isIs() + "\treadable: " + mbinfo.isReadable()
@Override public MBeanInfo getMBeanInfo() { MBeanInfo mBeanInfo = new MBeanInfo( this.getClass().getName(), "简单的自定义DynamicMBean", of(new MBeanAttributeInfo("value", String.class.getName(), "动态属性value", true, true, false)), of(new MBeanConstructorInfo(this.getClass().getSimpleName(), "默认构造器", new MBeanParameterInfo[0])), of(new MBeanOperationInfo("displayValue", "自定义 displayValue 方法", new MBeanParameterInfo[0], String.class.getName(), ACTION)), new MBeanNotificationInfo[0]); return mBeanInfo; }
_attributeMap.put(attributeInfo.getName(), dynamicMetric); attributeInfoList.add(new MBeanAttributeInfo(SENSOR_NAME_TAG, String.class.getName(), "The name of the metric sensor", true, false, false)); MBeanConstructorInfo constructorInfo = new MBeanConstructorInfo( String.format("Default %s Constructor", getClass().getSimpleName()), getClass().getConstructors()[0]);
final String sysUpTimeDescription = "Elapsed time in milliseconds since the last boot of the Java application (corresponds to SNMP attribute system.sysUpTime.0)"; final MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[] { new MBeanAttributeInfo("SysName", String.class.getName(), sysNameDescription, true, true, false), new MBeanAttributeInfo("SysDescr", String.class.getName(), sysDescrDescription, true, true, false), new MBeanAttributeInfo("SysLocation", String.class.getName(), sysLocationDescription, true, true, false), new MBeanAttributeInfo("SysContact", String.class.getName(), sysContactDescription, true, true, false), new MBeanAttributeInfo("SysUpTime", long.class.getName(), sysUpTimeDescription, true, false, false) }; final MBeanConstructorInfo constructor1 = new MBeanConstructorInfo(getClass().getName(), "Constructor without parameter", new MBeanParameterInfo[] {}); final MBeanConstructorInfo constructor2 = new MBeanConstructorInfo(getClass().getName(), "Constructor with only sysName and sysDescr parameters", new MBeanParameterInfo[] { new MBeanParameterInfo("sysName", String.class.getName(), sysNameDescription), new MBeanParameterInfo("sysDescr", String.class.getName(), sysDescrDescription) }); final MBeanConstructorInfo constructor3 = new MBeanConstructorInfo(getClass().getName(), "Constructor with all parameters", new MBeanParameterInfo[] { new MBeanParameterInfo("sysName", String.class.getName(), sysNameDescription), new MBeanParameterInfo("sysDescr", String.class.getName(), sysDescrDescription),
new MBeanConstructorInfo("ConnectionPoolMBean(): Construct a ConnectionPoolMBean object.", ConnectionPoolMBean.class.getConstructors()[0]) }; new MBeanOperationInfo(OPERATION_NAME_SHUTDOWN, "Stop and dispose this connection pool.", new MBeanParameterInfo[]{}, "void", MBeanOperationInfo.ACTION) };
protected Object createObject() throws SAXException { return new MBeanConstructorInfo(name, description, signature); } }
private MBeanConstructorInfo[] createMBeanConstructorInfo(MBeanMetaData metadata, MBeanDescription descrs) { Class mbeanClass = metadata.mbean.getClass(); Constructor[] ctors = mbeanClass.getConstructors(); MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[ctors.length]; for (int i = 0; i < ctors.length; ++i) { Constructor constructor = ctors[i]; String descr = descrs == null ? null : descrs.getConstructorDescription(constructor); Class[] params = constructor.getParameterTypes(); MBeanParameterInfo[] paramsInfo = new MBeanParameterInfo[params.length]; for (int j = 0; j < params.length; ++j) { Class param = params[j]; String paramName = descrs == null ? null : descrs.getConstructorParameterName(constructor, j); String paramDescr = descrs == null ? null : descrs.getConstructorParameterDescription(constructor, j); paramsInfo[j] = new MBeanParameterInfo(paramName, param.getName(), paramDescr); } String ctorName = constructor.getName(); MBeanConstructorInfo info = new MBeanConstructorInfo(ctorName.substring(ctorName.lastIndexOf('.') + 1), descr, paramsInfo); constructors[i] = info; } return constructors; }
assertNotNull(constructors); for (int i = 0; i < constructors.length; i++) { MBeanParameterInfo[] signature = constructors[i].getSignature(); assertNotNull(signature); for (int i = 0; i < operations.length; i++) { MBeanParameterInfo[] signature = operations[i].getSignature(); assertNotNull(signature);
/** * Constructs a <code>MBeanConstructorInfo</code> instance based upon a * <code>javax.management.MBeanConstructorInfo</code> instance. * * @param mbeanConstructorInfo The <code>javax.management.MBeanConstructorInfo</code> to base this instance on. */ public MBeanConstructorInfo(javax.management.MBeanConstructorInfo mbeanConstructorInfo) { name = mbeanConstructorInfo.getName(); description = mbeanConstructorInfo.getDescription(); signature = convertSignature(mbeanConstructorInfo.getSignature()); }
@Override public boolean equals( final MBeanConstructorInfo a, final MBeanConstructorInfo b ) { return a == b || a.getName().equals( b.getName() ) && Arrays.equals( a.getSignature(), b.getSignature() ); } }
private int getConstructorIndex(MBeanConstructorInfo cons) { Integer idx = (Integer)m_mapConstructorToResourceIndex.get(cons); if (idx != null) { return idx.intValue(); } // do multiple constuctors with the same arg count exist? if (m_setAmbiguousConstructors.contains(cons)) return -1; // no signature match - try using parameter count int nbParams = cons.getSignature().length; idx = (Integer)m_mapConstructorParamCountToResourceIndex.get(new Integer(nbParams)); if (idx != null) { return idx.intValue(); } return 0; }
@Override public int hashCode( final MBeanConstructorInfo o ) { return o.getName().hashCode(); }
MBeanInfo info = mbsc.getMBeanInfo(name); for (MBeanAttributeInfo mbinfo : info.getAttributes()) { Object batchSize = mbsc.getAttribute(name, mbinfo.getName()); System.out.println(mbinfo.getName() + "\t" + batchSize); System.out.println(info.getDescription()); for (MBeanConstructorInfo i : info.getConstructors()) { System.out.println(i.getDescription()); System.out.println(i.getName()); for (MBeanParameterInfo pi : i.getSignature()) { System.out.println(pi.getDescription()); System.out.println(pi.getName()); System.out.println(pi.getType()); System.out.println(oi.getDescription()); System.out.println(oi.getName()); System.out.println(oi.getReturnType()); for (MBeanParameterInfo pi : oi.getSignature()) { System.out.println(pi.getDescription()); Object batchSize = mbsc.getAttribute(name, mbinfo.getName()); System.out.println(mbinfo.getName() + "\t" + batchSize); System.out.println("isIs: " + mbinfo.isIs() + "\treadable: " + mbinfo.isReadable()
new MBeanAttributeInfo("AuthConfig", "java.lang.String", "", true, true, false) }; Constructor<?> ctor = null; new MBeanConstructorInfo("Default ctor", ctor) }; Method getConfiguration = null; new MBeanOperationInfo("Access the LoginConfiguration", getConfiguration) }; MBeanInfo info = new MBeanInfo(c.getName(), "Default JAAS LoginConfig",
_attributeMap.put(attributeInfo.getName(), dynamicMetric); attributeInfoList.add(new MBeanAttributeInfo(SENSOR_NAME_TAG, String.class.getName(), "The name of the metric sensor", true, false, false)); MBeanConstructorInfo constructorInfo = new MBeanConstructorInfo( String.format("Default %s Constructor", getClass().getSimpleName()), getClass().getConstructors()[0]);
new MBeanConstructorInfo("ConnectionPoolMBean(): Construct a ConnectionPoolMBean object.", ConnectionPoolMBean.class.getConstructors()[0]) }; new MBeanOperationInfo(OPERATION_NAME_SHUTDOWN, "Stop and dispose this connection pool.", new MBeanParameterInfo[]{}, "void", MBeanOperationInfo.ACTION) };
private MBeanConstructorInfo[] createMBeanConstructorsInfo1() { Constructor[] constructors = this.getClass().getConstructors(); MBeanConstructorInfo[] dConstructors = new MBeanConstructorInfo[constructors.length]; for (int i = 0; i < constructors.length; i++) { //if (constructors[i].getParameterTypes().length > 0) dConstructors[i] = new MBeanConstructorInfo( "Instantiate " + THIS_CLASS_NAME + " with the specified container.", constructors[i]); } return dConstructors; }
/** * Constructs a <code>MBeanConstructorInfo</code> instance based upon a * <code>javax.management.MBeanConstructorInfo</code> instance. * * @param mbeanConstructorInfo The <code>javax.management.MBeanConstructorInfo</code> to base this instance on. */ public MBeanConstructorInfo(javax.management.MBeanConstructorInfo mbeanConstructorInfo) { name = mbeanConstructorInfo.getName(); description = mbeanConstructorInfo.getDescription(); signature = convertSignature(mbeanConstructorInfo.getSignature()); }