Search in sources :

Example 1 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project jmxtrans by jmxtrans.

the class JmxResultProcessor method getResult.

/**
	 * Populates the Result objects. This is a recursive function. Query
	 * contains the keys that we want to get the values of.
	 */
private void getResult(Builder<Result> accumulator, String attributeName, CompositeData cds) {
    CompositeType t = cds.getCompositeType();
    Map<String, Object> values = newHashMap();
    Set<String> keys = t.keySet();
    for (String key : keys) {
        Object value = cds.get(key);
        if (value instanceof TabularDataSupport) {
            TabularDataSupport tds = (TabularDataSupport) value;
            processTabularDataSupport(accumulator, attributeName + "." + key, tds);
        // continue because we added tabular contents within above, but need primitives at this level
        } else if (value instanceof CompositeDataSupport) {
            // now recursively go through everything.
            CompositeDataSupport cds2 = (CompositeDataSupport) value;
            getResult(accumulator, attributeName, cds2);
            // because we don't want to add to the list yet.
            return;
        } else {
            values.put(key, value);
        }
    }
    Result r = getNewResultObject(attributeName, values);
    accumulator.add(r);
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 2 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project nhin-d by DirectProject.

the class DNSServer method registerMBean.

/**
	 * Register the MBean
	 */
private void registerMBean(DNSServerSettings settings) {
    String[] itemNames = { "Port", "Bind Address", "Max Request Size", "Max Outstanding Accepts", "Max Active Accepts", "Max Connection Backlog", "Read Buffer Size", "Send Timeout", "Receive Timeout", "Socket Close Timeout" };
    String[] itemDesc = { "Port", "Bind Address", "Max Request Size", "Max Outstanding Accepts", "Max Active Accepts", "Max Connection Backlog", "Read Buffer Size", "Send Timeout", "Receive Timeout", "Socket Close Timeout" };
    OpenType<?>[] types = { SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER };
    Object[] settingsValues = { settings.getPort(), settings.getBindAddress(), settings.getMaxRequestSize(), settings.getMaxOutstandingAccepts(), settings.getMaxActiveRequests(), settings.getMaxConnectionBacklog(), settings.getReadBufferSize(), settings.getSendTimeout(), settings.getReceiveTimeout(), settings.getSocketCloseTimeout() };
    try {
        CompositeType settingsType = new CompositeType(DNSServerSettings.class.getSimpleName(), "DNS server settings.", itemNames, itemDesc, types);
        settingsData = new CompositeDataSupport(settingsType, itemNames, settingsValues);
    } 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, DNSServerMBean.class);
        final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
    } catch (JMException e) {
        LOGGER.error("Unable to register the DNSServer MBean", e);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) StandardMBean(javax.management.StandardMBean) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ObjectName(javax.management.ObjectName) OpenDataException(javax.management.openmbean.OpenDataException) JMException(javax.management.JMException) CompositeType(javax.management.openmbean.CompositeType) MBeanServer(javax.management.MBeanServer)

Example 3 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project jdk8u_jdk by JetBrains.

the class CompositeDataStringTest method main.

public static void main(String[] args) throws Exception {
    CompositeType basicCT = new CompositeType("basicCT", "basic CompositeType", new String[] { "name", "value" }, new String[] { "name", "value" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.INTEGER });
    CompositeType ct = new CompositeType("noddy", "descr", new String[] { "strings", "ints", "cds" }, new String[] { "string array", "int array", "composite data array" }, new OpenType<?>[] { ArrayType.getArrayType(SimpleType.STRING), ArrayType.getPrimitiveArrayType(int[].class), ArrayType.getArrayType(basicCT) });
    CompositeData basicCD1 = new CompositeDataSupport(basicCT, new String[] { "name", "value" }, new Object[] { "ceathar", 4 });
    CompositeData basicCD2 = new CompositeDataSupport(basicCT, new String[] { "name", "value" }, new Object[] { "naoi", 9 });
    CompositeData cd = new CompositeDataSupport(ct, new String[] { "strings", "ints", "cds" }, new Object[] { new String[] { "fred", "jim", "sheila" }, new int[] { 2, 3, 5, 7 }, new CompositeData[] { basicCD1, basicCD2 } });
    String s = cd.toString();
    System.out.println("CompositeDataSupport.toString(): " + s);
    String[] expected = { "fred, jim, sheila", "2, 3, 5, 7", "ceathar", "naoi" };
    boolean ok = true;
    for (String expect : expected) {
        if (s.contains(expect))
            System.out.println("OK: string contains <" + expect + ">");
        else {
            ok = false;
            System.out.println("NOT OK: string does not contain <" + expect + ">");
        }
    }
    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("TEST FAILED: string did not contain expected substrings");
}
Also used : CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 4 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project jdk8u_jdk by JetBrains.

the class TabularDataOrderTest method makeTable.

