use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.
the class DefaultMXBeanMappingFactory method makeCompositeMapping.
private MXBeanMapping makeCompositeMapping(Class<?> c, MXBeanMappingFactory factory) throws OpenDataException {
// For historical reasons GcInfo implements CompositeData but we
// shouldn't count its CompositeData.getCompositeType() field as
// an item in the computed CompositeType.
final boolean gcInfoHack = (c.getName().equals("com.sun.management.GcInfo") && c.getClassLoader() == null);
ReflectUtil.checkPackageAccess(c);
final List<Method> methods = MBeanAnalyzer.eliminateCovariantMethods(Arrays.asList(c.getMethods()));
final SortedMap<String, Method> getterMap = newSortedMap();
/* Select public methods that look like "T getX()" or "boolean
isX()", where T is not void and X is not the empty
string. Exclude "Class getClass()" inherited from Object. */
for (Method method : methods) {
final String propertyName = propertyName(method);
if (propertyName == null)
continue;
if (gcInfoHack && propertyName.equals("CompositeType"))
continue;
Method old = getterMap.put(decapitalize(propertyName), method);
if (old != null) {
final String msg = "Class " + c.getName() + " has method name clash: " + old.getName() + ", " + method.getName();
throw new OpenDataException(msg);
}
}
final int nitems = getterMap.size();
if (nitems == 0) {
throw new OpenDataException("Can't map " + c.getName() + " to an open data type");
}
final Method[] getters = new Method[nitems];
final String[] itemNames = new String[nitems];
final OpenType<?>[] openTypes = new OpenType<?>[nitems];
int i = 0;
for (Map.Entry<String, Method> entry : getterMap.entrySet()) {
itemNames[i] = entry.getKey();
final Method getter = entry.getValue();
getters[i] = getter;
final Type retType = getter.getGenericReturnType();
openTypes[i] = factory.mappingForType(retType, factory).getOpenType();
i++;
}
CompositeType compositeType = new CompositeType(c.getName(), c.getName(), // field names
itemNames, // field descriptions
itemNames, openTypes);
return new CompositeMapping(c, compositeType, itemNames, getters, factory);
}
use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.
the class ThreadInfoCompositeData method getCompositeData.
protected CompositeData getCompositeData() {
// Convert StackTraceElement[] to CompositeData[]
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
CompositeData[] stackTraceData = new CompositeData[stackTrace.length];
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement ste = stackTrace[i];
stackTraceData[i] = StackTraceElementCompositeData.toCompositeData(ste);
}
// Convert MonitorInfo[] and LockInfo[] to CompositeData[]
CompositeData lockInfoData = LockInfoCompositeData.toCompositeData(threadInfo.getLockInfo());
// Convert LockInfo[] and MonitorInfo[] to CompositeData[]
LockInfo[] lockedSyncs = threadInfo.getLockedSynchronizers();
CompositeData[] lockedSyncsData = new CompositeData[lockedSyncs.length];
for (int i = 0; i < lockedSyncs.length; i++) {
LockInfo li = lockedSyncs[i];
lockedSyncsData[i] = LockInfoCompositeData.toCompositeData(li);
}
MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
CompositeData[] lockedMonitorsData = new CompositeData[lockedMonitors.length];
for (int i = 0; i < lockedMonitors.length; i++) {
MonitorInfo mi = lockedMonitors[i];
lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi);
}
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
// threadInfoItemNames!
final Object[] threadInfoItemValues = { new Long(threadInfo.getThreadId()), threadInfo.getThreadName(), threadInfo.getThreadState().name(), new Long(threadInfo.getBlockedTime()), new Long(threadInfo.getBlockedCount()), new Long(threadInfo.getWaitedTime()), new Long(threadInfo.getWaitedCount()), lockInfoData, threadInfo.getLockName(), new Long(threadInfo.getLockOwnerId()), threadInfo.getLockOwnerName(), stackTraceData, new Boolean(threadInfo.isSuspended()), new Boolean(threadInfo.isInNative()), lockedMonitorsData, lockedSyncsData };
try {
return new CompositeDataSupport(threadInfoCompositeType, threadInfoItemNames, threadInfoItemValues);
} catch (OpenDataException e) {
// Should never reach here
throw new AssertionError(e);
}
}
use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.
the class NotCompliantCauseTest method test1.
/**
* Test that NotCompliantMBeanException has a cause in case of
* type mapping problems.
**/
void test1() {
try {
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
ObjectName oname = new ObjectName("domain:type=test");
mbs.createMBean(NotCompliant.class.getName(), oname);
System.err.println("ERROR: expected " + "NotCompliantMBeanException not thrown");
throw new RuntimeTestException("NotCompliantMBeanException not thrown");
} catch (RuntimeTestException e) {
throw e;
} catch (NotCompliantMBeanException e) {
Throwable cause = e.getCause();
if (cause == null)
throw new RuntimeTestException("NotCompliantMBeanException " + "doesn't have any cause.", e);
while (cause.getCause() != null) {
if (cause instanceof OpenDataException)
break;
cause = cause.getCause();
}
if (!(cause instanceof OpenDataException))
throw new RuntimeTestException("NotCompliantMBeanException " + "doesn't have expected cause (" + OpenDataException.class.getName() + "): " + cause, e);
System.err.println("SUCCESS: Found expected cause: " + cause);
} catch (Exception e) {
System.err.println("Unexpected exception: " + e);
throw new RuntimeException("Unexpected exception: " + e, e);
}
}
use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.
the class MXBeanRefTest method main.
public static void main(String[] args) throws Exception {
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
ObjectName productName = new ObjectName("d:type=Product,n=1");
ObjectName product2Name = new ObjectName("d:type=Product,n=2");
ObjectName moduleName = new ObjectName("d:type=Module");
mbs.registerMBean(product, productName);
mbs.registerMBean(product2, product2Name);
mbs.registerMBean(module, moduleName);
ModuleMXBean moduleProxy = JMX.newMXBeanProxy(mbs, moduleName, ModuleMXBean.class);
ObjectName on;
on = (ObjectName) mbs.getAttribute(moduleName, "Product");
check("ObjectName attribute value", on.equals(productName));
ProductMXBean productProxy = moduleProxy.getProduct();
MBeanServerInvocationHandler mbsih = (MBeanServerInvocationHandler) Proxy.getInvocationHandler(productProxy);
check("ObjectName in proxy", mbsih.getObjectName().equals(productName));
mbs.setAttribute(moduleName, new Attribute("Product", product2Name));
ProductMXBean product2Proxy = module.getProduct();
mbsih = (MBeanServerInvocationHandler) Proxy.getInvocationHandler(product2Proxy);
check("Proxy after setAttribute", mbsih.getObjectName().equals(product2Name));
moduleProxy.setProduct(productProxy);
ProductMXBean productProxyAgain = module.getProduct();
mbsih = (MBeanServerInvocationHandler) Proxy.getInvocationHandler(productProxyAgain);
check("Proxy after proxied set", mbsih.getObjectName().equals(productName));
MBeanServer mbs2 = MBeanServerFactory.createMBeanServer();
ProductMXBean productProxy2 = JMX.newMXBeanProxy(mbs2, productName, ProductMXBean.class);
try {
moduleProxy.setProduct(productProxy2);
check("Proxy for wrong MBeanServer worked but shouldn't", false);
} catch (Exception e) {
if (e instanceof UndeclaredThrowableException && e.getCause() instanceof OpenDataException)
check("Proxy for wrong MBeanServer correctly rejected", true);
else {
e.printStackTrace(System.out);
check("Proxy for wrong MBeanServer got wrong exception", false);
}
}
// Test 6283873
ObjectName dup = new ObjectName("a:b=c");
mbs.registerMBean(new MBeanServerDelegate(), dup);
try {
mbs.registerMBean(new ProductImpl(), dup);
check("Duplicate register succeeded but should fail", false);
} catch (InstanceAlreadyExistsException e) {
check("Got correct exception from duplicate name", true);
} catch (Exception e) {
e.printStackTrace(System.out);
check("Got wrong exception from duplicate name", false);
}
if (failure != null)
throw new Exception("TEST FAILED: " + failure);
System.out.println("TEST PASSED");
}
use of javax.management.openmbean.OpenDataException in project aries by apache.
the class BundleWiringData method getRequirementsCompositeData.
public static CompositeData[] getRequirementsCompositeData(List<BundleRequirement> bundleRequirements) {
try {
CompositeData[] data = new CompositeData[bundleRequirements.size()];
for (int i = 0; i < bundleRequirements.size(); i++) {
BundleRequirement requirement = bundleRequirements.get(i);
CompositeData cd = BundleWiringData.getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_REQUIREMENT_TYPE, requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet());
data[i] = cd;
}
return data;
} catch (OpenDataException e) {
throw new IllegalStateException("Can't create CompositeData", e);
}
}
Aggregations