Search in sources :

Example 21 with StandardMBean

use of javax.management.StandardMBean in project derby by apache.

the class JMXManagementService method registerMBean.

/**
 * Registers an MBean with the MBean server as a StandardMBean.
 * Use of the StandardMBean allows the implementation details
 * of Derby's mbeans to be hidden from JMX, thus only exposing
 * the MBean's interface in org.apache.derby.mbeans.
 *
 * @param bean The MBean to wrap with a StandardMBean and register
 * @param beanInterface The management interface for the MBean.
 * @param keyProperties The String representation of the MBean's key properties,
 * they will be added into the ObjectName with Derby's domain. Key
 * type should be first with a short name for the bean, typically the
 * class name without the package.
 */
public synchronized <T> Object registerMBean(final T bean, final Class<T> beanInterface, final String keyProperties) throws StandardException {
    try {
        final ObjectName beanName = new ObjectName(DERBY_JMX_DOMAIN + ":" + keyProperties + ",system=" + systemIdentifier);
        final StandardMBean standardMBean = new StandardMBean(bean, beanInterface) {

            /**
             * Hide the implementation name from JMX clients
             * by providing the interface name as the class
             * name for the MBean. Allows the permissions
             * in a policy file to be granted to the public
             * MBean interfaces.
             */
            protected String getClassName(MBeanInfo info) {
                return beanInterface.getName();
            }
        };
        // new StandardMBean(bean, beanInterface);
        registeredMbeans.put(beanName, standardMBean);
        if (mbeanServer != null)
            jmxRegister(standardMBean, beanName);
        return beanName;
    } catch (JMException jme) {
        throw StandardException.plainWrapException(jme);
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) StandardMBean(javax.management.StandardMBean) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 22 with StandardMBean

use of javax.management.StandardMBean in project derby by apache.

the class JMXManagementService method boot.

/**
 * Start the management service if derby.system.jmx is true.
 * <P>
 * Starting the service means:
 * <UL>
 * <LI> getting the platform MBeanServer which may require starting it
 * <LI> registering a Version mbean representing the system
 * </UL>
 */
public synchronized void boot(boolean create, Properties properties) throws StandardException {
    registeredMbeans = new HashMap<ObjectName, StandardMBean>();
    systemIdentifier = getMonitor().getUUIDFactory().createUUID().toString();
    findServer();
    myManagementBean = (ObjectName) registerMBean(this, ManagementMBean.class, "type=Management");
    myManagementServer = mbeanServer;
    registerMBean(new Version(getMonitor().getEngineVersion(), SystemPermission.ENGINE), VersionMBean.class, "type=Version,jar=derby.jar");
}
Also used : StandardMBean(javax.management.StandardMBean) Version(org.apache.derby.mbeans.Version) ObjectName(javax.management.ObjectName)

Example 23 with StandardMBean

use of javax.management.StandardMBean in project jvm-breakglass by matlux.

the class MBeanRegistration method registerMBean.

private static void registerMBean(MBeanServer mbs, ObjectName objectName, NreplMBean nreplServer) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    StandardMBean mbean = new StandardMBean(nreplServer, NreplMBean.class, false);
    mbs.registerMBean(mbean, objectName);
}
Also used : StandardMBean(javax.management.StandardMBean)

Example 24 with StandardMBean

use of javax.management.StandardMBean in project tomee by apache.

the class Alternative method postConstruct.

