Search in sources :

Example 56 with JMException

use of javax.management.JMException in project cxf by apache.

the class CounterRepository method createCounter.

public Counter createCounter(ObjectName on) {
    Counter counter = new ResponseTimeCounter(on);
    InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
    if (null != im) {
        try {
            im.register(counter);
        } catch (JMException e) {
            LOG.log(Level.WARNING, "INSTRUMENTATION_REGISTER_FAULT_MSG", new Object[] { on, e });
        }
    }
    return counter;
}
Also used : JMException(javax.management.JMException) InstrumentationManager(org.apache.cxf.management.InstrumentationManager)

Example 57 with JMException

use of javax.management.JMException in project cxf by apache.

the class InstrumentationManagerImpl method init.

@PostConstruct
public void init() {
    if (bus != null && bus.getExtension(MBeanServer.class) != null) {
        enabled = true;
        mbs = bus.getExtension(MBeanServer.class);
    }
    if (isEnabled()) {
        if (mbs == null) {
            // return platform mbean server if the option is specified.
            if (usePlatformMBeanServer) {
                mbs = ManagementFactory.getPlatformMBeanServer();
            } else {
                String mbeanServerID = mbeanServerIDMap.get(mbeanServerName);
                List<MBeanServer> servers = null;
                if (mbeanServerID != null) {
                    servers = CastUtils.cast(MBeanServerFactory.findMBeanServer(mbeanServerID));
                }
                if (servers == null || servers.isEmpty()) {
                    mbs = MBeanServerFactory.createMBeanServer(mbeanServerName);
                    try {
                        mbeanServerID = (String) mbs.getAttribute(getDelegateName(), "MBeanServerId");
                        mbeanServerIDMap.put(mbeanServerName, mbeanServerID);
                    } catch (JMException e) {
                    // ignore
                    }
                } else {
                    mbs = servers.get(0);
                }
            }
        }
        if (!connectFailed && null != bus) {
            try {
                // Register Bus here since we can guarantee that Instrumentation
                // infrastructure has been initialized.
                ManagedBus mbus = new ManagedBus(bus);
                register(mbus);
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.info("registered " + mbus.getObjectName());
                }
            } catch (JMException jmex) {
                LOG.log(Level.SEVERE, "REGISTER_FAILURE_MSG", new Object[] { bus, jmex });
            }
        }
    }
    if (null != bus) {
        bus.setExtension(this, InstrumentationManager.class);
        BusLifeCycleManager blcm = bus.getExtension(BusLifeCycleManager.class);
        if (null != blcm) {
            blcm.registerLifeCycleListener(this);
        }
    }
}
Also used : ManagedBus(org.apache.cxf.bus.ManagedBus) JMException(javax.management.JMException) BusLifeCycleManager(org.apache.cxf.buslifecycle.BusLifeCycleManager) MBeanServer(javax.management.MBeanServer) PostConstruct(javax.annotation.PostConstruct)

Example 58 with JMException

use of javax.management.JMException in project vibur-dbcp by vibur.

the class ViburMonitoring method unregisterMBean.

static void unregisterMBean(ViburDBCPDataSource dataSource) {
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName = new ObjectName(dataSource.getJmxName());
        if (mbs.isRegistered(objectName)) {
            mbs.unregisterMBean(objectName);
        } else {
            logger.debug(dataSource.getJmxName() + " is not registered.");
        }
    } catch (JMException e) {
        logger.warn("Unable to unregister mBean {}", dataSource.getJmxName(), e);
    }
}
Also used : JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 59 with JMException

use of javax.management.JMException in project vibur-dbcp by vibur.

the class ViburMonitoring method registerMBean.

static void registerMBean(ViburDBCPDataSource dataSource) {
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName = new ObjectName(dataSource.getJmxName());
        if (!mbs.isRegistered(objectName)) {
            mbs.registerMBean(new ViburMonitoring(dataSource), objectName);
        } else {
            logger.warn(dataSource.getJmxName() + " is already registered.");
        }
    } catch (JMException e) {
        logger.warn("Unable to register mBean {}", dataSource.getJmxName(), e);
    }
}
Also used : JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 60 with JMException

use of javax.management.JMException in project alfresco-repository by Alfresco.

the class DynamicMBeanExporter method registerMBean.

/*
     * (non-Javadoc)
     * @see org.alfresco.enterprise.repo.management.DynamicMBeanExportOperations#registerMBean(java.lang.Object,
     * javax.management.ObjectName)
     */
@SuppressWarnings("unchecked")
public ObjectName registerMBean(Object managedResource, ObjectName objectName) {
    Object mbean;
    if (isMBean(managedResource.getClass())) {
        mbean = managedResource;
    } else {
        mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
    }
    ObjectName actualObjectName = objectName;
    try {
        doRegister(mbean, actualObjectName);
    } catch (JMException e) {
        throw new RuntimeException(e);
    }
    return actualObjectName;
}
Also used : JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Aggregations

JMException (javax.management.JMException)116 ObjectName (javax.management.ObjectName)66 MBeanServer (javax.management.MBeanServer)33 IOException (java.io.IOException)22 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)13 MBeanInfo (javax.management.MBeanInfo)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)9 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 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)4