javax.management.modelmbean.ModelMBeanAttributeInfo Java Examples

The following examples show how to use javax.management.modelmbean.ModelMBeanAttributeInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestModelMBean.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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);
    }
}
 
Example #2
Source File: AnnotationMetadataAssemblerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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"));
}
 
Example #3
Source File: StatisticAttributeInfo.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: ConfigAttributeInfo.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: MX4JModelMBean.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #6
Source File: MX4JModelMBean.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #7
Source File: MX4JModelMBean.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #8
Source File: JmxUtils.java    From iaf with Apache License 2.0 6 votes vote down vote up
/**
 * Builds an AttributeInfo in a default way
 * @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;
}
 
Example #9
Source File: AnnotationMetadataAssemblerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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"));
}
 
Example #10
Source File: StatisticAttributeInfo.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #11
Source File: AbstractMetadataAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #12
Source File: AbstractMetadataAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #13
Source File: MethodExclusionMBeanInfoAssemblerComboTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #14
Source File: MethodNameBasedMBeanInfoAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAgeIsReadOnly() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();
	ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE);

	assertTrue(attr.isReadable());
	assertFalse(attr.isWritable());
}
 
Example #15
Source File: MethodExclusionMBeanInfoAssemblerMappedTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #16
Source File: MethodExclusionMBeanInfoAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSupermanIsReadOnly() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();
	ModelMBeanAttributeInfo attr = info.getAttribute("Superman");

	assertTrue(attr.isReadable());
	assertFalse(attr.isWritable());
}
 
Example #17
Source File: MethodExclusionMBeanInfoAssemblerNotMappedTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #18
Source File: InterfaceBasedMBeanInfoAssemblerMappedTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #19
Source File: ModelMBeanInfoSupporter.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void addModelMBeanAttribute(String fname,
                                   String ftype,
                                   boolean read,
                                   boolean write,
                                   boolean is,
                                   String description,
                                   Descriptor desc) {
    attributes.put(fname, new ModelMBeanAttributeInfo(fname,
                                                       ftype,
                                                       description,
                                                       read,
                                                       write,
                                                       is,
                                                       desc));
}
 
Example #20
Source File: AbstractMetadataAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #21
Source File: AbstractMetadataAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #22
Source File: AbstractMetadataAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #23
Source File: AbstractMetadataAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #24
Source File: MethodNameBasedMBeanInfoAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testGetAgeIsReadOnly() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();
	ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE);

	assertTrue(attr.isReadable());
	assertFalse(attr.isWritable());
}
 
Example #25
Source File: MethodExclusionMBeanInfoAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testSupermanIsReadOnly() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();
	ModelMBeanAttributeInfo attr = info.getAttribute("Superman");

	assertTrue(attr.isReadable());
	assertFalse(attr.isWritable());
}
 
Example #26
Source File: MethodExclusionMBeanInfoAssemblerNotMappedTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #27
Source File: InterfaceBasedMBeanInfoAssemblerMappedTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #28
Source File: MethodExclusionMBeanInfoAssemblerComboTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #29
Source File: MethodNameBasedMBeanInfoAssemblerMappedTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #30
Source File: MethodExclusionMBeanInfoAssemblerMappedTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}