Search in sources :

Example 81 with JMException

use of javax.management.JMException in project opennms by OpenNMS.

the class DefaultJmxCollector method collect.

private void collect(MBeanServerConnection concreteConnection, JmxCollection jmxCollection, JmxSampleProcessor sampleProcessor) {
    if (jmxCollection == null || jmxCollection.getMbeanCount() < 1) {
        logger.info("No MBeans to collect.");
        return;
    }
    try {
        for (Mbean eachMbean : jmxCollection.getMbeans()) {
            logger.debug("Collecting MBean (objectname={}, wildcard={})", eachMbean.getObjectname(), isWildcard(eachMbean.getObjectname()));
            final Collection<ObjectName> objectNames = getObjectNames(concreteConnection, eachMbean.getObjectname());
            for (ObjectName eachObjectName : objectNames) {
                logger.debug("Collecting ObjectName {}", eachObjectName);
                boolean collect = canBeCollected(concreteConnection, eachObjectName, eachMbean.getKeyfield(), eachMbean.getExclude());
                if (collect) {
                    List<String> attributeNames = extractAttributeNames(eachMbean);
                    List<Attribute> attributes = getAttributes(concreteConnection, eachObjectName, attributeNames);
                    for (Attribute eachAttribute : attributes) {
                        if (eachAttribute.getValue() instanceof CompositeData) {
                            CompositeData compositeData = (CompositeData) eachAttribute.getValue();
                            for (CompMember eachCompositeMember : getCompositeMembers(eachMbean, eachAttribute.getName())) {
                                JmxCompositeSample sample = new JmxCompositeSample(eachMbean, eachAttribute, compositeData, eachCompositeMember);
                                logger.debug("Collected sample {}", sample);
                                sampleProcessor.process(sample, eachObjectName);
                            }
                        } else {
                            JmxAttributeSample sample = new JmxAttributeSample(eachMbean, eachAttribute);
                            logger.debug("Collected sample {}", sample);
                            sampleProcessor.process(sample, eachObjectName);
                        }
                    }
                } else {
                    logger.debug("Skip ObjectName {}", eachObjectName);
                }
            }
        }
    } catch (JMException e) {
        logger.error("Could not collect data", e);
    } catch (IOException e) {
        logger.error("Could not communicate with MBeanServer", e);
    }
}
Also used : Attribute(javax.management.Attribute) CompositeData(javax.management.openmbean.CompositeData) JmxCompositeSample(org.opennms.netmgt.jmx.samples.JmxCompositeSample) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) CompMember(org.opennms.netmgt.config.collectd.jmx.CompMember) Mbean(org.opennms.netmgt.config.collectd.jmx.Mbean) JMException(javax.management.JMException) JmxAttributeSample(org.opennms.netmgt.jmx.samples.JmxAttributeSample)

Example 82 with JMException

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

the class Supervisor method register.

/**
 * Registers the {@code Supervisor} instance, if not already done.
 * If the supervisor has already been registered but has not yet been
 * {@linkplain #unregister() unregistered}, then this method does nothing.
 *
 * <p>If the registration fails, then this method logs a message at the warning level
 * and the MBean will not be registered. This method does not propagate the exception
 * because the MBean is not a mandatory part of SIS library.</p>
 */
@Configuration
public static synchronized void register() {
    if (name == null) {
        // In case of failure.
        name = ObjectName.WILDCARD;
        final LogRecord record;
        try {
            final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            final ObjectName n = new ObjectName(NAME);
            server.registerMBean(new Supervisor(), n);
            // Store only on success.
            name = n;
            return;
        } catch (InstanceAlreadyExistsException e) {
            record = Messages.getResources(null).getLogRecord(Level.CONFIG, Messages.Keys.AlreadyRegistered_2, "MBean", NAME);
        } catch (JMException e) {
            record = new LogRecord(Level.WARNING, e.toString());
            record.setThrown(e);
        } catch (SecurityException e) {
            record = new LogRecord(Level.CONFIG, e.toString());
        }
        record.setLoggerName(Loggers.SYSTEM);
        Logging.log(Supervisor.class, "register", record);
    }
}
Also used : LogRecord(java.util.logging.LogRecord) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Configuration(org.apache.sis.util.Configuration)

Example 83 with JMException

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

the class JMXManagementService method startManagement.

public synchronized void startManagement() {
    // Has this service been shut down?
    if (registeredMbeans == null)
        return;
    checkJMXControl();
    // Already active?
    if (isManagementActive())
        return;
    findServer();
    // If we can't find the server then we can't register.
    if (mbeanServer == null)
        return;
    for (ObjectName mbeanName : registeredMbeans.keySet()) {
        // to be re-registered with JMX
        if (mbeanName.equals(myManagementBean) && mbeanServer.isRegistered(myManagementBean))
            continue;
        try {
            jmxRegister(registeredMbeans.get(mbeanName), mbeanName);
        } catch (JMException e) {
        // TODO - what to do here?
        }
    }
}
Also used : JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 84 with JMException

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

the class BgpAlarmBroadcaster method init.

@PostConstruct
public void init() {
    // Set up the Infra for Posting BGP Alarms as JMX notifications.
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(this, objectName());
    } catch (JMException e) {
        LOG.error("Adding a NotificationBroadcaster failed.", e);
    }
    LOG.info("{} start", getClass().getSimpleName());
}
Also used : JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) PostConstruct(javax.annotation.PostConstruct)

Example 85 with JMException

use of javax.management.JMException in project narayana by jbosstm.

the class StoreManagerProxy method registerBean.

/**
 * MBean registration helper method
 * @param name MBean object name
 * @param bean MBean implementation
 * @param register whether to register or unregister the MBean
 * @return true if the bean was successfully registered or unregistered
 */
public static boolean registerBean(ObjectName name, Object bean, boolean register) {
    try {
        MBeanServer mbs = JMXServer.getAgent().getServer();
        boolean isRegistered = mbs.isRegistered(name);
        System.out.println((register ? "" : "un") + "registering bean " + name);
        if (register && isRegistered) {
            System.out.println(name + " is already registered");
            return true;
        } else if (!register && !isRegistered) {
            System.out.println(name + " is not registered");
            return true;
        } else if (register) {
            mbs.registerMBean(bean, name);
        } else {
            mbs.unregisterMBean(name);
        }
        return true;
    } catch (JMException e) {
        System.out.println("MBean registration error: " + e.getMessage());
        return false;
    }
}
Also used : JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer)

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