use of javax.management.NotCompliantMBeanException in project quasar by puniverse.
the class JMXForkJoinPoolMonitor method registerMBean.
protected void registerMBean() {
try {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName mxbeanName = new ObjectName(mbeanName);
mbs.registerMBean(this, mxbeanName);
this.registered = true;
} catch (InstanceAlreadyExistsException ex) {
throw new RuntimeException(ex);
} catch (MBeanRegistrationException ex) {
ex.printStackTrace();
} catch (NotCompliantMBeanException ex) {
throw new AssertionError(ex);
} catch (MalformedObjectNameException ex) {
throw new AssertionError(ex);
}
}
use of javax.management.NotCompliantMBeanException 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.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.
the class MBeanIntrospector method getPerInterface.
final PerInterface<M> getPerInterface(Class<?> mbeanInterface) throws NotCompliantMBeanException {
PerInterfaceMap<M> map = getPerInterfaceMap();
synchronized (map) {
WeakReference<PerInterface<M>> wr = map.get(mbeanInterface);
PerInterface<M> pi = (wr == null) ? null : wr.get();
if (pi == null) {
try {
MBeanAnalyzer<M> analyzer = getAnalyzer(mbeanInterface);
MBeanInfo mbeanInfo = makeInterfaceMBeanInfo(mbeanInterface, analyzer);
pi = new PerInterface<M>(mbeanInterface, this, analyzer, mbeanInfo);
wr = new WeakReference<PerInterface<M>>(pi);
map.put(mbeanInterface, wr);
} catch (Exception x) {
throw Introspector.throwException(mbeanInterface, x);
}
}
return pi;
}
}
use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.
the class MBeanAnalyzer method initMaps.
// Introspect the mbeanInterface and initialize this object's maps.
//
private void initMaps(Class<?> mbeanType, MBeanIntrospector<M> introspector) throws Exception {
final List<Method> methods1 = introspector.getMethods(mbeanType);
final List<Method> methods = eliminateCovariantMethods(methods1);
/* Run through the methods to detect inconsistencies and to enable
us to give getter and setter together to visitAttribute. */
for (Method m : methods) {
final String name = m.getName();
final int nParams = m.getParameterTypes().length;
final M cm = introspector.mFrom(m);
String attrName = "";
if (name.startsWith("get"))
attrName = name.substring(3);
else if (name.startsWith("is") && m.getReturnType() == boolean.class)
attrName = name.substring(2);
if (attrName.length() != 0 && nParams == 0 && m.getReturnType() != void.class) {
// It's a getter
// Check we don't have both isX and getX
AttrMethods<M> am = attrMap.get(attrName);
if (am == null)
am = new AttrMethods<M>();
else {
if (am.getter != null) {
final String msg = "Attribute " + attrName + " has more than one getter";
throw new NotCompliantMBeanException(msg);
}
}
am.getter = cm;
attrMap.put(attrName, am);
} else if (name.startsWith("set") && name.length() > 3 && nParams == 1 && m.getReturnType() == void.class) {
// It's a setter
attrName = name.substring(3);
AttrMethods<M> am = attrMap.get(attrName);
if (am == null)
am = new AttrMethods<M>();
else if (am.setter != null) {
final String msg = "Attribute " + attrName + " has more than one setter";
throw new NotCompliantMBeanException(msg);
}
am.setter = cm;
attrMap.put(attrName, am);
} else {
// It's an operation
List<M> cms = opMap.get(name);
if (cms == null)
cms = newList();
cms.add(cm);
opMap.put(name, cms);
}
}
/* Check that getters and setters are consistent. */
for (Map.Entry<String, AttrMethods<M>> entry : attrMap.entrySet()) {
AttrMethods<M> am = entry.getValue();
if (!introspector.consistent(am.getter, am.setter)) {
final String msg = "Getter and setter for " + entry.getKey() + " have inconsistent types";
throw new NotCompliantMBeanException(msg);
}
}
}
use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.
the class Introspector method checkCompliance.
public static void checkCompliance(Class<?> mbeanClass) throws NotCompliantMBeanException {
//
if (DynamicMBean.class.isAssignableFrom(mbeanClass))
return;
// Is Standard MBean?
//
final Exception mbeanException;
try {
getStandardMBeanInterface(mbeanClass);
return;
} catch (NotCompliantMBeanException e) {
mbeanException = e;
}
// Is MXBean?
//
final Exception mxbeanException;
try {
getMXBeanInterface(mbeanClass);
return;
} catch (NotCompliantMBeanException e) {
mxbeanException = e;
}
final String msg = "MBean class " + mbeanClass.getName() + " does not implement " + "DynamicMBean, and neither follows the Standard MBean conventions (" + mbeanException.toString() + ") nor the MXBean conventions (" + mxbeanException.toString() + ")";
throw new NotCompliantMBeanException(msg);
}
Aggregations