Search in sources :

Example 66 with InstanceAlreadyExistsException

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();
}
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 67 with InstanceAlreadyExistsException

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);
        }
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) GeoEntryExtractionException(org.codice.ddf.spatial.geocoding.GeoEntryExtractionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) GeoEntryIndexingException(org.codice.ddf.spatial.geocoding.GeoEntryIndexingException) GeoNamesRemoteDownloadException(org.codice.ddf.spatial.geocoding.GeoNamesRemoteDownloadException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 68 with InstanceAlreadyExistsException

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);
    }
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) URISyntaxException(java.net.URISyntaxException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 69 with InstanceAlreadyExistsException

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));
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 70 with InstanceAlreadyExistsException

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

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)116 ObjectName (javax.management.ObjectName)87 MBeanRegistrationException (javax.management.MBeanRegistrationException)73 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)70 MalformedObjectNameException (javax.management.MalformedObjectNameException)64 MBeanServer (javax.management.MBeanServer)48 InstanceNotFoundException (javax.management.InstanceNotFoundException)37 IOException (java.io.IOException)13 ObjectInstance (javax.management.ObjectInstance)12 Test (org.junit.Test)12 StandardMBean (javax.management.StandardMBean)9 MBeanException (javax.management.MBeanException)7 ReflectionException (javax.management.ReflectionException)7 HashMap (java.util.HashMap)5 JMRuntimeException (javax.management.JMRuntimeException)4 RuntimeOperationsException (javax.management.RuntimeOperationsException)4 MalformedURLException (java.net.MalformedURLException)3 AttributeNotFoundException (javax.management.AttributeNotFoundException)3 DynamicMBean (javax.management.DynamicMBean)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3