Search in sources :

Example 21 with MBeanRegistrationException

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

the class ResourceCacheServiceTest method setupMockMBeanServer.

private void setupMockMBeanServer(boolean isRegistered, boolean throwMBeanRegException) throws Exception {
    when(mockMBeanServer.isRegistered(resourceCacheServiceObjectName)).thenReturn(isRegistered);
    if (throwMBeanRegException) {
        doThrow(new MBeanRegistrationException(new Exception(), "")).when(mockMBeanServer).registerMBean(any(StandardMBean.class), eq(resourceCacheServiceObjectName));
        doThrow(new MBeanRegistrationException(new Exception(), "")).when(mockMBeanServer).unregisterMBean(resourceCacheServiceObjectName);
    }
}
Also used : StandardMBean(javax.management.StandardMBean) MBeanRegistrationException(javax.management.MBeanRegistrationException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 22 with MBeanRegistrationException

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

use of javax.management.MBeanRegistrationException 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 24 with MBeanRegistrationException

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

the class ApplicationServiceBeanTest method testDestroyWhenUnregisterMBeanThrowsMBeanRegistrationException.

/**
     * Tests the {@link ApplicationServiceBean#destroy()} method
     * for the case where an MBeanRegistrationException is thrown
     * by mBeanServer.unregisterMBean(...)
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testDestroyWhenUnregisterMBeanThrowsMBeanRegistrationException() throws Exception {
    ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
    doThrow(new MBeanRegistrationException(new Exception())).when(mBeanServer).unregisterMBean(any(ObjectName.class));
    serviceBean.destroy();
}
Also used : MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 25 with MBeanRegistrationException

use of javax.management.MBeanRegistrationException in project tomcat by apache.

the class SlowQueryReportJmx method deregisterJmx.

protected void deregisterJmx() {
    try {
        if (mbeans.remove(poolName) != null) {
            ObjectName oname = getObjectName(getClass(), poolName);
            ManagementFactory.getPlatformMBeanServer().unregisterMBean(oname);
        }
    } catch (MBeanRegistrationException e) {
        log.debug("Jmx deregistration failed.", e);
    } catch (InstanceNotFoundException e) {
        log.debug("Jmx deregistration failed.", e);
    } catch (MalformedObjectNameException e) {
        log.warn("Jmx deregistration failed.", e);
    } catch (RuntimeOperationsException e) {
        log.warn("Jmx deregistration failed.", e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

MBeanRegistrationException (javax.management.MBeanRegistrationException)48 ObjectName (javax.management.ObjectName)39 MalformedObjectNameException (javax.management.MalformedObjectNameException)35 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)31 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)29 InstanceNotFoundException (javax.management.InstanceNotFoundException)21 MBeanServer (javax.management.MBeanServer)20 StandardMBean (javax.management.StandardMBean)8 IOException (java.io.IOException)7 RuntimeOperationsException (javax.management.RuntimeOperationsException)5 MalformedURLException (java.net.MalformedURLException)4 JMRuntimeException (javax.management.JMRuntimeException)3 MBeanException (javax.management.MBeanException)3 ObjectInstance (javax.management.ObjectInstance)3 PrivilegedActionException (java.security.PrivilegedActionException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ReflectionException (javax.management.ReflectionException)2 Test (org.junit.Test)2 Logger (ch.qos.logback.classic.Logger)1