Search in sources :

Example 26 with JMException

use of javax.management.JMException in project fabric8 by jboss-fuse.

the class ManagedApiFeature method initialize.

@Override
public void initialize(Server server, Bus bus) {
    final ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
    final InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
    if (iMgr != null) {
        try {
            iMgr.register(mApi);
            final ServerLifeCycleManager slcMgr = bus.getExtension(ServerLifeCycleManager.class);
            if (slcMgr != null) {
                slcMgr.registerListener(mApi);
                slcMgr.startServer(server);
            }
            // Register notification listener to propagate unregistration of endpoint MBeans
            final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
            if (mBeanServer == null) {
                return;
            }
            NotificationListener listener = new NotificationListener() {

                @Override
                public void handleNotification(Notification notification, Object handback) {
                    MBeanServerNotification mbsNotification = (MBeanServerNotification) notification;
                    ObjectName objectName = mbsNotification.getMBeanName();
                    String type = mbsNotification.getType();
                    try {
                        if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type) && mApi.isCompanion(objectName)) {
                            if (slcMgr != null) {
                                slcMgr.unRegisterListener(mApi);
                            }
                            iMgr.unregister(mApi);
                            mBeanServer.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this);
                        }
                    } catch (JMException e) {
                        LOG.log(Level.WARNING, "Unregistering ManagedApi failed.", e);
                    }
                }
            };
            mBeanServer.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, mBeanServerNotificationFilter, null);
        } catch (JMException jmex) {
            jmex.printStackTrace();
            LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
        }
    }
}
Also used : ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) MBeanServerNotification(javax.management.MBeanServerNotification) JMException(javax.management.JMException) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) Notification(javax.management.Notification) MBeanServerNotification(javax.management.MBeanServerNotification) MBeanServer(javax.management.MBeanServer) NotificationListener(javax.management.NotificationListener) ObjectName(javax.management.ObjectName)

Example 27 with JMException

use of javax.management.JMException in project netvirt by opendaylight.

the class BgpAlarmBroadcaster method close.

@Override
@PreDestroy
public void close() {
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName = objectName();
        if (mbs.isRegistered(objectName)) {
            mbs.unregisterMBean(objectName);
        }
    } catch (JMException e) {
        LOG.error("Error unregistering MXBean", e);
    }
}
Also used : JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) PreDestroy(javax.annotation.PreDestroy)

Example 28 with JMException

use of javax.management.JMException 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 29 with JMException

use of javax.management.JMException in project fuse-karaf by jboss-fuse.

the class Activator method addingService.

@Override
public MBeanServer addingService(ServiceReference<MBeanServer> serviceReference) {
    mbeanServerReference = serviceReference;
    MBeanServer server = context.getService(serviceReference);
    try {
        installFilteringRuntimeBean(context, server);
    } catch (JMException e) {
        LOG.error(e.getMessage(), e);
    }
    return server;
}
Also used : JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer)

Example 30 with JMException

use of javax.management.JMException in project spring-integration by spring-projects.

the class IntegrationMBeanExporter method registerBeanInstance.

/**
 * Copy of private method in super class. Needed so we can avoid using the bean factory to extract the bean again,
 * and risk it being a proxy (which it almost certainly is by now).
 *
 * @param bean the bean instance to register
 * @param beanKey the bean name or human readable version if auto-generated
 * @return the JMX object name of the MBean that was registered
 */
private ObjectName registerBeanInstance(Object bean, String beanKey) {
    try {
        ObjectName objectName = getObjectName(bean, beanKey);
        Object mbeanToExpose = null;
        if (isMBean(bean.getClass())) {
            mbeanToExpose = bean;
        } else {
            DynamicMBean adaptedBean = adaptMBeanIfPossible(bean);
            if (adaptedBean != null) {
                mbeanToExpose = adaptedBean;
            }
        }
        if (mbeanToExpose != null) {
            if (logger.isInfoEnabled()) {
                logger.info("Located MBean '" + beanKey + "': registering with JMX server as MBean [" + objectName + "]");
            }
            doRegister(mbeanToExpose, objectName);
        } else {
            if (logger.isInfoEnabled()) {
                logger.info("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" + objectName + "]");
            }
            ModelMBean mbean = createAndConfigureMBean(bean, beanKey);
            doRegister(mbean, objectName);
        // injectNotificationPublisherIfNecessary(bean, mbean, objectName);
        }
        return objectName;
    } catch (JMException e) {
        throw new UnableToRegisterMBeanException("Unable to register MBean [" + bean + "] with key '" + beanKey + "'", e);
    }
}
Also used : UnableToRegisterMBeanException(org.springframework.jmx.export.UnableToRegisterMBeanException) DynamicMBean(javax.management.DynamicMBean) ModelMBean(javax.management.modelmbean.ModelMBean) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Aggregations

JMException (javax.management.JMException)114 ObjectName (javax.management.ObjectName)65 MBeanServer (javax.management.MBeanServer)35 IOException (java.io.IOException)21 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)13 MalformedObjectNameException (javax.management.MalformedObjectNameException)12 MBeanInfo (javax.management.MBeanInfo)10 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)8 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 StandardMBean (javax.management.StandardMBean)7 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)6 Date (java.util.Date)5 Attribute (javax.management.Attribute)5 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)5 Element (org.w3c.dom.Element)5 PostConstruct (javax.annotation.PostConstruct)4 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)4