Search in sources :

Example 11 with CompositeData

use of javax.management.openmbean.CompositeData in project camel by apache.

the class ManagedTransformerRegistryTest method testManageTransformerRegistry.

public void testManageTransformerRegistry() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"), null);
    List<ObjectName> list = new ArrayList<ObjectName>(set);
    ObjectName on = null;
    for (ObjectName name : list) {
        if (name.getCanonicalName().contains("DefaultTransformerRegistry")) {
            on = name;
            break;
        }
    }
    assertNotNull("Should have found TransformerRegistry", on);
    Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumCacheSize");
    assertEquals(1000, max.intValue());
    Integer current = (Integer) mbeanServer.getAttribute(on, "Size");
    assertEquals(3, current.intValue());
    current = (Integer) mbeanServer.getAttribute(on, "StaticSize");
    assertEquals(0, current.intValue());
    current = (Integer) mbeanServer.getAttribute(on, "DynamicSize");
    assertEquals(3, current.intValue());
    String source = (String) mbeanServer.getAttribute(on, "Source");
    assertTrue(source.startsWith("TransformerRegistry"));
    assertTrue(source.endsWith("capacity: 1000"));
    TabularData data = (TabularData) mbeanServer.invoke(on, "listTransformers", null, null);
    for (Object row : data.values()) {
        CompositeData composite = (CompositeData) row;
        String scheme = (String) composite.get("scheme");
        String from = (String) composite.get("from");
        String to = (String) composite.get("to");
        String description = (String) composite.get("description");
        boolean isStatic = (boolean) composite.get("static");
        boolean isDynamic = (boolean) composite.get("dynamic");
        LOG.info("[{}][{}][{}][{}][{}][{}]", scheme, from, to, isStatic, isDynamic, description);
        if (description.startsWith("ProcessorTransformer")) {
            assertEquals(null, scheme);
            assertEquals("xml:foo", from);
            assertEquals("json:bar", to);
        } else if (description.startsWith("DataFormatTransformer")) {
            assertEquals(null, scheme);
            assertEquals("java:" + ManagedTransformerRegistryTest.class.getName(), from);
            assertEquals("xml:test", to);
        } else if (description.startsWith("MyTransformer")) {
            assertEquals("custom", scheme);
            assertEquals(null, from);
            assertEquals(null, to);
        } else {
            fail("Unexpected transformer:" + description);
        }
    }
    assertEquals(3, data.size());
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 12 with CompositeData

use of javax.management.openmbean.CompositeData in project camel by apache.

the class ManagedValidatorRegistryTest method testManageValidatorRegistry.

public void testManageValidatorRegistry() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"), null);
    List<ObjectName> list = new ArrayList<ObjectName>(set);
    ObjectName on = null;
    for (ObjectName name : list) {
        if (name.getCanonicalName().contains("DefaultValidatorRegistry")) {
            on = name;
            break;
        }
    }
    assertNotNull("Should have found ValidatorRegistry", on);
    Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumCacheSize");
    assertEquals(1000, max.intValue());
    Integer current = (Integer) mbeanServer.getAttribute(on, "Size");
    assertEquals(3, current.intValue());
    current = (Integer) mbeanServer.getAttribute(on, "StaticSize");
    assertEquals(0, current.intValue());
    current = (Integer) mbeanServer.getAttribute(on, "DynamicSize");
    assertEquals(3, current.intValue());
    String source = (String) mbeanServer.getAttribute(on, "Source");
    assertTrue(source.startsWith("ValidatorRegistry"));
    assertTrue(source.endsWith("capacity: 1000"));
    TabularData data = (TabularData) mbeanServer.invoke(on, "listValidators", null, null);
    for (Object row : data.values()) {
        CompositeData composite = (CompositeData) row;
        String type = (String) composite.get("type");
        String description = (String) composite.get("description");
        boolean isStatic = (boolean) composite.get("static");
        boolean isDynamic = (boolean) composite.get("dynamic");
        LOG.info("[{}][{}][{}][{}]", type, isStatic, isDynamic, description);
        if (description.startsWith("ProcessorValidator")) {
            if (description.contains("direct://transformer")) {
                assertEquals("xml:foo", type);
            } else if (description.contains("validate(simple{${body}} is not null")) {
                assertEquals("json:test", type);
            } else {
                fail("Unexpected validator:" + description);
            }
        } else if (description.startsWith("MyValidator")) {
            assertEquals("custom", type);
        } else {
            fail("Unexpected validator:" + description);
        }
    }
    assertEquals(3, data.size());
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 13 with CompositeData

use of javax.management.openmbean.CompositeData in project hadoop by apache.

the class JMXJsonServlet method writeObject.

