Search in sources :

Example 46 with ModelMBeanInfo

use of javax.management.modelmbean.ModelMBeanInfo in project kernel by exoplatform.

the class JMXManagementProvider method manage.

public Object manage(ManagedResource context) {
    if (context == null) {
        throw new IllegalArgumentException("The context cannot be null");
    }
    ExoModelMBean mbean = null;
    try {
        ExoMBeanInfoBuilder infoBuilder = new ExoMBeanInfoBuilder(context.getMetaData());
        ModelMBeanInfo info = infoBuilder.build();
        mbean = new ExoModelMBean(context, context.getResource(), info);
    } catch (IllegalArgumentException e) {
        LOG.warn("Could not create the ExoModelMBean for the class " + context.getResource() == null ? null : context.getResource().getClass(), e);
    } catch (RuntimeOperationsException e) {
        LOG.warn("Could not create the ExoModelMBean for the class " + context.getResource() == null ? null : context.getResource().getClass(), e);
    } catch (InstanceNotFoundException e) {
        LOG.warn("Could not create the ExoModelMBean for the class " + context.getResource() == null ? null : context.getResource().getClass(), e);
    } catch (MBeanException e) {
        LOG.warn("Could not create the ExoModelMBean for the class " + context.getResource() == null ? null : context.getResource().getClass(), e);
    } catch (InvalidTargetObjectTypeException e) {
        LOG.warn("Could not create the ExoModelMBean for the class " + context.getResource() == null ? null : context.getResource().getClass(), e);
    }
    // 
    if (mbean != null) {
        ObjectName on = null;
        PropertiesInfo oni = PropertiesInfo.resolve(context.getResource().getClass(), NameTemplate.class);
        if (oni != null) {
            try {
                Map<String, String> foo = oni.resolve(context.getResource());
                on = JMX.createObjectName("exo", foo);
            } catch (MalformedObjectNameException e) {
                LOG.warn("Could not create the ObjectName for the class " + context.getResource().getClass(), e);
            }
        }
        if (on != null) {
            // Merge with the container hierarchy context
            try {
                Map<String, String> props = new LinkedHashMap<String, String>();
                // Merge scoping properties
                List<MBeanScopingData> list = context.getScopingData(MBeanScopingData.class);
                // Read in revert order because wee received list of parents in upward order
                for (int i = list.size(); i > 0; i--) {
                    MBeanScopingData scopingData = list.get(i - 1);
                    props.putAll(scopingData);
                }
                // and a Hashtable<String, String> with Java 6.
                for (Object o : on.getKeyPropertyList().entrySet()) {
                    Map.Entry entry = (Map.Entry) o;
                    String key = (String) entry.getKey();
                    String value = (String) entry.getValue();
                    props.put(key, value);
                }
                // 
                on = JMX.createObjectName(on.getDomain(), props);
                // 
                attemptToRegister(on, mbean);
                // 
                return on;
            } catch (MalformedObjectNameException e) {
                LOG.warn("Could not register the MBean for the class " + context.getResource().getClass(), e);
            }
        }
    }
    // 
    return null;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) ObjectName(javax.management.ObjectName) LinkedHashMap(java.util.LinkedHashMap) MBeanException(javax.management.MBeanException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 47 with ModelMBeanInfo

use of javax.management.modelmbean.ModelMBeanInfo in project kernel by exoplatform.

the class AbstractExoMBeanTest method register.

protected Bean register(String name, Class clazz) {
    try {
        ObjectName objectName = ObjectName.getInstance(name);
        ModelMBeanInfo info = new ExoMBeanInfoBuilder(clazz).build();
        RequiredModelMBean mbean = new RequiredModelMBean(info);
        mbean.setManagedResource(clazz.newInstance(), "ObjectReference");
        server.registerMBean(mbean, objectName);
        return new Bean(objectName, (ModelMBeanInfo) server.getMBeanInfo(objectName));
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}
Also used : ExoMBeanInfoBuilder(org.exoplatform.management.jmx.impl.ExoMBeanInfoBuilder) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) ObjectName(javax.management.ObjectName) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean)

Example 48 with ModelMBeanInfo

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

the class RMEndpoint method initialise.

