private MBeanAttributeInfo[] keys() { List<MBeanAttributeInfo> keys = new ArrayList<>(); for ( String key : config.keySet() ) { keys.add( new MBeanAttributeInfo( key, String.class.getName(), describeConfigParameter( key ), true, false, false ) ); } return keys.toArray( new MBeanAttributeInfo[keys.size()] ); }
@Override public MBeanInfo getMBeanInfo() { MBeanAttributeInfo attr = new MBeanAttributeInfo("name", "java.lang.String", "", true, false, false); return new MBeanInfo( TestDynamicMBean.class.getName(), "", new MBeanAttributeInfo[]{attr}, new MBeanConstructorInfo[0], new MBeanOperationInfo[0], new MBeanNotificationInfo[0]); }
@Override public MBeanInfo getMBeanInfo() { MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[metrics.size()]; int i = 0; for (Map.Entry<String, KafkaMetric> entry : this.metrics.entrySet()) { String attribute = entry.getKey(); KafkaMetric metric = entry.getValue(); attrs[i] = new MBeanAttributeInfo(attribute, double.class.getName(), metric.metricName().description(), true, false, false); i += 1; } return new MBeanInfo(this.getClass().getName(), "", attrs, null, null, null); }
/** * Returns attributes defined for this MBean as an array of MBeanAttributeInfo objects. * * @return attributes defined as an array of MBeanAttributeInfo objects. */ @Override protected MBeanAttributeInfo[] createMBeanAttributeInfo() { MBeanAttributeInfo[] attributesInfo = new MBeanAttributeInfo[MAX_ATTRIBUTES_COUNT]; /* * First letter in attribute name has to be 'V' so that getVersion is called. With 'v' it looks * for getversion, same for others */ attributesInfo[0] = new MBeanAttributeInfo("Version", String.class.getName(), "GemFire Enterprise Version", true, /* readable */ false, /* writable */ false);/* has getter with name like 'is****' */ attributesInfo[1] = new MBeanAttributeInfo("RefreshInterval", String.class.getName(), "The interval (in seconds) between auto-polling for updating member & statistics resources. If this is '-1', it means the this MBean has not yet been initialized. First call to getMembers operation will initialize this MBean.", true, /* readable */ false, /* writable */ false);/* has getter with name like 'is****' */ attributesInfo[2] = new MBeanAttributeInfo("Id", String.class.getName(), "Identifier of the GemFire Enterprise. If this is 'N/A', it means the this MBean has not yet been initialized. First call to getMembers operation will initialize this MBean.", true, /* readable */ false, /* writable */ false);/* has getter with name like 'is****' */ return attributesInfo; }
@Override public MBeanInfo getMBeanInfo() { if (dirtyAttributeInfoCache) { synchronized(metricsMap) { attributeInfos = new MBeanAttributeInfo[metricsMap.size()]; int i = 0; for (String key : metricsMap.keySet()) { attributeInfos[i] = new MBeanAttributeInfo( key, metricsMap.get(key).getClass().getName(), key, true, true/*writable*/, false); i++; } dirtyAttributeInfoCache = false; } } return new MBeanInfo( this.getClass().getName(), "metrics information", attributeInfos, ctors, ops, notifs); }
MBeanAttributeInfo newAttrInfo(String name, String desc, String type) { return new MBeanAttributeInfo(getAttrName(name), type, desc, true, false, false); // read-only, non-is }
void registerLayoutMBean(Layout layout) { if(layout == null) return; String name = getAppenderName(appender)+",layout="+layout.getClass().getName(); cat.debug("Adding LayoutMBean:"+name); ObjectName objectName = null; try { LayoutDynamicMBean appenderMBean = new LayoutDynamicMBean(layout); objectName = new ObjectName("log4j:appender="+name); if (!server.isRegistered(objectName)) { registerMBean(appenderMBean, objectName); dAttributes.add(new MBeanAttributeInfo("appender=" + name, "javax.management.ObjectName", "The " + name + " layout.", true, true, false)); } } catch(JMException e) { cat.error("Could not add DynamicLayoutMBean for ["+name+"].", e); } catch(java.beans.IntrospectionException e) { cat.error("Could not add DynamicLayoutMBean for ["+name+"].", e); } catch(RuntimeException e) { cat.error("Could not add DynamicLayoutMBean for ["+name+"].", e); } }
void registerAppenderMBean(Appender appender) { String name = getAppenderName(appender); cat.debug("Adding AppenderMBean for appender named "+name); ObjectName objectName = null; try { AppenderDynamicMBean appenderMBean = new AppenderDynamicMBean(appender); objectName = new ObjectName("log4j", "appender", name); if (!server.isRegistered(objectName)) { registerMBean(appenderMBean, objectName); dAttributes.add(new MBeanAttributeInfo("appender=" + name, "javax.management.ObjectName", "The " + name + " appender.", true, true, false)); } } catch(JMException e) { cat.error("Could not add appenderMBean for ["+name+"].", e); } catch(java.beans.IntrospectionException e) { cat.error("Could not add appenderMBean for ["+name+"].", e); } catch(RuntimeException e) { cat.error("Could not add appenderMBean for ["+name+"].", e); } }
private void buildDynamicMBeanInfo() { Constructor[] constructors = this.getClass().getConstructors(); dConstructors[0] = new MBeanConstructorInfo( "HierarchyDynamicMBean(): Constructs a HierarchyDynamicMBean instance", constructors[0]); dAttributes.add(new MBeanAttributeInfo("name", "java.lang.String", "The name of this Logger.", true, false, false)); dAttributes.add(new MBeanAttributeInfo("priority", "java.lang.String", "The priority of this logger.", true, true, false)); MBeanParameterInfo[] params = new MBeanParameterInfo[2]; params[0] = new MBeanParameterInfo("class name", "java.lang.String", "add an appender to this logger"); params[1] = new MBeanParameterInfo("appender name", "java.lang.String", "name of the appender"); dOperations[0] = new MBeanOperationInfo("addAppender", "addAppender(): add an appender", params, "void", MBeanOperationInfo.ACTION); }
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); }
dAttributes.add(new MBeanAttributeInfo(name, returnClassName, "Dynamic",
private MBeanAttributeInfo createAttributeInfo(Monitor<?> m) { final String type = (m instanceof NumericMonitor<?>) ? Number.class.getName() : String.class.getName(); return new MBeanAttributeInfo( "value", type, m.getConfig().toString(), true, // isReadable false, // isWritable false); // isIs } }
attrs[i++] = new MBeanAttributeInfo(name, "long", "Minimum request processing time in milliseconds in last " + postfix + ".", true, false, false); attrs[i++] = new MBeanAttributeInfo(name, "long", "Minimum request processing time in milliseconds in last " + postfix + ".", true, false, false); attrs[i++] = new MBeanAttributeInfo(name, "long", "Average request processing time in milliseconds in last " + postfix + ".", true, false, false); attrs[i++] = new MBeanAttributeInfo(name, "double", "Average requests per second in last " + postfix + ".", true, false, false); attrs[i++] = new MBeanAttributeInfo(name, "double", "Request count in last " + postfix + ".", true, false, false);
attrs[i++] = new MBeanAttributeInfo(name, "long", "Minimum request processing time in milliseconds in last " + postfix + ".", true, false, false); attrs[i++] = new MBeanAttributeInfo(name, "long", "Minimum request processing time in milliseconds in last " + postfix + ".", true, false, false); attrs[i++] = new MBeanAttributeInfo(name, "long", "Average request processing time in milliseconds in last " + postfix + ".", true, false, false); attrs[i++] = new MBeanAttributeInfo(name, "double", "Average requests per second in last " + postfix + ".", true, false, false); attrs[i++] = new MBeanAttributeInfo(name, "double", "Request count in last " + postfix + ".", true, false, false);
dAttributes.add(new MBeanAttributeInfo(name, returnClassName, "Dynamic",
ObjectName addLoggerMBean(Logger logger) { String name = logger.getName(); ObjectName objectName = null; try { LoggerDynamicMBean loggerMBean = new LoggerDynamicMBean(logger); objectName = new ObjectName("log4j", "logger", name); if (!server.isRegistered(objectName)) { registerMBean(loggerMBean, objectName); NotificationFilterSupport nfs = new NotificationFilterSupport(); nfs.enableType(ADD_APPENDER + logger.getName()); log.debug("---Adding logger [" + name + "] as listener."); nbs.addNotificationListener(loggerMBean, nfs, null); vAttributes.add(new MBeanAttributeInfo("logger=" + name, "javax.management.ObjectName", "The " + name + " logger.", true, true, // this makes the object // clickable false)); } } catch(JMException e) { log.error("Could not add loggerMBean for ["+name+"].", e); } catch(RuntimeException e) { log.error("Could not add loggerMBean for ["+name+"].", e); } return objectName; }
attrs[i] = new MBeanAttributeInfo( name, field.getType().getName(),
protected void findFields(Object instance) { // traverse class hierarchy and find all annotated fields for(Class<?> clazz=instance.getClass(); clazz != null && clazz != Object.class; clazz=clazz.getSuperclass()) { Field[] fields=clazz.getDeclaredFields(); for(Field field: fields) { ManagedAttribute attr=field.getAnnotation(ManagedAttribute.class); Property prop=field.getAnnotation(Property.class); boolean expose_prop=prop != null && prop.exposeAsManagedAttribute(); boolean expose=attr != null || expose_prop; if(expose) { String fieldName=attr != null? attr.name() : (prop != null? prop.name() : null); if(fieldName != null && fieldName.trim().isEmpty()) fieldName=field.getName(); String descr=attr != null? attr.description() : prop.description(); boolean writable=attr != null? attr.writable() : prop.writable(); MBeanAttributeInfo info=new MBeanAttributeInfo(fieldName, field.getType().getCanonicalName(), descr, true, !Modifier.isFinal(field.getModifiers()) && writable, false); atts.put(fieldName, new AttributeEntry(field.getName(), info)); } } } }
@Before public void setup() throws Throwable { jmxServer = mock( MBeanServer.class ); beanName = new ObjectName( "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference" ); attributeName = "name"; when( jmxServer.queryNames( new ObjectName( "*:*" ), null ) ) .thenReturn( asSet( beanName ) ); when( jmxServer.getMBeanInfo( beanName ) ) .thenReturn( new MBeanInfo( "org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[]{ new MBeanAttributeInfo( attributeName, "someType", "This is the attribute desc.", true, false, false ) }, null, null, null ) ); } }
"This is a description", new MBeanAttributeInfo[]{ new MBeanAttributeInfo( "name", "differenceMaker", "Who makes the difference?", true, false, false ) },