use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method setAttributes.
public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException {
if (name == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("ObjectName name cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
}
if (attributes == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("AttributeList cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
}
name = nonDefaultDomain(name);
final DynamicMBean instance = getMBean(name);
final AttributeList allowedAttributes;
final SecurityManager sm = System.getSecurityManager();
if (sm == null)
allowedAttributes = attributes;
else {
String classname = getClassName(instance);
// Check if the caller has the right to invoke 'setAttribute'
//
checkMBeanPermission(classname, null, name, "setAttribute");
// Check if the caller has the right to invoke 'setAttribute'
// on each specific attribute
//
allowedAttributes = new AttributeList(attributes.size());
for (Attribute attribute : attributes.asList()) {
try {
checkMBeanPermission(classname, attribute.getName(), name, "setAttribute");
allowedAttributes.add(attribute);
} catch (SecurityException e) {
// OK: Do not add this attribute to the list
}
}
}
try {
return instance.setAttributes(allowedAttributes);
} catch (Throwable t) {
rethrow(t);
throw new AssertionError();
}
}
use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getListener.
private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException {
// ----------------
// Get listener object
// ----------------
DynamicMBean instance;
try {
instance = getMBean(listener);
} catch (InstanceNotFoundException e) {
throw EnvHelp.initCause(new ListenerNotFoundException(e.getMessage()), e);
}
Object resource = getResource(instance);
if (!(resource instanceof NotificationListener)) {
final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName());
final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName();
throw new RuntimeOperationsException(exc, msg);
}
return (NotificationListener) resource;
}
use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method addNotificationListener.
public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException {
// ------------------------------
// ------------------------------
// ----------------
// Get listener object
// ----------------
DynamicMBean instance = getMBean(listener);
Object resource = getResource(instance);
if (!(resource instanceof NotificationListener)) {
throw new RuntimeOperationsException(new IllegalArgumentException(listener.getCanonicalName()), "The MBean " + listener.getCanonicalName() + "does not implement the NotificationListener interface");
}
// ----------------
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name + ", Listener = " + listener);
}
server.addNotificationListener(name, (NotificationListener) resource, filter, handback);
}
use of javax.management.DynamicMBean in project controller by opendaylight.
the class ConfigTransactionControllerImpl method putConfigBeanToJMXAndInternalMaps.
private synchronized ObjectName putConfigBeanToJMXAndInternalMaps(final ModuleIdentifier moduleIdentifier, final Module module, final ModuleFactory moduleFactory, @Nullable final ModuleInternalInfo maybeOldConfigBeanInfo, final DependencyResolver dependencyResolver, final boolean isDefaultBean, final BundleContext bundleContext) throws InstanceAlreadyExistsException {
LOG.debug("Adding module {} to transaction {}", moduleIdentifier, this);
if (!moduleIdentifier.equals(module.getIdentifier())) {
throw new IllegalStateException("Incorrect name reported by module. Expected " + moduleIdentifier + ", got " + module.getIdentifier());
}
if (!dependencyResolver.getIdentifier().equals(moduleIdentifier)) {
throw new IllegalStateException("Incorrect name reported by dependency resolver. Expected " + moduleIdentifier + ", got " + dependencyResolver.getIdentifier());
}
DynamicMBean writableDynamicWrapper = new DynamicWritableWrapper(module, moduleIdentifier, getTransactionIdentifier().getName(), readOnlyAtomicBoolean, transactionsMBeanServer, configMBeanServer);
ObjectName writableON = ObjectNameUtil.createTransactionModuleON(getTransactionIdentifier().getName(), moduleIdentifier);
// put wrapper to jmx
TransactionModuleJMXRegistration transactionModuleJMXRegistration = getTxModuleJMXRegistrator().registerMBean(writableDynamicWrapper, writableON);
dependencyResolverManager.put(moduleIdentifier, module, moduleFactory, maybeOldConfigBeanInfo, transactionModuleJMXRegistration, isDefaultBean, bundleContext);
return writableON;
}
use of javax.management.DynamicMBean in project controller by opendaylight.
the class AbstractDynamicWrapperTest method testReadAttributes.
@Test
public void testReadAttributes() throws Exception {
DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);
assertEquals(threadCount, proxy.getAttribute(THREAD_COUNT));
assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(), proxy.getAttribute(TRIGGER_NEW_INSTANCE_CREATION));
AttributeList attributes = proxy.getAttributes(new String[] { THREAD_COUNT, TRIGGER_NEW_INSTANCE_CREATION });
assertEquals(2, attributes.size());
Attribute threadCountAttr = (Attribute) attributes.get(0);
assertEquals(THREAD_COUNT, threadCountAttr.getName());
assertEquals(threadCount, threadCountAttr.getValue());
Attribute boolTestAttr = (Attribute) attributes.get(1);
assertEquals(TRIGGER_NEW_INSTANCE_CREATION, boolTestAttr.getName());
assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(), boolTestAttr.getValue());
MBeanInfo beanInfo = proxy.getMBeanInfo();
assertEquals(2, beanInfo.getAttributes().length);
}
Aggregations