Search in sources :

Example 86 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project controller by opendaylight.

the class AbstractConfigTest method initConfigTransactionManagerImpl.

// this method should be called in @Before
protected void initConfigTransactionManagerImpl(final ModuleFactoriesResolver resolver) {
    final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    this.configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(platformMBeanServer);
    initBundleContext();
    this.baseJmxRegistrator = new BaseJMXRegistrator(platformMBeanServer);
    this.configRegistry = new ConfigRegistryImpl(resolver, platformMBeanServer, this.baseJmxRegistrator, new BindingContextProvider() {

        @Override
        public synchronized void update(final ClassLoadingStrategy classLoadingStrategy, final SchemaContextProvider ctxProvider) {
        // NOOP
        }

        @Override
        public synchronized BindingRuntimeContext getBindingContext() {
            return getBindingRuntimeContext();
        }
    });
    this.notifyingConfigRegistry = new JMXNotifierConfigRegistry(this.configRegistry, platformMBeanServer);
    try {
        this.configRegistryJMXRegistrator.registerToJMXNoNotifications(this.configRegistry);
        this.configRegistryJMXRegistrator.registerToJMX(this.notifyingConfigRegistry);
    } catch (final InstanceAlreadyExistsException e) {
        throw new RuntimeException(e);
    }
    this.configRegistryClient = new ConfigRegistryJMXClient(platformMBeanServer);
    this.currentBundleContextServiceRegistrationHandler = new RecordingBundleContextServiceRegistrationHandler();
}
Also used : JMXNotifierConfigRegistry(org.opendaylight.controller.config.manager.impl.jmx.JMXNotifierConfigRegistry) BindingContextProvider(org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider) BaseJMXRegistrator(org.opendaylight.controller.config.manager.impl.jmx.BaseJMXRegistrator) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ClassLoadingStrategy(org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy) SchemaContextProvider(org.opendaylight.yangtools.yang.model.api.SchemaContextProvider) ConfigRegistryJMXRegistrator(org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator) ConfigRegistryJMXClient(org.opendaylight.controller.config.util.ConfigRegistryJMXClient) MBeanServer(javax.management.MBeanServer)

Example 87 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project controller by opendaylight.

the class HierarchicalRuntimeBeanRegistrationImpl method register.

@Override
public HierarchicalRuntimeBeanRegistrationImpl register(final String key, final String value, final RuntimeBean mxBean) {
    Map<String, String> currentProperties = new HashMap<>(properties);
    currentProperties.put(key, value);
    ObjectName on = ObjectNameUtil.createRuntimeBeanName(moduleIdentifier.getFactoryName(), moduleIdentifier.getInstanceName(), currentProperties);
    InternalJMXRegistrator child = internalJMXRegistrator.createChild();
    try {
        child.registerMBean(mxBean, on);
    } catch (final InstanceAlreadyExistsException e) {
        throw RootRuntimeBeanRegistratorImpl.sanitize(e, moduleIdentifier, on);
    }
    return new HierarchicalRuntimeBeanRegistrationImpl(moduleIdentifier, child, currentProperties);
}
Also used : HashMap(java.util.HashMap) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectName(javax.management.ObjectName)

Example 88 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project sis by apache.

the class Supervisor method register.

/**
 * Registers the {@code Supervisor} instance, if not already done.
 * If the supervisor has already been registered but has not yet been
 * {@linkplain #unregister() unregistered}, then this method does nothing.
 *
 * <p>If the registration fails, then this method logs a message at the warning level
 * and the MBean will not be registered. This method does not propagate the exception
 * because the MBean is not a mandatory part of SIS library.</p>
 */
@Configuration
public static synchronized void register() {
    if (name == null) {
        // In case of failure.
        name = ObjectName.WILDCARD;
        final LogRecord record;
        try {
            final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            final ObjectName n = new ObjectName(NAME);
            server.registerMBean(new Supervisor(), n);
            // Store only on success.
            name = n;
            return;
        } catch (InstanceAlreadyExistsException e) {
            record = Messages.getResources(null).getLogRecord(Level.CONFIG, Messages.Keys.AlreadyRegistered_2, "MBean", NAME);
        } catch (JMException e) {
            record = new LogRecord(Level.WARNING, e.toString());
            record.setThrown(e);
        } catch (SecurityException e) {
            record = new LogRecord(Level.CONFIG, e.toString());
        }
        record.setLoggerName(Loggers.SYSTEM);
        Logging.log(Supervisor.class, "register", record);
    }
}
Also used : LogRecord(java.util.logging.LogRecord) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Configuration(org.apache.sis.util.Configuration)

Example 89 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project controller by opendaylight.

the class TwoInterfacesExportTest method tryToRegisterThreadPoolWithSameName.

@Test
public void tryToRegisterThreadPoolWithSameName() throws InstanceAlreadyExistsException {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    transaction.createModule(TestingScheduledThreadPoolModuleFactory.NAME, SCHEDULED1);
    try {
        transaction.createModule(TestingScheduledThreadPoolModuleFactory.NAME, SCHEDULED1);
        fail();
    } catch (final InstanceAlreadyExistsException e) {
        assertThat(e.getMessage(), containsString("There is an instance registered with name " + "ModuleIdentifier{factoryName='scheduled', instanceName='scheduled1'}"));
    }
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) Test(org.junit.Test)

Example 90 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project controller by opendaylight.

the class AbstractMXBean method registerMBean.

/**
 * Registers this bean with the platform MBean server with the domain defined by
 * {@link #BASE_JMX_PREFIX}.
 *
 * @return true is successfully registered, false otherwise.
 */
public boolean registerMBean() {
    boolean registered = false;
    try {
        // Object to identify MBean
        final ObjectName mbeanName = this.getMBeanObjectName();
        LOG.debug("Register MBean {}", mbeanName);
        // unregistered if already registered
        if (server.isRegistered(mbeanName)) {
            LOG.debug("MBean {} found to be already registered", mbeanName);
            try {
                unregisterMBean(mbeanName);
            } catch (MBeanRegistrationException | InstanceNotFoundException e) {
                LOG.warn("unregister mbean {} resulted in exception {} ", mbeanName, e);
            }
        }
        server.registerMBean(this, mbeanName);
        registered = true;
        LOG.debug("MBean {} registered successfully", mbeanName.getCanonicalName());
    } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | MalformedObjectNameException e) {
        LOG.error("registration failed {}", e);
    }
    return registered;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) 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