Search in sources :

Example 21 with ModelMBeanInfo

use of javax.management.modelmbean.ModelMBeanInfo in project spring-framework by spring-projects.

the class InterfaceBasedMBeanInfoAssemblerCustomTests method testGetAgeIsReadOnly.

@Test
public void testGetAgeIsReadOnly() throws Exception {
    ModelMBeanInfo info = getMBeanInfoFromAssembler();
    ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE);
    assertTrue(attr.isReadable());
    assertFalse(attr.isWritable());
}
Also used : ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Example 22 with ModelMBeanInfo

use of javax.management.modelmbean.ModelMBeanInfo in project spring-framework by spring-projects.

the class InterfaceBasedMBeanInfoAssemblerMappedTests method testGetAgeIsReadOnly.

@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());
}
Also used : ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Example 23 with ModelMBeanInfo

use of javax.management.modelmbean.ModelMBeanInfo in project spring-framework by spring-projects.

the class MethodExclusionMBeanInfoAssemblerComboTests method testGetAgeIsReadOnly.

@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());
}
Also used : ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Example 24 with ModelMBeanInfo

use of javax.management.modelmbean.ModelMBeanInfo in project spring-framework by spring-projects.

the class MethodExclusionMBeanInfoAssemblerComboTests method testNickNameIsExposed.

@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());
}
Also used : ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) Test(org.junit.Test)

Example 25 with ModelMBeanInfo

use of javax.management.modelmbean.ModelMBeanInfo in project camel by apache.

the class SpringManagementMBeanAssembler method assemble.

public ModelMBean assemble(MBeanServer mBeanServer, Object obj, ObjectName name) throws JMException {
    ModelMBeanInfo mbi = null;
    // prefer to use the managed instance if it has been annotated with Spring JMX annotations
    if (obj instanceof ManagedInstance) {
        Object custom = ((ManagedInstance) obj).getInstance();
        if (custom != null && ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(), ManagedResource.class)) {
            LOG.trace("Assembling MBeanInfo for: {} from custom @ManagedResource object: {}", name, custom);
            // get the mbean info from the custom managed object
            mbi = springAssembler.getMBeanInfo(custom, name.toString());
            // and let the custom object be registered in JMX
            obj = custom;
        }
    }
    if (mbi == null) {
        if (ObjectHelper.hasAnnotation(obj.getClass().getAnnotations(), ManagedResource.class)) {
            // the object has a Spring ManagedResource annotations so assemble the MBeanInfo
            LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
            mbi = springAssembler.getMBeanInfo(obj, name.toString());
        } else {
            // fallback and let the default mbean assembler handle this instead
            return super.assemble(mBeanServer, obj, name);
        }
    }
    LOG.trace("Assembled MBeanInfo {}", mbi);
    RequiredModelMBean mbean = (RequiredModelMBean) mBeanServer.instantiate(RequiredModelMBean.class.getName());
    mbean.setModelMBeanInfo(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;
}
Also used : JMException(javax.management.JMException) NotificationSenderAware(org.apache.camel.api.management.NotificationSenderAware) ManagedInstance(org.apache.camel.api.management.ManagedInstance) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) NotificationSenderAdapter(org.apache.camel.management.NotificationSenderAdapter) ManagedResource(org.springframework.jmx.export.annotation.ManagedResource) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean)

Aggregations

ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)63 Test (org.junit.Test)44 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)33 Descriptor (javax.management.Descriptor)16 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)12 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)9 ModelMBeanInfoSupport (javax.management.modelmbean.ModelMBeanInfoSupport)9 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)8 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)6 MBeanException (javax.management.MBeanException)5 ObjectName (javax.management.ObjectName)5 FileLogger (mx4j.log.FileLogger)5 Logger (mx4j.log.Logger)5 MBeanLogger (mx4j.log.MBeanLogger)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)4 MBeanServer (javax.management.MBeanServer)4 RuntimeOperationsException (javax.management.RuntimeOperationsException)4 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)4 ModelMBean (javax.management.modelmbean.ModelMBean)4 Attribute (javax.management.Attribute)3