javax.management.modelmbean.ModelMBeanInfo Java Examples

The following examples show how to use javax.management.modelmbean.ModelMBeanInfo. 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: AbstractJmxAssemblerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testAttributeHasCorrespondingOperations() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();

	ModelMBeanOperationInfo get = info.getOperation("getName");
	assertNotNull("get operation should not be null", get);
	assertEquals("get operation should have visibility of four",
			get.getDescriptor().getFieldValue("visibility"),
			new Integer(4));
	assertEquals("get operation should have role \"getter\"", "getter", get.getDescriptor().getFieldValue("role"));

	ModelMBeanOperationInfo set = info.getOperation("setName");
	assertNotNull("set operation should not be null", set);
	assertEquals("set operation should have visibility of four",
			set.getDescriptor().getFieldValue("visibility"),
			new Integer(4));
	assertEquals("set operation should have role \"setter\"", "setter", set.getDescriptor().getFieldValue("role"));
}
 
Example #2
Source File: MX4JModelMBean.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private Logger getModelMBeanLogger(String notificationType) throws MBeanException
{
   // Get a copy to avoid synchronization
   ModelMBeanInfo info = getModelMBeanInfo();

   // First look if there is a suitable notification descriptor, otherwise use MBean descriptor
   Descriptor descriptor = null;
   Logger modelMBeanLogger = null;
   if (notificationType != null)
   {
      descriptor = info.getDescriptor(notificationType, "notification");
      modelMBeanLogger = findLogger(descriptor);
   }

   if (modelMBeanLogger == null)
   {
      descriptor = info.getMBeanDescriptor();
      modelMBeanLogger = findLogger(descriptor);
      if (modelMBeanLogger != null) return modelMBeanLogger;
   }

   return null;
}
 
Example #3
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 #4
Source File: AbstractJmxAssemblerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testAttributeHasCorrespondingOperations() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();

	ModelMBeanOperationInfo get = info.getOperation("getName");
	assertNotNull("get operation should not be null", get);
	assertEquals("get operation should have visibility of four",
			get.getDescriptor().getFieldValue("visibility"),
			new Integer(4));
	assertEquals("get operation should have role \"getter\"", "getter", get.getDescriptor().getFieldValue("role"));

	ModelMBeanOperationInfo set = info.getOperation("setName");
	assertNotNull("set operation should not be null", set);
	assertEquals("set operation should have visibility of four",
			set.getDescriptor().getFieldValue("visibility"),
			new Integer(4));
	assertEquals("set operation should have role \"setter\"", "setter", set.getDescriptor().getFieldValue("role"));
}
 
Example #5
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 #6
Source File: AbstractJmxAssemblerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testAttributeHasCorrespondingOperations() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();

	ModelMBeanOperationInfo get = info.getOperation("getName");
	assertNotNull("get operation should not be null", get);
	assertEquals("get operation should have visibility of four",
			get.getDescriptor().getFieldValue("visibility"),
			new Integer(4));
	assertEquals("get operation should have role \"getter\"", "getter", get.getDescriptor().getFieldValue("role"));

	ModelMBeanOperationInfo set = info.getOperation("setName");
	assertNotNull("set operation should not be null", set);
	assertEquals("set operation should have visibility of four",
			set.getDescriptor().getFieldValue("visibility"),
			new Integer(4));
	assertEquals("set operation should have role \"setter\"", "setter", set.getDescriptor().getFieldValue("role"));
}
 
Example #7
Source File: AbstractMetadataAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testOperationParameterMetadata() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();
	ModelMBeanOperationInfo oper = info.getOperation("add");
	MBeanParameterInfo[] params = oper.getSignature();

	assertEquals("Invalid number of params", 2, params.length);
	assertEquals("Incorrect name for x param", "x", params[0].getName());
	assertEquals("Incorrect type for x param", int.class.getName(), params[0].getType());

	assertEquals("Incorrect name for y param", "y", params[1].getName());
	assertEquals("Incorrect type for y param", int.class.getName(), params[1].getType());
}
 
Example #8
Source File: InterfaceBasedMBeanInfoAssemblerCustomTests.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 #9
Source File: AbstractMetadataAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testOperationDescriptor() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();
	Descriptor desc = info.getOperation("myOperation").getDescriptor();

	assertEquals("Currency Time Limit should be 30", "30", desc.getFieldValue("currencyTimeLimit"));
	assertEquals("Role should be \"operation\"", "operation", desc.getFieldValue("role"));
}
 
Example #10
Source File: AbstractMetadataAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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"));
}
 
Example #11
Source File: InterfaceBasedMBeanInfoAssemblerCustomTests.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 #12
Source File: ModelMBeanAssemblerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testAttributeHasCorrespondingOperations() throws Exception {
    ModelMBeanInfo info = getMBeanInfoFromAssembler();

    ModelMBeanOperationInfo myOperation = info.getOperation("myOperation");
    assertNotNull("get operation should not be null", myOperation);
    assertEquals("Incorrect myOperation return type", "long", myOperation.getReturnType());

    ModelMBeanOperationInfo add = info.getOperation("add");
    assertNotNull("set operation should not be null", add);
    assertEquals("Incorrect add method description", "Add Two Numbers Together", add.getDescription());

}
 
Example #13
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());
}
 
Example #14
Source File: DefaultManagementMBeanAssembler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ModelMBean assemble(Object obj, ObjectName name) throws JMException {
  ModelMBeanInfo mbi = null;

  // use the default provided mbean which has been annotated with JMX
  // annotations
  LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
  mbi = assembler.getMBeanInfo(obj, null, name.toString());

  if (mbi == null) {
    return null;
  }

  RequiredModelMBean mbean = new RequiredModelMBean(mbi);

  try {
    mbean.setManagedResource(obj, "ObjectReference");
  } catch (InvalidTargetObjectTypeException e) {
    throw new JMException(e.getMessage());
  }

  // Allows the managed object to send notifications
  if (obj instanceof NotificationSenderAware) {
    ((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean));
  }

  return mbean;
}
 
