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