use of javax.management.DynamicMBean in project sling by apache.
the class JmxAdjustableStatusForTestingIT method invokeMBean.
private void invokeMBean(String operation, Object[] args, String[] signature) throws Exception {
ServiceReference[] serviceReference = bundleContext.getServiceReferences(DynamicMBean.class.getName(), "(jmx.objectname=org.apache.sling.healthcheck:type=AdjustableHealthCheckForTesting)");
DynamicMBean mBean = (DynamicMBean) bundleContext.getService(serviceReference[0]);
mBean.invoke(operation, args, signature);
}
use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method exclusiveUnregisterMBean.
private void exclusiveUnregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException {
DynamicMBean instance = getMBean(name);
// may throw InstanceNotFoundException
checkMBeanPermission(instance, null, name, "unregisterMBean");
if (instance instanceof MBeanRegistration)
preDeregisterInvoke((MBeanRegistration) instance);
final Object resource = getResource(instance);
// Unregisters the MBean from the repository.
// Returns the resource context that was used.
// The returned context does nothing for regular MBeans.
// For ClassLoader MBeans and JMXNamespace (and JMXDomain)
// MBeans - the context makes it possible to unregister these
// objects from the appropriate framework artifacts, such as
// the CLR or the dispatcher, from within the repository lock.
// In case of success, we also need to call context.done() at the
// end of this method.
//
final ResourceContext context = unregisterFromRepository(resource, instance, name);
try {
if (instance instanceof MBeanRegistration)
postDeregisterInvoke(name, (MBeanRegistration) instance);
} finally {
context.done();
}
}
use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method objectInstancesFromFilteredNamedObjects.
/**
* Applies the specified queries to the set of NamedObjects.
*/
private Set<ObjectInstance> objectInstancesFromFilteredNamedObjects(Set<NamedObject> list, QueryExp query) {
Set<ObjectInstance> result = new HashSet<ObjectInstance>();
// No query ...
if (query == null) {
for (NamedObject no : list) {
final DynamicMBean obj = no.getObject();
final String className = safeGetClassName(obj);
result.add(new ObjectInstance(no.getName(), className));
}
} else {
// Access the filter
MBeanServer oldServer = QueryEval.getMBeanServer();
query.setMBeanServer(server);
try {
for (NamedObject no : list) {
final DynamicMBean obj = no.getObject();
boolean res;
try {
res = query.apply(no.getName());
} catch (Exception e) {
res = false;
}
if (res) {
String className = safeGetClassName(obj);
result.add(new ObjectInstance(no.getName(), className));
}
}
} finally {
/*
* query.setMBeanServer is probably
* QueryEval.setMBeanServer so put back the old
* value. Since that method uses a ThreadLocal
* variable, this code is only needed for the
* unusual case where the user creates a custom
* QueryExp that calls a nested query on another
* MBeanServer.
*/
query.setMBeanServer(oldServer);
}
}
return result;
}
use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getClassLoader.
/**
* <p>Return the named {@link java.lang.ClassLoader}.
* @param loaderName The ObjectName of the ClassLoader.
* @return The named ClassLoader.
* @exception InstanceNotFoundException if the named ClassLoader
* is not found.
*/
public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException {
if (loaderName == null) {
checkMBeanPermission((String) null, null, null, "getClassLoader");
return server.getClass().getClassLoader();
}
DynamicMBean instance = getMBean(loaderName);
checkMBeanPermission(instance, null, loaderName, "getClassLoader");
Object resource = getResource(instance);
/* Check if the given MBean is a ClassLoader */
if (!(resource instanceof ClassLoader))
throw new InstanceNotFoundException(loaderName.toString() + " is not a classloader");
return (ClassLoader) resource;
}
use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method setAttribute.
public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, 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 (attribute == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
}
name = nonDefaultDomain(name);
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "setAttribute", "ObjectName = " + name + ", Attribute = " + attribute.getName());
}
DynamicMBean instance = getMBean(name);
checkMBeanPermission(instance, attribute.getName(), name, "setAttribute");
try {
instance.setAttribute(attribute);
} catch (AttributeNotFoundException e) {
throw e;
} catch (InvalidAttributeValueException e) {
throw e;
} catch (Throwable t) {
rethrowMaybeMBeanException(t);
throw new AssertionError();
}
}
Aggregations