ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attrName, description, getter, setter); Descriptor desc = info.getDescriptor(); if (getter != null) { desc.setField(FIELD_GET_METHOD, getter.getName());
getter, setter); Descriptor descriptor = info.getDescriptor(); if(getter != null) descriptor.setField("getMethod", getter.getName());
ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attrName, description, getter, setter); Descriptor desc = info.getDescriptor(); if (getter != null) { desc.setField(FIELD_GET_METHOD, getter.getName());
private void removeAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException { if (listener == null) throw new RuntimeOperationsException(new IllegalArgumentException( "Listener cannot be null.")); AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter(); if (attributeName != null) { filter.enableAttribute(attributeName); } else { MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes(); for (int i = 0; i < ai.length; i++) { Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor(); filter.enableAttribute((String) d.getFieldValue("name")); } } getAttributeChangeBroadcaster().removeNotificationListener(listener, filter, handback); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Listener " + listener + " for attribute " + attributeName + " removed successfully, handback is " + handback); }
@Override public void addAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, IllegalArgumentException { if (listener == null) throw new RuntimeOperationsException(new IllegalArgumentException( "Listener cannot be null.")); AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter(); if (attributeName != null) { filter.enableAttribute(attributeName); } else { MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes(); for (int i = 0; i < ai.length; i++) { Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor(); filter.enableAttribute((String) d.getFieldValue("name")); } } getAttributeChangeBroadcaster().addNotificationListener(listener, filter, handback); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Listener " + listener + " for attribute " + attributeName + " added successfully, handback is " + handback); }
@Test public void testAttributeDescriptor() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); Descriptor desc = info.getAttribute(NAME_ATTRIBUTE).getDescriptor(); assertEquals("Default value should be foo", "foo", desc.getFieldValue("default")); assertEquals("Currency Time Limit should be 20", "20", desc.getFieldValue("currencyTimeLimit")); assertEquals("Persist Policy should be OnUpdate", "OnUpdate", desc.getFieldValue("persistPolicy")); assertEquals("Persist Period should be 300", "300", desc.getFieldValue("persistPeriod")); }
Descriptor attributeDescriptor = attrInfo.getDescriptor(); if (attributeDescriptor == null) throw new AttributeNotFoundException(
@Test public void testAttributeInfoHasDescriptors() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = info.getAttribute(NAME_ATTRIBUTE); Descriptor desc = attr.getDescriptor(); assertNotNull("getMethod field should not be null", desc.getFieldValue("getMethod")); assertNotNull("setMethod field should not be null", desc.getFieldValue("setMethod")); assertEquals("getMethod field has incorrect value", "getName", desc.getFieldValue("getMethod")); assertEquals("setMethod field has incorrect value", "setName", desc.getFieldValue("setMethod")); }
Descriptor attributeDescriptor = attrInfo.getDescriptor(); if (attributeDescriptor == null) throw new AttributeNotFoundException(
@Test public void testMetricDescriptorDefaults() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); Descriptor desc = info.getAttribute(CACHE_ENTRIES_METRIC).getDescriptor(); assertNull("Currency Time Limit should not be populated", desc.getFieldValue("currencyTimeLimit")); assertNull("Persist Policy should not be populated", desc.getFieldValue("persistPolicy")); assertNull("Persist Period should not be populated", desc.getFieldValue("persistPeriod")); assertNull("Unit should not be populated", desc.getFieldValue("units")); assertEquals("Display Name should be populated by default via JMX", CACHE_ENTRIES_METRIC,desc.getFieldValue("displayName")); assertEquals("Metric Type should be GAUGE", "GAUGE",desc.getFieldValue("metricType")); assertNull("Metric Category should not be populated", desc.getFieldValue("metricCategory")); }
@Test public void testMetricDescriptor() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); Descriptor desc = info.getAttribute(QUEUE_SIZE_METRIC).getDescriptor(); assertEquals("Currency Time Limit should be 20", "20", desc.getFieldValue("currencyTimeLimit")); assertEquals("Persist Policy should be OnUpdate", "OnUpdate", desc.getFieldValue("persistPolicy")); assertEquals("Persist Period should be 300", "300", desc.getFieldValue("persistPeriod")); assertEquals("Unit should be messages", "messages",desc.getFieldValue("units")); assertEquals("Display Name should be Queue Size", "Queue Size",desc.getFieldValue("displayName")); assertEquals("Metric Type should be COUNTER", "COUNTER",desc.getFieldValue("metricType")); assertEquals("Metric Category should be utilization", "utilization",desc.getFieldValue("metricCategory")); }
@Test public void testRegistrationOnInterface() throws Exception { Object bean = getContext().getBean("testInterfaceBean"); ModelMBeanInfo inf = getAssembler().getMBeanInfo(bean, "bean:name=interfaceTestBean"); assertNotNull(inf); assertEquals("My Managed Bean", inf.getDescription()); ModelMBeanOperationInfo op = inf.getOperation("foo"); assertNotNull("foo operation not exposed", op); assertEquals("invoke foo", op.getDescription()); assertNull("doNotExpose operation should not be exposed", inf.getOperation("doNotExpose")); ModelMBeanAttributeInfo attr = inf.getAttribute("Bar"); assertNotNull("bar attribute not exposed", attr); assertEquals("Bar description", attr.getDescription()); ModelMBeanAttributeInfo attr2 = inf.getAttribute("CacheEntries"); assertNotNull("cacheEntries attribute not exposed", attr2); assertEquals("Metric Type should be COUNTER", "COUNTER", attr2.getDescriptor().getFieldValue("metricType")); }
/** * Generates a setter signature string for a ModelMBean attribute by checking the * descriptor for setMethod. */ public static String setterSignature(ModelMBeanAttributeInfo info) { if (null == info) { throw new IllegalArgumentException("ModelMBeanAttributeInfo cannot be null"); } String methodName = (String) info.getDescriptor().getFieldValue("setMethod"); if (null == methodName) { throw new IllegalArgumentException("setMethod not defined in ModelMBeanAttributeInfo descriptor"); } return methodSignature(Void.TYPE.getName(), methodName, new String[]{info.getType()}); }
/** * Generates a getter signature string for a ModelMBean attribute by checking the * descriptor for getMethod. */ public static String getterSignature(ModelMBeanAttributeInfo info) { if (null == info) { throw new IllegalArgumentException("ModelMBeanAttributeInfo cannot be null"); } String methodName = (String) info.getDescriptor().getFieldValue("getMethod"); if (null == methodName) { throw new IllegalArgumentException("getMethod not defined in ModelMBeanAttributeInfo descriptor"); } return methodSignature(info.getType(), methodName, null); }
/** * Generates a getter signature string for a ModelMBean attribute by checking the * descriptor for getMethod. * * @param info the attribute info * @return the signature */ public static String getterSignature(ModelMBeanAttributeInfo info) { if (null == info) { throw new IllegalArgumentException("ModelMBeanAttributeInfo cannot be null"); } String methodName = (String) info.getDescriptor().getFieldValue("getMethod"); if (null == methodName) { throw new IllegalArgumentException("getMethod not defined in ModelMBeanAttributeInfo descriptor"); } return methodSignature(info.getType(), methodName, null); }
protected void initAttributeContexts(MBeanAttributeInfo[] attributes) { super.initAttributeContexts(attributes); for (int i = 0; i < attributes.length; ++i) { ModelMBeanAttributeInfo info = (ModelMBeanAttributeInfo) attributes[i]; String name = info.getName(); InvocationContext ctx = (InvocationContext) attributeContextMap.get(name); ctx.setDescriptor(info.getDescriptor()); ctx.setReadable(info.isReadable()); ctx.setWritable(info.isWritable()); } }
protected void initAttributeContexts(MBeanAttributeInfo[] attributes) { super.initAttributeContexts(attributes); for (int i = 0; i < attributes.length; ++i) { ModelMBeanAttributeInfo info = (ModelMBeanAttributeInfo) attributes[i]; String name = info.getName(); InvocationContext ctx = (InvocationContext) attributeContextMap.get(name); ctx.setDescriptor(info.getDescriptor()); ctx.setReadable(info.isReadable()); ctx.setWritable(info.isWritable()); } }
protected JmxAttribute buildProperty(Class<?> managedClass, BeanProperty property) { MBeanProperty jmxAttribute = new MBeanProperty( property, getPropertyExportName(managedClass, property), getPropertyDescription(managedClass, property), getPropertyAccess(managedClass, property)); Descriptor desc = jmxAttribute.getMetadata().getDescriptor(); populatePropertyDescriptor(managedClass, property, desc); jmxAttribute.getMetadata().setDescriptor(desc); return jmxAttribute; }
protected JmxAttribute buildAttribute(Class<?> managedClass, Field field) { MBeanAttribute jmxAttribute = new MBeanAttribute( field, getAttributeExportName(managedClass, field), getAttributeDescription(managedClass, field), getAttributeAccess(managedClass, field)); Descriptor desc = jmxAttribute.getMetadata().getDescriptor(); populateAttributeDescriptor(managedClass, field, desc); jmxAttribute.getMetadata().setDescriptor(desc); return jmxAttribute; }
public void addAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, IllegalArgumentException { if (listener == null) throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString())); AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter(); if (attributeName != null) { filter.enableAttribute(attributeName); } else { MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes(); for (int i = 0; i < ai.length; i++) { Descriptor d = ((ModelMBeanAttributeInfo)ai[i]).getDescriptor(); filter.enableAttribute((String)d.getFieldValue("name")); } } getAttributeChangeBroadcaster().addNotificationListener(listener, filter, handback); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Listener " + listener + " for attribute " + attributeName + " added successfully, handback is " + handback); }