@Override public ModelMBeanAttributeInfo createAttributeInfo() { Descriptor desc = new DescriptorSupport(new String[] {"name=" + this.displayName, "descriptorType=attribute", "currencyTimeLimit=-1", // always stale "displayName=" + this.displayName, "getMethod=getJmxValue", "setMethod=setJmxValue"}); Assert.assertTrue(this.config != null, "Config target object is null!"); desc.setField("targetObject", this.config); ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(this.displayName, // name this.type, // type this.description, // description this.readable, // isReadable this.writeable, // isWritable this.is, // isIs desc); return info; }
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); }
private void removeAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException { 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().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 ModelMBeanAttributeInfo createAttributeInfo() { Descriptor desc = new DescriptorSupport(new String[] {"name=" + this.displayName, "descriptorType=attribute", "currencyTimeLimit=-1", // always stale "displayName=" + this.displayName, "getMethod=getValue"}); Assert.assertTrue(this.stat != null, "Stat target object is null!"); desc.setField("targetObject", this.stat); ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(this.displayName, // name this.type, // type this.description, // description this.readable, // isReadable this.writeable, // isWritable this.is, // isIs desc); return info; }
@Override public ModelMBeanAttributeInfo createAttributeInfo() { Descriptor desc = new DescriptorSupport( new String[] { "name=" + this.displayName, "descriptorType=attribute", "currencyTimeLimit=-1", // always stale "displayName=" + this.displayName, "getMethod=getJmxValue", "setMethod=setJmxValue" }); Assert.assertTrue(this.config != null, "Config target object is null!"); desc.setField("targetObject", this.config); ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo( this.displayName, // name this.type, // type this.description, // description this.readable, // isReadable this.writeable, // isWritable this.is, // isIs desc); return info; }
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); }
private void removeAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException { 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().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 ModelMBeanAttributeInfo createAttributeInfo() { Descriptor desc = new DescriptorSupport( new String[] { "name=" + this.displayName, "descriptorType=attribute", "currencyTimeLimit=-1", // always stale "displayName=" + this.displayName, "getMethod=getValue" }); Assert.assertTrue(this.stat != null, "Stat target object is null!"); desc.setField("targetObject", this.stat); ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo( this.displayName, // name this.type, // type this.description, // description this.readable, // isReadable this.writeable, // isWritable this.is, // isIs desc); return info; }
@Override public MBeanInfo getMBeanInfo() { try { ModelMBeanAttributeInfo[] attributes = new ModelMBeanAttributeInfo[0]; ModelMBeanConstructorInfo[] constructors = new ModelMBeanConstructorInfo[] { new ModelMBeanConstructorInfo("-", this.getClass().getConstructor()) }; ModelMBeanOperationInfo[] operations = new ModelMBeanOperationInfo[] { new ModelMBeanOperationInfo("info", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.INFO), new ModelMBeanOperationInfo("action", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.ACTION), new ModelMBeanOperationInfo("actionInfo", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.ACTION_INFO), new ModelMBeanOperationInfo("unknown", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.UNKNOWN) }; ModelMBeanNotificationInfo[] notifications = new ModelMBeanNotificationInfo[0]; return new ModelMBeanInfoSupport(this.getClass().getName(), "-", attributes, constructors, operations, notifications); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Verify that notification which RequiredModelMBean is emitted is correct. */ private void verifyNotifivation( AttributeChangeNotification attributeChangeNotification, ModelMBeanAttributeInfo attributeInfo) { assertEquals(attributeChangeNotification.getAttributeName(), attributeInfo.getName()); assertEquals(attributeChangeNotification.getAttributeType(), attributeInfo.getType()); assertEquals(attributeChangeNotification.getNewValue(), "new value"); assertNull(attributeChangeNotification.getOldValue()); assertEquals(attributeChangeNotification.getType(), "jmx.attribute.change"); assertEquals(attributeChangeNotification.getMessage(), "AttributeChangeDetected"); assertEquals(attributeChangeNotification.getSequenceNumber(), 1); }
/** * Verify default fields of descriptor from ModelMBeanAttributeInfo: * name=nameUsedInConstructor, displayName=nameUsedInConstructor and * descriptorType=attribute. */ public Result testModelMBeanAttributeInfo() throws Exception { Method getter = sampleClass.getMethod("getH", null); Method setter = sampleClass.getMethod("setH", new Class[] { String.class }); final String name = "attribute name"; ModelMBeanAttributeInfo attributeInfo = new ModelMBeanAttributeInfo( name, "description", getter, setter); descriptor = attributeInfo.getDescriptor(); //descriptor.getFieldNames(); assertEquals(descriptor.getFieldValue("name"), name); assertEquals(descriptor.getFieldValue("displayName"), name); assertEquals(descriptor.getFieldValue("descriptorType"), "attribute"); assertEquals(descriptor.getFields().length, 3); commonCheck(); return result(); }
/** * Builds an AttributeInfo in a default way * @param name * @param displayName * @param description * @param deflt * @param operName * @param signature * @return the default modelMBeanAttributeInfo object */ public static ModelMBeanAttributeInfo buildAttributeInfo(String name, String displayName, String description, String deflt, String operName, String signature){ Descriptor attrDesc = new DescriptorSupport(); attrDesc.setField("name", name); attrDesc.setField("descriptorType", "attribute"); attrDesc.setField("default", deflt); attrDesc.setField("displayName", displayName); attrDesc.setField( "getMethod", operName); ModelMBeanAttributeInfo result=new ModelMBeanAttributeInfo(name, signature, description, true, false, false, attrDesc); return result; }
@Test public void testAttributeFromInterface() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = inf.getAttribute("Colour"); assertTrue("The name attribute should be writable", attr.isWritable()); assertTrue("The name attribute should be readable", attr.isReadable()); }
@Test public void testAttributeDescriptionOnSetter() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = inf.getAttribute(AGE_ATTRIBUTE); assertEquals("The description for the age attribute is incorrect", "The Age Attribute", attr.getDescription()); }
@Test public void testAttributeDescriptionOnGetter() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = inf.getAttribute(NAME_ATTRIBUTE); assertEquals("The description for the name attribute is incorrect", "The Name Attribute", attr.getDescription()); }
/** * Tests the situation where the attribute is only defined on the getter. */ @Test public void testReadOnlyAttribute() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = inf.getAttribute(AGE_ATTRIBUTE); assertFalse("The age attribute should not be writable", attr.isWritable()); }
@Test public void testReadWriteAttribute() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = inf.getAttribute(NAME_ATTRIBUTE); assertTrue("The name attribute should be writable", attr.isWritable()); assertTrue("The name attribute should be readable", attr.isReadable()); }
/** * Tests the situation where the property only has a getter. */ @Test public void testWithOnlySetter() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = inf.getAttribute("NickName"); assertNotNull("Attribute should not be null", attr); }
/** * Tests the situation where the property only has a setter. */ @Test public void testWithOnlyGetter() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = info.getAttribute("Superman"); assertNotNull("Attribute should not be null", attr); }
@Test public void testMetricDescription() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo metric = inf.getAttribute(QUEUE_SIZE_METRIC); ModelMBeanOperationInfo operation = inf.getOperation("getQueueSize"); assertEquals("The description for the queue size metric is incorrect", "The QueueSize metric", metric.getDescription()); assertEquals("The description for the getter operation of the queue size metric is incorrect", "The QueueSize metric", operation.getDescription()); }
@Test public void testGetAgeIsReadOnly() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE); assertTrue(attr.isReadable()); assertFalse(attr.isWritable()); }
@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")); }
@Test public void testGetAgeIsReadOnly() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE); assertTrue("Age is not readable", attr.isReadable()); assertFalse("Age is not writable", attr.isWritable()); }
@Test public void testGetAgeIsReadOnly() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE); assertTrue("Age is not readable", attr.isReadable()); assertTrue("Age is not writable", attr.isWritable()); }
@Test public void testSupermanIsReadOnly() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = info.getAttribute("Superman"); assertTrue(attr.isReadable()); assertFalse(attr.isWritable()); }