use of javax.management.InstanceAlreadyExistsException in project ddf by codice.
the class TestMigratable method initWhenMBeanUnregistrationFails.
@Test(expected = MBeanRegistrationException.class)
public void initWhenMBeanUnregistrationFails() throws Exception {
ConfigurationMigrationManager configurationMigrationManager = createConfigurationMigrationManager();
when(mBeanServer.registerMBean(configurationMigrationManager, configMigrationServiceObjectName)).thenThrow(new InstanceAlreadyExistsException());
doThrow(new MBeanRegistrationException(new Exception())).when(mBeanServer).unregisterMBean(configMigrationServiceObjectName);
configurationMigrationManager.init();
}
use of javax.management.InstanceAlreadyExistsException in project ddf by codice.
the class Geocoding method registerMbean.
private void registerMbean() {
ObjectName objectName = null;
MBeanServer mBeanServer = null;
try {
objectName = new ObjectName(Geocoding.class.getName() + ":service=geocoding");
mBeanServer = ManagementFactory.getPlatformMBeanServer();
} catch (MalformedObjectNameException e) {
LOGGER.info("Unable to create Geocoding Configuration MBean.", e);
}
if (mBeanServer != null) {
try {
try {
mBeanServer.registerMBean(this, objectName);
LOGGER.debug("Registered Geocoding 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 Geocoding Configuration 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() : Geocoding.class.getName(), e);
}
}
}
use of javax.management.InstanceAlreadyExistsException in project ddf by codice.
the class ApplicationServiceBean method init.
/**
* Initializes the initial variables and registers the class to the MBean
* server. <br/>
* <br/>
* <b>NOTE: This should be run before any other operations are performed.
* Operations will NOT be usable until this is called (and until destroy()
* is called).</b>
*
* @throws ApplicationServiceException if an error occurs during registration.
*/
public void init() throws ApplicationServiceException {
try {
try {
LOGGER.debug("Registering application service MBean under object name: {}", objectName.toString());
mBeanServer.registerMBean(this, objectName);
} catch (InstanceAlreadyExistsException iaee) {
// Try to remove and re-register
LOGGER.debug("Re-registering Application Service MBean");
mBeanServer.unregisterMBean(objectName);
mBeanServer.registerMBean(this, objectName);
}
} catch (Exception e) {
LOGGER.warn("Could not register mbean.", e);
throw new ApplicationServiceException(e);
}
}
use of javax.management.InstanceAlreadyExistsException in project ddf by codice.
the class ConfigurationAdminTest method testInitAlreadyExists.
/**
* Tests the {@link ConfigurationAdmin#init()} method for the case where
* it has already been initialized
*
* @throws Exception
*/
@Test
public void testInitAlreadyExists() throws Exception {
org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
MBeanServer testServer = mock(MBeanServer.class);
ConfigurationAdmin configAdmin = new ConfigurationAdmin(testConfigAdmin);
configAdmin.setMBeanServer(testServer);
when(testServer.registerMBean(any(Object.class), any(ObjectName.class))).thenThrow(new InstanceAlreadyExistsException()).thenReturn(null);
configAdmin.init();
verify(testServer, times(2)).registerMBean(any(Object.class), any(ObjectName.class));
verify(testServer).unregisterMBean(any(ObjectName.class));
}
use of javax.management.InstanceAlreadyExistsException in project ddf by codice.
the class UndeliveredMessages method registerMbean.
private void registerMbean() {
try {
undeliveredMessagesObjectName = new ObjectName(UndeliveredMessages.class.getName() + M_BEAN_NAME);
} catch (MalformedObjectNameException e) {
LOGGER.warn("Unable to create MBean: [{}]. For more " + "information, set logging level to DEBUG.", undeliveredMessagesObjectName);
LOGGER.debug("Unable to create MBean: [{}].", undeliveredMessagesObjectName, e);
}
if (mBeanServer == null) {
LOGGER.warn("Could not register MBean: [{}], MBean server is null.", undeliveredMessagesObjectName);
return;
}
try {
try {
mBeanServer.registerMBean(this, undeliveredMessagesObjectName);
LOGGER.info("Registered MBean under object name: {}", undeliveredMessagesObjectName);
} catch (InstanceAlreadyExistsException e) {
// Try to remove and re-register
mBeanServer.unregisterMBean(undeliveredMessagesObjectName);
mBeanServer.registerMBean(this, undeliveredMessagesObjectName);
LOGGER.info("Re-registered MBean: [{}]", undeliveredMessagesObjectName);
}
} catch (MBeanRegistrationException | InstanceNotFoundException | InstanceAlreadyExistsException | NotCompliantMBeanException e) {
LOGGER.warn("Could not register MBean: [{}]. For more information, set " + "logging level to DEBUG.", undeliveredMessagesObjectName);
LOGGER.debug("Could not register MBean: [{}].", undeliveredMessagesObjectName, e);
}
}
Aggregations