use of javax.management.ObjectInstance in project pulsar by yahoo.
the class MBeanStatsGenerator method generate.
private Collection<Metrics> generate() {
List<Metrics> metricsCollection = new ArrayList<Metrics>();
@SuppressWarnings("unchecked") Set<ObjectInstance> instances = mbs.queryMBeans(null, null);
for (ObjectInstance instance : instances) {
String beanName = instance.getObjectName().toString();
// skip GC MBean to avoid recursion
if (beanName.startsWith("java.lang:type=GarbageCollector")) {
continue;
}
Metrics metrics = convert(instance);
if (metrics != null) {
metricsCollection.add(metrics);
}
}
return metricsCollection;
}
use of javax.management.ObjectInstance in project jdk8u_jdk by JetBrains.
the class ServerNotifForwarder method checkMBeanPermission.
static void checkMBeanPermission(final MBeanServer mbs, final ObjectName name, final String actions) throws InstanceNotFoundException, SecurityException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
AccessControlContext acc = AccessController.getContext();
ObjectInstance oi;
try {
oi = AccessController.doPrivileged(new PrivilegedExceptionAction<ObjectInstance>() {
public ObjectInstance run() throws InstanceNotFoundException {
return mbs.getObjectInstance(name);
}
});
} catch (PrivilegedActionException e) {
throw (InstanceNotFoundException) extractException(e);
}
String classname = oi.getClassName();
MBeanPermission perm = new MBeanPermission(classname, null, name, actions);
sm.checkPermission(perm, acc);
}
}
use of javax.management.ObjectInstance in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method registerDynamicMBean.
private ObjectInstance registerDynamicMBean(String classname, DynamicMBean mbean, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
name = nonDefaultDomain(name);
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "registerMBean", "ObjectName = " + name);
}
ObjectName logicalName = preRegister(mbean, server, name);
// preRegister returned successfully, so from this point on we
// must call postRegister(false) if there is any problem.
boolean registered = false;
boolean registerFailed = false;
ResourceContext context = null;
try {
if (mbean instanceof DynamicMBean2) {
try {
((DynamicMBean2) mbean).preRegister2(server, logicalName);
// until we succeed
registerFailed = true;
} catch (Exception e) {
if (e instanceof RuntimeException)
throw (RuntimeException) e;
if (e instanceof InstanceAlreadyExistsException)
throw (InstanceAlreadyExistsException) e;
throw new RuntimeException(e);
}
}
if (logicalName != name && logicalName != null) {
logicalName = ObjectName.getInstance(nonDefaultDomain(logicalName));
}
checkMBeanPermission(classname, null, logicalName, "registerMBean");
if (logicalName == null) {
final RuntimeException wrapped = new IllegalArgumentException("No object name specified");
throw new RuntimeOperationsException(wrapped, "Exception occurred trying to register the MBean");
}
final Object resource = getResource(mbean);
// Register the MBean with the repository.
// Returns the resource context that was used.
// The returned context does nothing for regular MBeans.
// For ClassLoader MBeans the context makes it possible to register these
// objects with the appropriate framework artifacts, such as
// the CLR, from within the repository lock.
// In case of success, we also need to call context.done() at the
// end of this method.
//
context = registerWithRepository(resource, mbean, logicalName);
registerFailed = false;
registered = true;
} finally {
try {
postRegister(logicalName, mbean, registered, registerFailed);
} finally {
if (registered && context != null)
context.done();
}
}
return new ObjectInstance(logicalName, classname);
}
use of javax.management.ObjectInstance in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method queryMBeans.
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
// Check if the caller has the right to invoke 'queryMBeans'
//
checkMBeanPermission((String) null, null, null, "queryMBeans");
// Perform query without "query".
//
Set<ObjectInstance> list = queryMBeansImpl(name, null);
// Check if the caller has the right to invoke 'queryMBeans'
// on each specific classname/objectname in the list.
//
Set<ObjectInstance> allowedList = new HashSet<ObjectInstance>(list.size());
for (ObjectInstance oi : list) {
try {
checkMBeanPermission(oi.getClassName(), null, oi.getObjectName(), "queryMBeans");
allowedList.add(oi);
} catch (SecurityException e) {
// OK: Do not add this ObjectInstance to the list
}
}
//
return filterListOfObjectInstances(allowedList, query);
} else {
//
return queryMBeansImpl(name, query);
}
}
use of javax.management.ObjectInstance in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getObjectInstance.
public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException {
name = nonDefaultDomain(name);
DynamicMBean instance = getMBean(name);
checkMBeanPermission(instance, null, name, "getObjectInstance");
final String className = getClassName(instance);
return new ObjectInstance(name, className);
}
Aggregations