Example #15
Source File: MBeanExporter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the {@code ModelMBeanInfo} for the bean with the supplied key
 * and of the supplied type.
 */
private ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException {
	ModelMBeanInfo info = this.assembler.getMBeanInfo(managedBean, beanKey);
	if (logger.isWarnEnabled() && ObjectUtils.isEmpty(info.getAttributes()) &&
			ObjectUtils.isEmpty(info.getOperations())) {
		logger.warn("Bean with key '" + beanKey +
				"' has been registered as an MBean but has no exposed attributes or operations");
	}
	return info;
}
 
Example #16
Source File: AnnotationMetadataAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #17
Source File: InterfaceBasedMBeanInfoAssemblerMappedTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithFallThrough() throws Exception {
	InterfaceBasedMBeanInfoAssembler assembler =
			getWithMapping("foobar", "org.springframework.jmx.export.assembler.ICustomJmxBean");
	assembler.setManagedInterfaces(new Class<?>[] {IAdditionalTestMethods.class});

	ModelMBeanInfo inf = assembler.getMBeanInfo(getBean(), getObjectName());
	MBeanAttributeInfo attr = inf.getAttribute("NickName");

	assertNickName(attr);
}
 
Example #18
Source File: MethodExclusionMBeanInfoAssemblerComboTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testNickNameIsExposed() throws Exception {
	ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
	MBeanAttributeInfo attr = inf.getAttribute("NickName");
	assertNotNull("Nick Name should not be null", attr);
	assertTrue("Nick Name should be writable", attr.isWritable());
	assertTrue("Nick Name should be readable", attr.isReadable());
}
 
Example #19
Source File: AbstractMetadataAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testManagedResourceDescriptor() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();
	Descriptor desc = info.getMBeanDescriptor();

	assertEquals("Logging should be set to true", "true", desc.getFieldValue("log"));
	assertEquals("Log file should be jmx.log", "jmx.log", desc.getFieldValue("logFile"));
	assertEquals("Currency Time Limit should be 15", "15", desc.getFieldValue("currencyTimeLimit"));
	assertEquals("Persist Policy should be OnUpdate", "OnUpdate", desc.getFieldValue("persistPolicy"));
	assertEquals("Persist Period should be 200", "200", desc.getFieldValue("persistPeriod"));
	assertEquals("Persist Location should be foo", "./foo", desc.getFieldValue("persistLocation"));
	assertEquals("Persist Name should be bar", "bar.jmx", desc.getFieldValue("persistName"));
}
 
Example #20
Source File: MBeanExporter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Gets the {@code ModelMBeanInfo} for the bean with the supplied key
 * and of the supplied type.
 */
private ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException {
	ModelMBeanInfo info = this.assembler.getMBeanInfo(managedBean, beanKey);
	if (logger.isInfoEnabled() && ObjectUtils.isEmpty(info.getAttributes()) &&
			ObjectUtils.isEmpty(info.getOperations())) {
		logger.info("Bean with key '" + beanKey +
				"' has been registered as an MBean but has no exposed attributes or operations");
	}
	return info;
}
 
Example #21
Source File: AbstractJmxAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotificationMetadata() throws Exception {
	ModelMBeanInfo info = (ModelMBeanInfo) getMBeanInfo();
	MBeanNotificationInfo[] notifications = info.getNotifications();
	assertEquals("Incorrect number of notifications", 1, notifications.length);
	assertEquals("Incorrect notification name", "My Notification", notifications[0].getName());

	String[] notifTypes = notifications[0].getNotifTypes();

	assertEquals("Incorrect number of notification types", 2, notifTypes.length);
	assertEquals("Notification type.foo not found", "type.foo", notifTypes[0]);
	assertEquals("Notification type.bar not found", "type.bar", notifTypes[1]);
}
 
Example #22
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 #23
Source File: MethodNameBasedMBeanInfoAssemblerTests.java    From spring-analysis-note 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 #24
Source File: MethodExclusionMBeanInfoAssemblerMappedTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testNickNameIsExposed() throws Exception {
	ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
	MBeanAttributeInfo attr = inf.getAttribute("NickName");
	assertNotNull("Nick Name should not be null", attr);
	assertTrue("Nick Name should be writable", attr.isWritable());
	assertTrue("Nick Name should be readable", attr.isReadable());
}
 
Example #25
Source File: MethodExclusionMBeanInfoAssemblerMappedTests.java    From spring-analysis-note 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 #26
Source File: MethodExclusionMBeanInfoAssemblerTests.java    From spring-analysis-note 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 #27
Source File: MethodExclusionMBeanInfoAssemblerNotMappedTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testNickNameIsExposed() throws Exception {
	ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
	MBeanAttributeInfo attr = inf.getAttribute("NickName");
	assertNotNull("Nick Name should not be null", attr);
	assertTrue("Nick Name should be writable", attr.isWritable());
	assertTrue("Nick Name should be readable", attr.isReadable());
}
 
Example #28
Source File: InterfaceBasedMBeanInfoAssemblerMappedTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testNickNameIsExposed() throws Exception {
	ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
	MBeanAttributeInfo attr = inf.getAttribute("NickName");

	assertNickName(attr);
}
 
Example #29
Source File: InterfaceBasedMBeanInfoAssemblerMappedTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testNickNameIsExposed() throws Exception {
	ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
	MBeanAttributeInfo attr = inf.getAttribute("NickName");

	assertNickName(attr);
}
 
Example #30
Source File: AnnotationMetadataAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}