Search in sources :

Example 16 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.

the class ManagementFactoryHelper method addMBean.

/**
     * Registers a given MBean if not registered in the MBeanServer;
     * otherwise, just return.
     */
private static void addMBean(MBeanServer mbs, Object mbean, String mbeanName) {
    try {
        final ObjectName objName = Util.newObjectName(mbeanName);
        // inner class requires these fields to be final
        final MBeanServer mbs0 = mbs;
        final Object mbean0 = mbean;
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {

            public Void run() throws MBeanRegistrationException, NotCompliantMBeanException {
                try {
                    mbs0.registerMBean(mbean0, objName);
                    return null;
                } catch (InstanceAlreadyExistsException e) {
                // if an instance with the object name exists in
                // the MBeanServer ignore the exception
                }
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw Util.newException(e.getException());
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 17 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project ddf by codice.

the class QueryMonitor method registerMbean.

private void registerMbean() {
    try {
        objectName = new ObjectName(QueryMonitor.class.getName() + ":service=querymonitor");
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    } catch (MalformedObjectNameException e) {
        LOGGER.info("Unable to create Query Monitor Configuration MBean.", e);
    }
    if (mBeanServer == null) {
        return;
    }
    try {
        try {
            mBeanServer.registerMBean(this, objectName);
            LOGGER.debug("Registered Query Monitor Configuration MBean under object name: {}", objectName.toString());
        } catch (InstanceAlreadyExistsException e) {
            // Try to remove and re-register
            mBeanServer.unregisterMBean(objectName);
            mBeanServer.registerMBean(this, objectName);
            LOGGER.debug("Re-registered Query Monitor Configuration MBean");
        }
    } catch (MBeanRegistrationException | InstanceNotFoundException | InstanceAlreadyExistsException | NotCompliantMBeanException e) {
        LOGGER.info("Could not register MBean [{}].", objectName.toString(), e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 18 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project ddf by codice.

the class DataUsage method registerMbean.

private void registerMbean() {
    try {
        objectName = new ObjectName(DataUsage.class.getName() + ":service=datausage");
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    } catch (MalformedObjectNameException e) {
        LOGGER.error("Unable to create Data Usage Configuration MBean.", e);
    }
    if (mBeanServer == null) {
        return;
    }
    try {
        try {
            mBeanServer.registerMBean(this, objectName);
            LOGGER.info("Registered Data Usage Configuration MBean under object name: {}", objectName.toString());
        } catch (InstanceAlreadyExistsException e) {
            // Try to remove and re-register
            mBeanServer.unregisterMBean(objectName);
            mBeanServer.registerMBean(this, objectName);
            LOGGER.info("Re-registered Data Usage Configuration MBean");
        }
    } catch (MBeanRegistrationException | InstanceNotFoundException | InstanceAlreadyExistsException | NotCompliantMBeanException e) {
        LOGGER.error("Could not register MBean [{}].", objectName.toString(), e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 19 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project flink by apache.

the class JMXReporter method notifyOfAddedMetric.

// ------------------------------------------------------------------------
//  adding / removing metrics
// ------------------------------------------------------------------------
@Override
public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
    final String domain = generateJmxDomain(metricName, group);
    final Hashtable<String, String> table = generateJmxTable(group.getAllVariables());
    AbstractBean jmxMetric;
    ObjectName jmxName;
    try {
        jmxName = new ObjectName(domain, table);
    } catch (MalformedObjectNameException e) {
        /**
			 * There is an implementation error on our side if this occurs. Either the domain was modified and no longer
			 * conforms to the JMX domain rules or the table wasn't properly generated.
			 */
        LOG.debug("Implementation error. The domain or table does not conform to JMX rules.", e);
        return;
    }
    if (metric instanceof Gauge) {
        jmxMetric = new JmxGauge((Gauge<?>) metric);
    } else if (metric instanceof Counter) {
        jmxMetric = new JmxCounter((Counter) metric);
    } else if (metric instanceof Histogram) {
        jmxMetric = new JmxHistogram((Histogram) metric);
    } else if (metric instanceof Meter) {
        jmxMetric = new JmxMeter((Meter) metric);
    } else {
        LOG.error("Cannot add unknown metric type: {}. This indicates that the metric type " + "is not supported by this reporter.", metric.getClass().getName());
        return;
    }
    try {
        synchronized (this) {
            mBeanServer.registerMBean(jmxMetric, jmxName);
            registeredMetrics.put(metric, jmxName);
        }
    } catch (NotCompliantMBeanException e) {
        // implementation error on our side
        LOG.debug("Metric did not comply with JMX MBean rules.", e);
    } catch (InstanceAlreadyExistsException e) {
        LOG.warn("A metric with the name " + jmxName + " was already registered.", e);
    } catch (Throwable t) {
        LOG.warn("Failed to register metric", t);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Histogram(org.apache.flink.metrics.Histogram) Meter(org.apache.flink.metrics.Meter) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectName(javax.management.ObjectName) Gauge(org.apache.flink.metrics.Gauge) Counter(org.apache.flink.metrics.Counter)

Example 20 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project dropwizard by dropwizard.

the class DefaultLoggingFactory method configure.

@Override
public void configure(MetricRegistry metricRegistry, String name) {
    LoggingUtil.hijackJDKLogging();
    CHANGE_LOGGER_CONTEXT_LOCK.lock();
    final Logger root;
    try {
        root = configureLoggers(name);
    } finally {
        CHANGE_LOGGER_CONTEXT_LOCK.unlock();
    }
    final LevelFilterFactory<ILoggingEvent> levelFilterFactory = new ThresholdLevelFilterFactory();
    final AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory = new AsyncLoggingEventAppenderFactory();
    final LayoutFactory<ILoggingEvent> layoutFactory = new DropwizardLayoutFactory();
    for (AppenderFactory<ILoggingEvent> output : appenders) {
        root.addAppender(output.build(loggerContext, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
    }
    StatusPrinter.setPrintStream(configurationErrorsStream);
    try {
        StatusPrinter.printIfErrorsOccured(loggerContext);
    } finally {
        StatusPrinter.setPrintStream(System.out);
    }
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    MBEAN_REGISTRATION_LOCK.lock();
    try {
        final ObjectName objectName = new ObjectName("io.dropwizard:type=Logging");
        if (!server.isRegistered(objectName)) {
            server.registerMBean(new JMXConfigurator(loggerContext, server, objectName), objectName);
        }
    } catch (MalformedObjectNameException | InstanceAlreadyExistsException | NotCompliantMBeanException | MBeanRegistrationException e) {
        throw new RuntimeException(e);
    } finally {
        MBEAN_REGISTRATION_LOCK.unlock();
    }
    configureInstrumentation(root, metricRegistry);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) ThresholdLevelFilterFactory(io.dropwizard.logging.filter.ThresholdLevelFilterFactory) ObjectName(javax.management.ObjectName) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) JMXConfigurator(ch.qos.logback.classic.jmx.JMXConfigurator) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer)

Aggregations

NotCompliantMBeanException (javax.management.NotCompliantMBeanException)58 ObjectName (javax.management.ObjectName)37 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)29 MBeanRegistrationException (javax.management.MBeanRegistrationException)29 MBeanServer (javax.management.MBeanServer)26 MalformedObjectNameException (javax.management.MalformedObjectNameException)24 StandardMBean (javax.management.StandardMBean)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 MBeanException (javax.management.MBeanException)5 ReflectionException (javax.management.ReflectionException)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 Logger (org.apache.aries.jmx.Logger)4 RegistrableStandardEmitterMBean (org.apache.aries.jmx.util.shared.RegistrableStandardEmitterMBean)4 IntrospectionException (javax.management.IntrospectionException)3 JMRuntimeException (javax.management.JMRuntimeException)3 ObjectInstance (javax.management.ObjectInstance)3 RuntimeOperationsException (javax.management.RuntimeOperationsException)3 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)3 IOException (java.io.IOException)2