private static TabularData makeTable() throws OpenDataException {
    TabularData td = new TabularDataSupport(tt);
    for (Map.Entry<String, Integer> entry : stringToValue.entrySet()) {
        CompositeData cd = new CompositeDataSupport(ct, new String[] { "name", "int" }, new Object[] { entry.getKey(), entry.getValue() });
        td.put(cd);
    }
    return td;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TabularData(javax.management.openmbean.TabularData)

Example 5 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project karaf by apache.

the class JMXSecurityTest method testOSGiConfigAdminMBean.

private void testOSGiConfigAdminMBean(MBeanServerConnection connection, ObjectName mbean, String pidPrefix, boolean shouldSucceed, boolean isAdmin) throws Exception {
    String infix = "." + System.currentTimeMillis();
    String suffix = infix + "_" + counter.incrementAndGet();
    String pid = pidPrefix + suffix;
    CompositeType ct = new CompositeType("PROPERTY", "X", new String[] { "Key", "Value", "Type" }, new String[] { "X", "X", "X" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
    TabularType tt = new TabularType("PROPERTIES", "X", ct, new String[] { "Key" });
    TabularDataSupport tds = new TabularDataSupport(tt);
    Map<String, Object> data = new HashMap<>();
    data.put("Key", "foo");
    data.put("Value", "bar");
    data.put("Type", "String");
    CompositeDataSupport cds = new CompositeDataSupport(ct, data);
    tds.put(cds);
    assertJmxInvoke(shouldSucceed, connection, mbean, "update", new Object[] { pid, tds }, new String[] { String.class.getName(), TabularData.class.getName() });
    TabularData td = (TabularData) connection.invoke(mbean, "getProperties", new Object[] { pid }, new String[] { String.class.getName() });
    if (shouldSucceed) {
        assertEquals("bar", td.get(new Object[] { "foo" }).get("Value"));
    }
    String[][] configs = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pid + ")" }, new String[] { String.class.getName() });
    if (shouldSucceed) {
        assertEquals(1, configs.length);
        assertEquals(pid, configs[0][0]);
    }
    assertJmxInvoke(shouldSucceed, connection, mbean, "delete", new Object[] { pid }, new String[] { String.class.getName() });
    TabularDataSupport tds2 = new TabularDataSupport(tt);
    Map<String, Object> data2 = new HashMap<>();
    data2.put("Key", "a.b.c");
    data2.put("Value", "d.e.f");
    data2.put("Type", "String");
    CompositeDataSupport cds2 = new CompositeDataSupport(ct, data2);
    tds2.put(cds2);
    String suffix2 = infix + "_" + counter.incrementAndGet();
    String pid2 = pidPrefix + suffix2;
    String location2 = "mylocation" + System.currentTimeMillis();
    assertJmxInvoke(shouldSucceed, connection, mbean, "updateForLocation", new Object[] { pid2, location2, tds2 }, new String[] { String.class.getName(), String.class.getName(), TabularData.class.getName() });
    TabularData td2 = (TabularData) connection.invoke(mbean, "getPropertiesForLocation", new Object[] { pid2, location2 }, new String[] { String.class.getName(), String.class.getName() });
    if (shouldSucceed) {
        assertEquals("d.e.f", td2.get(new Object[] { "a.b.c" }).get("Value"));
    }
    assertJmxInvoke(shouldSucceed, connection, mbean, "deleteForLocation", new Object[] { pid2, location2 }, new String[] { String.class.getName(), String.class.getName() });
    if (isAdmin) {
        String suffix3 = infix + "_" + counter.incrementAndGet();
        String pid3 = pidPrefix + suffix3;
        TabularDataSupport tds3 = new TabularDataSupport(tt);
        assertJmxInvoke(shouldSucceed, connection, mbean, "update", new Object[] { pid3, tds3 }, new String[] { String.class.getName(), TabularData.class.getName() });
        String[][] configs2 = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() });
        assertEquals(1, configs2.length);
        assertEquals(pid3, configs2[0][0]);
        String location3 = "my.other.location." + System.currentTimeMillis();
        assertJmxInvoke(shouldSucceed, connection, mbean, "setBundleLocation", new Object[] { pid3, location3 }, new String[] { String.class.getName(), String.class.getName() });
        String[][] configs3 = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() });
        assertEquals(1, configs3.length);
        assertEquals(pid3, configs3[0][0]);
        connection.invoke(mbean, "deleteConfigurations", new Object[] { "(service.pid=" + pid3 + ")" }, new String[] { String.class.getName() });
        assertEquals(0, ((String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() })).length);
    }
}
Also used : HashMap(java.util.HashMap) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Aggregations

CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)164 CompositeData (javax.management.openmbean.CompositeData)107 CompositeType (javax.management.openmbean.CompositeType)105 TabularDataSupport (javax.management.openmbean.TabularDataSupport)78 OpenDataException (javax.management.openmbean.OpenDataException)66 TabularData (javax.management.openmbean.TabularData)46 HashMap (java.util.HashMap)36 TabularType (javax.management.openmbean.TabularType)30 Map (java.util.Map)26 OpenType (javax.management.openmbean.OpenType)15 ObjectName (javax.management.ObjectName)12 MBeanServer (javax.management.MBeanServer)8 Test (org.junit.Test)8 IOException (java.io.IOException)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 MBeanException (javax.management.MBeanException)6 JsonArray (javax.json.JsonArray)5 JsonObject (javax.json.JsonObject)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)4