Search in sources :

Example 26 with TabularData

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

the class ManagedSendProcessorTest method testManageSendProcessor.

public void testManageSendProcessor() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(1);
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedMessageCount(0);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
    // should be on route1
    String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
    assertEquals("route1", routeId);
    String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", camelId);
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);
    String destination = (String) mbeanServer.getAttribute(on, "Destination");
    assertEquals("mock://result", destination);
    String pattern = (String) mbeanServer.getAttribute(on, "MessageExchangePattern");
    assertNull(pattern);
    TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(2, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(5, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Sends the message to a static endpoint\""));
    assertTrue(json.contains(" \"uri\": { \"kind\": \"attribute\", \"required\": \"true\", \"type\": \"string\", \"javaType\": \"java.lang.String\"," + " \"deprecated\": \"false\", \"value\": \"mock:result\""));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 27 with TabularData

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

the class ManagedRoundRobinLoadBalancerTest method testManageRoundRobinLoadBalancer.

public void testManageRoundRobinLoadBalancer() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedMessageCount(1);
    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
    template.sendBodyAndHeader("direct:start", "Bye World", "foo", "123");
    assertMockEndpointsSatisfied();
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
    // should be on route1
    String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
    assertEquals("route1", routeId);
    String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", camelId);
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);
    Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
    assertEquals(2, size.intValue());
    String last = (String) mbeanServer.getAttribute(on, "LastChosenProcessorId");
    assertEquals("bar", last);
    TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(2, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(5, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Balances message processing among a number of nodes"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 28 with TabularData

use of javax.management.openmbean.TabularData 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 29 with TabularData

use of javax.management.openmbean.TabularData 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 30 with TabularData

use of javax.management.openmbean.TabularData 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)

Aggregations

TabularData (javax.management.openmbean.TabularData)183 CompositeData (javax.management.openmbean.CompositeData)91 TabularDataSupport (javax.management.openmbean.TabularDataSupport)67 ObjectName (javax.management.ObjectName)54 MBeanServer (javax.management.MBeanServer)50 CompositeType (javax.management.openmbean.CompositeType)47 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)43 Test (org.junit.Test)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)21 HashMap (java.util.HashMap)20 TabularType (javax.management.openmbean.TabularType)17 Bundle (org.osgi.framework.Bundle)17 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)15 Collection (java.util.Collection)13 IOException (java.io.IOException)11 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)9 List (java.util.List)8 ServiceReference (org.osgi.framework.ServiceReference)8