private void writeObject(JsonGenerator jg, Object value) throws IOException {
    if (value == null) {
        jg.writeNull();
    } else {
        Class<?> c = value.getClass();
        if (c.isArray()) {
            jg.writeStartArray();
            int len = Array.getLength(value);
            for (int j = 0; j < len; j++) {
                Object item = Array.get(value, j);
                writeObject(jg, item);
            }
            jg.writeEndArray();
        } else if (value instanceof Number) {
            Number n = (Number) value;
            jg.writeNumber(n.toString());
        } else if (value instanceof Boolean) {
            Boolean b = (Boolean) value;
            jg.writeBoolean(b);
        } else if (value instanceof CompositeData) {
            CompositeData cds = (CompositeData) value;
            CompositeType comp = cds.getCompositeType();
            Set<String> keys = comp.keySet();
            jg.writeStartObject();
            for (String key : keys) {
                writeAttribute(jg, key, cds.get(key));
            }
            jg.writeEndObject();
        } else if (value instanceof TabularData) {
            TabularData tds = (TabularData) value;
            jg.writeStartArray();
            for (Object entry : tds.values()) {
                writeObject(jg, entry);
            }
            jg.writeEndArray();
        } else {
            jg.writeString(value.toString());
        }
    }
}
Also used : Set(java.util.Set) CompositeData(javax.management.openmbean.CompositeData) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 14 with CompositeData

use of javax.management.openmbean.CompositeData in project hbase by apache.

the class JSONBean method writeObject.

private static void writeObject(final JsonGenerator jg, final boolean description, Object value) throws IOException {
    if (value == null) {
        jg.writeNull();
    } else {
        Class<?> c = value.getClass();
        if (c.isArray()) {
            jg.writeStartArray();
            int len = Array.getLength(value);
            for (int j = 0; j < len; j++) {
                Object item = Array.get(value, j);
                writeObject(jg, description, item);
            }
            jg.writeEndArray();
        } else if (value instanceof Number) {
            Number n = (Number) value;
            jg.writeNumber(n.toString());
        } else if (value instanceof Boolean) {
            Boolean b = (Boolean) value;
            jg.writeBoolean(b);
        } else if (value instanceof CompositeData) {
            CompositeData cds = (CompositeData) value;
            CompositeType comp = cds.getCompositeType();
            Set<String> keys = comp.keySet();
            jg.writeStartObject();
            for (String key : keys) {
                writeAttribute(jg, key, null, cds.get(key));
            }
            jg.writeEndObject();
        } else if (value instanceof TabularData) {
            TabularData tds = (TabularData) value;
            jg.writeStartArray();
            for (Object entry : tds.values()) {
                writeObject(jg, description, entry);
            }
            jg.writeEndArray();
        } else {
            jg.writeString(value.toString());
        }
    }
}
Also used : Set(java.util.Set) CompositeData(javax.management.openmbean.CompositeData) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 15 with CompositeData

use of javax.management.openmbean.CompositeData in project hive by apache.

the class JMXJsonServlet method writeObject.

private void writeObject(JsonGenerator jg, Object value) throws IOException {
    if (value == null) {
        jg.writeNull();
    } else {
        Class<?> c = value.getClass();
        if (c.isArray()) {
            jg.writeStartArray();
            int len = Array.getLength(value);
            for (int j = 0; j < len; j++) {
                Object item = Array.get(value, j);
                writeObject(jg, item);
            }
            jg.writeEndArray();
        } else if (value instanceof Number) {
            Number n = (Number) value;
            jg.writeNumber(n.toString());
        } else if (value instanceof Boolean) {
            Boolean b = (Boolean) value;
            jg.writeBoolean(b);
        } else if (value instanceof CompositeData) {
            CompositeData cds = (CompositeData) value;
            CompositeType comp = cds.getCompositeType();
            Set<String> keys = comp.keySet();
            jg.writeStartObject();
            for (String key : keys) {
                writeAttribute(jg, key, cds.get(key));
            }
            jg.writeEndObject();
        } else if (value instanceof TabularData) {
            TabularData tds = (TabularData) value;
            jg.writeStartArray();
            for (Object entry : tds.values()) {
                writeObject(jg, entry);
            }
            jg.writeEndArray();
        } else {
            jg.writeString(value.toString());
        }
    }
}
Also used : Set(java.util.Set) CompositeData(javax.management.openmbean.CompositeData) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Aggregations

CompositeData (javax.management.openmbean.CompositeData)229 TabularData (javax.management.openmbean.TabularData)91 Test (org.junit.Test)73 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)51 CompositeType (javax.management.openmbean.CompositeType)50 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)27 Map (java.util.Map)27 Bundle (org.osgi.framework.Bundle)24 ObjectName (javax.management.ObjectName)21 OpenDataException (javax.management.openmbean.OpenDataException)18 IOException (java.io.IOException)17 Collection (java.util.Collection)16 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)16 AuditEvent (org.nhindirect.common.audit.AuditEvent)15 TabularType (javax.management.openmbean.TabularType)13 MBeanServer (javax.management.MBeanServer)12 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)11 MBeanException (javax.management.MBeanException)8