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);
}
}
}
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();
}
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);
}
}
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);
}
}
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);
}
}
Aggregations