Search in sources :

Example 61 with CompositeType

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)))) })));
}
Also used : MBeanInfo(javax.management.MBeanInfo) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) CompositeType(javax.management.openmbean.CompositeType) Test(org.junit.Test)

Example 62 with CompositeType

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);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) StandardMBean(javax.management.StandardMBean) JMException(javax.management.JMException) CompositeType(javax.management.openmbean.CompositeType) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 63 with CompositeType

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);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) StandardMBean(javax.management.StandardMBean) JMException(javax.management.JMException) CompositeType(javax.management.openmbean.CompositeType) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 64 with CompositeType

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);
}
Also used : OpenType(javax.management.openmbean.OpenType) Method(java.lang.reflect.Method) GenericArrayType(java.lang.reflect.GenericArrayType) SimpleType(javax.management.openmbean.SimpleType) ArrayType(javax.management.openmbean.ArrayType) CompositeType(javax.management.openmbean.CompositeType) ElementType(java.lang.annotation.ElementType) OpenType(javax.management.openmbean.OpenType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) TabularType(javax.management.openmbean.TabularType) OpenDataException(javax.management.openmbean.OpenDataException) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) SortedMap(java.util.SortedMap) CompositeType(javax.management.openmbean.CompositeType)

Example 65 with CompositeType

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.");
            }
        }
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

CompositeType (javax.management.openmbean.CompositeType)82 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)55 CompositeData (javax.management.openmbean.CompositeData)50 TabularDataSupport (javax.management.openmbean.TabularDataSupport)50 TabularData (javax.management.openmbean.TabularData)47 TabularType (javax.management.openmbean.TabularType)27 OpenType (javax.management.openmbean.OpenType)23 OpenDataException (javax.management.openmbean.OpenDataException)22 Map (java.util.Map)20 ObjectName (javax.management.ObjectName)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 MBeanServer (javax.management.MBeanServer)6 ArrayType (javax.management.openmbean.ArrayType)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 MBeanException (javax.management.MBeanException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3