@PostConstruct
public <T> void postConstruct() throws MBeanRegistrationException {
    final String name = properties.remove("name").toString();
    final String iface = properties.remove("interface").toString();
    final String prefix = properties.remove("prefix").toString();
    requireNotNull(name);
    requireNotNull(iface);
    try {
        final Class<T> ifaceCls = (Class<T>) Class.forName(iface, true, Thread.currentThread().getContextClassLoader());
        final StandardMBean mBean = new StandardMBean((T) this, ifaceCls);
        for (String attributeName : properties.stringPropertyNames()) {
            final Object value = properties.remove(attributeName);
            if (prefix != null) {
                if (!attributeName.startsWith(prefix + ".")) {
                    continue;
                } else {
                    attributeName = attributeName.substring(prefix.length() + 1);
                }
            }
            final Class<?> targetType = findAttributeType(mBean.getMBeanInfo(), attributeName);
            final Object targetValue = Converter.convert(value, targetType, null);
            final Attribute attribute = new Attribute(attributeName, targetValue);
            mBean.setAttribute(attribute);
        }
        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        final ObjectName objectName = new ObjectName(name);
        mbs.registerMBean(this, objectName);
    } catch (final Exception e) {
        LOGGER.severe("Unable to register mbean " + e.getMessage());
        throw new MBeanRegistrationException(e);
    }
}
Also used : StandardMBean(javax.management.StandardMBean) Attribute(javax.management.Attribute) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanRegistrationException(org.superbiz.resource.jmx.factory.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(org.superbiz.resource.jmx.factory.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) PostConstruct(javax.annotation.PostConstruct)

Example 25 with StandardMBean

use of javax.management.StandardMBean in project tomee by apache.

the class JMXBeanCreator method create.

public <T> Object create() throws MBeanRegistrationException {
    final String code = (String) properties.remove("code");
    final String name = (String) properties.remove("name");
    final String iface = (String) properties.remove("interface");
    final String prefix = (String) properties.remove("prefix");
    requireNotNull(code);
    requireNotNull(name);
    requireNotNull(iface);
    try {
        final Class<? extends T> cls = (Class<? extends T>) Class.forName(code, true, Thread.currentThread().getContextClassLoader());
        final Class<T> ifaceCls = (Class<T>) Class.forName(iface, true, Thread.currentThread().getContextClassLoader());
        final T instance = (T) cls.newInstance();
        final StandardMBean mBean = new StandardMBean(instance, ifaceCls);
        for (String attributeName : properties.stringPropertyNames()) {
            final Object value = properties.remove(attributeName);
            if (prefix != null) {
                if (!attributeName.startsWith(prefix + ".")) {
                    continue;
                } else {
                    attributeName = attributeName.substring(prefix.length() + 1);
                }
            }
            final Class<?> targetType = findAttributeType(mBean.getMBeanInfo(), attributeName);
            final Object targetValue = Converter.convert(value, targetType, null);
            final Attribute attribute = new Attribute(attributeName, targetValue);
            mBean.setAttribute(attribute);
        }
        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        final ObjectName objectName = new ObjectName(name);
        mbs.registerMBean(instance, objectName);
        return instance;
    } catch (final Exception e) {
        e.printStackTrace();
        LOGGER.severe("Unable to register mbean " + e.getMessage());
        throw new MBeanRegistrationException(e);
    }
}
Also used : StandardMBean(javax.management.StandardMBean) Attribute(javax.management.Attribute) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Aggregations

StandardMBean (javax.management.StandardMBean)70 ObjectName (javax.management.ObjectName)32 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)21 MBeanServer (javax.management.MBeanServer)17 MalformedObjectNameException (javax.management.MalformedObjectNameException)16 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)12 MBeanRegistrationException (javax.management.MBeanRegistrationException)9 Test (org.junit.Test)9 JMException (javax.management.JMException)7 IOException (java.io.IOException)6 Logger (org.apache.aries.jmx.Logger)6 InstanceNotFoundException (javax.management.InstanceNotFoundException)5 Activate (org.apache.felix.scr.annotations.Activate)5 IgniteStandardMXBean (org.apache.ignite.internal.mxbean.IgniteStandardMXBean)5 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 MBeanInfo (javax.management.MBeanInfo)4 OpenDataException (javax.management.openmbean.OpenDataException)4 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)3 CompositeType (javax.management.openmbean.CompositeType)3 OpenType (javax.management.openmbean.OpenType)3