Search in sources :

Example 21 with InstanceAlreadyExistsException

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

the class CertificateGenerator method registerMbean.

protected void registerMbean() {
    ObjectName objectName = null;
    MBeanServer mBeanServer = null;
    try {
        objectName = new ObjectName(CertificateGenerator.class.getName() + ":service=certgenerator");
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    } catch (MalformedObjectNameException e) {
        LOGGER.info("Unable to create Certificate Generator MBean.", e);
    }
    if (mBeanServer != null) {
        try {
            try {
                mBeanServer.registerMBean(this, objectName);
                LOGGER.debug("Registered Certificate Generator MBean under object name: {}", objectName.toString());
            } catch (InstanceAlreadyExistsException e) {
                LOGGER.debug("Re-registered Certificate Generator MBean");
            }
        } catch (Exception e) {
            //objectName is not always non-null because new ObjectName(...) can throw an exception
            LOGGER.info("Could not register MBean [{}].", objectName != null ? objectName.toString() : CertificateGenerator.class.getName(), e);
        }
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 22 with InstanceAlreadyExistsException

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

the class TestMigratable method initWhenMBeanReRegistrationFails.

@Test(expected = MBeanRegistrationException.class)
public void initWhenMBeanReRegistrationFails() throws Exception {
    ConfigurationMigrationManager configurationMigrationManager = createConfigurationMigrationManager();
    when(mBeanServer.registerMBean(configurationMigrationManager, configMigrationServiceObjectName)).thenThrow(new InstanceAlreadyExistsException(), new MBeanRegistrationException(new Exception()));
    configurationMigrationManager.init();
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MigrationException(org.codice.ddf.migration.MigrationException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with InstanceAlreadyExistsException

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

the class LoggingService method init.

public void init() throws Exception {
    try {
        if (logEvents == null) {
            logEvents = EvictingQueue.create(DEFAULT_LOG_EVENTS_LIMIT);
        }
        objectName = new ObjectName(MBEAN_OBJECT_NAME);
        mBeanServer.registerMBean(this, objectName);
        LOGGER.debug("Registered [{}] MBean under object name: [{}].", CLASS_NAME, objectName.toString());
    } catch (InstanceAlreadyExistsException e) {
        LOGGER.debug("[{}] already registered as an MBean. Re-registering.", CLASS_NAME);
        mBeanServer.unregisterMBean(objectName);
        mBeanServer.registerMBean(this, objectName);
        LOGGER.debug("Successfully re-registered [{}] as an MBean.", CLASS_NAME);
    }
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectName(javax.management.ObjectName)

Example 24 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException 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 25 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException 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)

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)49 ObjectName (javax.management.ObjectName)38 MalformedObjectNameException (javax.management.MalformedObjectNameException)30 MBeanRegistrationException (javax.management.MBeanRegistrationException)29 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)28 MBeanServer (javax.management.MBeanServer)25 InstanceNotFoundException (javax.management.InstanceNotFoundException)14 ObjectInstance (javax.management.ObjectInstance)8 IOException (java.io.IOException)6 StandardMBean (javax.management.StandardMBean)6 Test (org.junit.Test)3 MalformedURLException (java.net.MalformedURLException)2 CacheException (javax.cache.CacheException)2 JMRuntimeException (javax.management.JMRuntimeException)2 MBeanException (javax.management.MBeanException)2 ReflectionException (javax.management.ReflectionException)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 Logger (ch.qos.logback.classic.Logger)1 JMXConfigurator (ch.qos.logback.classic.jmx.JMXConfigurator)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1