void initialise(RMConfiguration config, Conduit c, EndpointReferenceType r, org.apache.cxf.transport.Destination d, Message message) {
    configuration = config;
    conduit = c;
    replyTo = r;
    createServices();
    createEndpoints(d);
    setPolicies(message);
    if (manager != null && manager.getBus() != null) {
        managedEndpoint = new ManagedRMEndpoint(this);
        instrumentationManager = manager.getBus().getExtension(InstrumentationManager.class);
        if (instrumentationManager != null) {
            ModelMBeanAssembler assembler = new ModelMBeanAssembler();
            ModelMBeanInfo mbi = assembler.getModelMbeanInfo(managedEndpoint.getClass());
            MBeanServer mbs = instrumentationManager.getMBeanServer();
            if (mbs == null) {
                LOG.log(Level.WARNING, "MBeanServer not available.");
            } else {
                try {
                    RequiredModelMBean rtMBean = (RequiredModelMBean) mbs.instantiate("javax.management.modelmbean.RequiredModelMBean");
                    rtMBean.setModelMBeanInfo(mbi);
                    try {
                        rtMBean.setManagedResource(managedEndpoint, "ObjectReference");
                    } catch (InvalidTargetObjectTypeException itotex) {
                        throw new JMException(itotex.getMessage());
                    }
                    ObjectName name = managedEndpoint.getObjectName();
                    instrumentationManager.register(rtMBean, name);
                    modelMBean = rtMBean;
                } catch (JMException jmex) {
                    LOG.log(Level.WARNING, "Registering ManagedRMEndpoint failed.", jmex);
                }
            }
        }
    }
}
Also used : ModelMBeanAssembler(org.apache.cxf.management.jmx.export.runtime.ModelMBeanAssembler) JMException(javax.management.JMException) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) MBeanServer(javax.management.MBeanServer) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) ObjectName(javax.management.ObjectName)

Example 49 with ModelMBeanInfo

use of javax.management.modelmbean.ModelMBeanInfo in project voldemort by voldemort.

the class JmxUtils method createModelMBean.

/**
 * Create a model mbean from an object using the description given in the
 * Jmx annotation if present. Only operations are supported so far, no
 * attributes, constructors, or notifications
 *
 * @param o The object to create an MBean for
 * @return The ModelMBean for the given object
 */
public static ModelMBean createModelMBean(Object o) {
    try {
        ModelMBean mbean = new RequiredModelMBean();
        JmxManaged annotation = o.getClass().getAnnotation(JmxManaged.class);
        String description = annotation == null ? "" : annotation.description();
        ModelMBeanInfo info = new ModelMBeanInfoSupport(o.getClass().getName(), description, extractAttributeInfo(o), new ModelMBeanConstructorInfo[0], extractOperationInfo(o), new ModelMBeanNotificationInfo[0]);
        mbean.setModelMBeanInfo(info);
        mbean.setManagedResource(o, "ObjectReference");
        return mbean;
    } catch (MBeanException e) {
        throw new VoldemortException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new VoldemortException(e);
    } catch (InstanceNotFoundException e) {
        throw new VoldemortException(e);
    }
}
Also used : RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) ModelMBean(javax.management.modelmbean.ModelMBean) JmxManaged(voldemort.annotations.jmx.JmxManaged) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) VoldemortException(voldemort.VoldemortException) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean)

Example 50 with ModelMBeanInfo

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

the class ModelMBeanAssemblerTest method testGetMBeanInfo.

@Test
public void testGetMBeanInfo() throws Exception {
    ModelMBeanInfo info = getMBeanInfoFromAssembler();
    assertNotNull("MBeanInfo should not be null", info);
}
Also used : ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Aggregations

ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)74 Test (org.junit.jupiter.api.Test)42 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)33 Descriptor (javax.management.Descriptor)16 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)14 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)11 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)10 ObjectName (javax.management.ObjectName)9 ModelMBeanInfoSupport (javax.management.modelmbean.ModelMBeanInfoSupport)9 Test (org.junit.Test)9 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)8 MBeanException (javax.management.MBeanException)6 InstanceNotFoundException (javax.management.InstanceNotFoundException)5 MBeanServer (javax.management.MBeanServer)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)5 RuntimeOperationsException (javax.management.RuntimeOperationsException)5 FileLogger (mx4j.log.FileLogger)5 Logger (mx4j.log.Logger)5 MBeanLogger (mx4j.log.MBeanLogger)5 JMException (javax.management.JMException)4