use of javax.management.openmbean.CompositeType in project neo4j by neo4j.
the class JmxQueryProcedureTest method shouldHandleCompositeAttributes.
@Test
public void shouldHandleCompositeAttributes() throws Throwable {
// given
ObjectName beanName = new ObjectName("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference");
when(jmxServer.queryNames(new ObjectName("*:*"), null)).thenReturn(asSet(beanName));
when(jmxServer.getMBeanInfo(beanName)).thenReturn(new MBeanInfo("org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[] { new MBeanAttributeInfo("name", "differenceMaker", "Who makes the difference?", true, false, false) }, null, null, null));
when(jmxServer.getAttribute(beanName, "name")).thenReturn(new CompositeDataSupport(new CompositeType("myComposite", "Composite description", new String[] { "key1", "key2" }, new String[] { "Can't be empty", "Also can't be empty" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.INTEGER }), map("key1", "Hello", "key2", 123)));
JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), jmxServer);
// when
RawIterator<Object[], ProcedureException> result = procedure.apply(null, new Object[] { "*:*" });
// then
assertThat(asList(result), contains(equalTo(new Object[] { "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference", "This is a description", map(attributeName, map("description", "Who makes the difference?", "value", map("description", "Composite description", "properties", map("key1", "Hello", "key2", 123)))) })));
}
use of javax.management.openmbean.CompositeType in project nhin-d by DirectProject.
the class FileAuditor method registerMBean.
/*
* Register the MBean
*/
private void registerMBean() {
LOGGER.info("Registering FileAuditor MBean");
try {
itemNames = new String[] { "Event Id", "Event Time", "Event Principal", "Event Name", "Event Type", "Contexts" };
OpenType<?>[] types = { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, ArrayType.getArrayType(SimpleType.STRING) };
eventType = new CompositeType("AuditEvent", "Direct Auditable Event", itemNames, itemNames, types);
} catch (OpenDataException e) {
LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
return;
}
Class<?> clazz = this.getClass();
final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
objectNameBuilder.append(":type=").append(clazz.getSimpleName());
objectNameBuilder.append(",name=").append(UUID.randomUUID());
try {
final StandardMBean mbean = new StandardMBean(this, AuditorMBean.class);
final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
} catch (JMException e) {
LOGGER.error("Unable to register the FileAuditor MBean", e);
}
}
use of javax.management.openmbean.CompositeType in project nhin-d by DirectProject.
the class RDBMSAuditor method registerMBean.
/*
* Register the MBean
*/
private void registerMBean() {
LOGGER.info("Registering RDBMSAuditor MBean");
try {
itemNames = new String[] { "Event Id", "Event Time", "Event Principal", "Event Name", "Event Type", "Contexts" };
OpenType<?>[] types = { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, ArrayType.getArrayType(SimpleType.STRING) };
eventType = new CompositeType("AuditEvent", "Direct Auditable Event", itemNames, itemNames, types);
} catch (OpenDataException e) {
LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
return;
}
final Class<?> clazz = this.getClass();
final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
objectNameBuilder.append(":type=").append(clazz.getSimpleName());
objectNameBuilder.append(",name=").append(UUID.randomUUID());
try {
final StandardMBean mbean = new StandardMBean(this, AuditorMBean.class);
final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
} catch (JMException e) {
LOGGER.error("Unable to register the RDBMSAuditors MBean", e);
}
}
use of javax.management.openmbean.CompositeType 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.CompositeType in project jdk8u_jdk by JetBrains.
the class ThreadInfoCompositeData method validateCompositeData.
/** Validate if the input CompositeData has the expected
* CompositeType (i.e. contain all attributes with expected
* names and types).
*/
public static void validateCompositeData(CompositeData cd) {
if (cd == null) {
throw new NullPointerException("Null CompositeData");
}
CompositeType type = cd.getCompositeType();
boolean currentVersion = true;
if (!isTypeMatched(threadInfoCompositeType, type)) {
currentVersion = false;
// check if cd is an older version
if (!isTypeMatched(threadInfoV5CompositeType, type)) {
throw new IllegalArgumentException("Unexpected composite type for ThreadInfo");
}
}
CompositeData[] stackTraceData = (CompositeData[]) cd.get(STACK_TRACE);
if (stackTraceData == null) {
throw new IllegalArgumentException("StackTraceElement[] is missing");
}
if (stackTraceData.length > 0) {
StackTraceElementCompositeData.validateCompositeData(stackTraceData[0]);
}
// validate v6 attributes
if (currentVersion) {
CompositeData li = (CompositeData) cd.get(LOCK_INFO);
if (li != null) {
if (!isTypeMatched(lockInfoCompositeType, li.getCompositeType())) {
throw new IllegalArgumentException("Unexpected composite type for \"" + LOCK_INFO + "\" attribute.");
}
}
CompositeData[] lms = (CompositeData[]) cd.get(LOCKED_MONITORS);
if (lms == null) {
throw new IllegalArgumentException("MonitorInfo[] is null");
}
if (lms.length > 0) {
MonitorInfoCompositeData.validateCompositeData(lms[0]);
}
CompositeData[] lsyncs = (CompositeData[]) cd.get(LOCKED_SYNCS);
if (lsyncs == null) {
throw new IllegalArgumentException("LockInfo[] is null");
}
if (lsyncs.length > 0) {
if (!isTypeMatched(lockInfoCompositeType, lsyncs[0].getCompositeType())) {
throw new IllegalArgumentException("Unexpected composite type for \"" + LOCKED_SYNCS + "\" attribute.");
}
}
}
}
Aggregations