use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method isInstanceOf.
public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException {
final DynamicMBean instance = getMBean(name);
checkMBeanPermission(instance, null, name, "isInstanceOf");
try {
Object resource = getResource(instance);
final String resourceClassName = (resource instanceof DynamicMBean) ? getClassName((DynamicMBean) resource) : resource.getClass().getName();
if (resourceClassName.equals(className))
return true;
final ClassLoader cl = resource.getClass().getClassLoader();
final Class<?> classNameClass = Class.forName(className, false, cl);
if (classNameClass.isInstance(resource))
return true;
final Class<?> resourceClass = Class.forName(resourceClassName, false, cl);
return classNameClass.isAssignableFrom(resourceClass);
} catch (Exception x) {
/* Could be SecurityException or ClassNotFoundException */
if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
MBEANSERVER_LOGGER.logp(Level.FINEST, DefaultMBeanServerInterceptor.class.getName(), "isInstanceOf", "Exception calling isInstanceOf", x);
}
return false;
}
}
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 jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getMBeanInfo.
public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException {
// ------------------------------
// ------------------------------
DynamicMBean moi = getMBean(name);
final MBeanInfo mbi;
try {
mbi = moi.getMBeanInfo();
} catch (RuntimeMBeanException e) {
throw e;
} catch (RuntimeErrorException e) {
throw e;
} catch (RuntimeException e) {
throw new RuntimeMBeanException(e, "getMBeanInfo threw RuntimeException");
} catch (Error e) {
throw new RuntimeErrorException(e, "getMBeanInfo threw Error");
}
if (mbi == null)
throw new JMRuntimeException("MBean " + name + "has no MBeanInfo");
checkMBeanPermission(mbi.getClassName(), null, name, "getMBeanInfo");
return mbi;
}
Aggregations