Search in sources :

Example 1 with OpenDataException

use of javax.management.openmbean.OpenDataException 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 2 with OpenDataException

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

the class ArrayTypeTest method main.

public static void main(String[] args) throws Exception {
    System.out.println("\nTest that Open MBeans support arrays of primitive types.");
    int index = 0;
    int error = 0;
    //
    // Constructor tests
    //
    System.out.println("\n>>> Constructor tests");
    System.out.println("\nArrayType<String[][]> a1 = new ArrayType<String[][]>(2, SimpleType.STRING)");
    ArrayType<String[][]> a1 = new ArrayType<String[][]>(2, SimpleType.STRING);
    printArrayType(a1);
    error += checkResult(index++, a1);
    System.out.println("\nArrayType<int[]> a2 = new ArrayType<int[]>(SimpleType.INTEGER, true)");
    ArrayType<int[]> a2 = new ArrayType<int[]>(SimpleType.INTEGER, true);
    printArrayType(a2);
    error += checkResult(index++, a2);
    System.out.println("\nArrayType<Integer[]> a3 = new ArrayType<Integer[]>(SimpleType.INTEGER, false)");
    ArrayType<Integer[]> a3 = new ArrayType<Integer[]>(SimpleType.INTEGER, false);
    printArrayType(a3);
    error += checkResult(index++, a3);
    System.out.println("\nArrayType<int[][][][]> a4 = new ArrayType<int[][][][]>(3, a2)");
    ArrayType<int[][][][]> a4 = new ArrayType<int[][][][]>(3, a2);
    printArrayType(a4);
    error += checkResult(index++, a4);
    System.out.println("\nArrayType<Integer[][][][]> a5 = new ArrayType<Integer[][][][]>(3, a3)");
    ArrayType<Integer[][][][]> a5 = new ArrayType<Integer[][][][]>(3, a3);
    printArrayType(a5);
    error += checkResult(index++, a5);
    System.out.println("\nArrayType<String[]> a6 = new ArrayType<String[]>(SimpleType.STRING, false)");
    ArrayType<String[]> a6 = new ArrayType<String[]>(SimpleType.STRING, false);
    printArrayType(a6);
    error += checkResult(index++, a6);
    System.out.println("\nArrayType<String[]> a7 = new ArrayType<String[]>(SimpleType.STRING, true)");
    // skip this dummy entry in the toStringResult array
    index++;
    try {
        ArrayType<String[]> a7 = new ArrayType<String[]>(SimpleType.STRING, true);
        System.out.println("\tDid not get expected OpenDataException!");
        System.out.println("Test failed!");
        error++;
    } catch (OpenDataException e) {
        System.out.println("\tGot expected OpenDataException: " + e);
        System.out.println("Test passed!");
    }
    //
    // Factory tests
    //
    System.out.println("\n>>> Factory tests");
    System.out.println("\nArrayType<Integer[]> a8 = ArrayType.getArrayType(SimpleType.INTEGER)");
    ArrayType<Integer[]> a8 = ArrayType.getArrayType(SimpleType.INTEGER);
    printArrayType(a8);
    error += checkResult(index++, a8);
    System.out.println("\nArrayType<Integer[][]> a9 = ArrayType.getArrayType(a8)");
    ArrayType<Integer[][]> a9 = ArrayType.getArrayType(a8);
    printArrayType(a9);
    error += checkResult(index++, a9);
    System.out.println("\nArrayType<int[][]> a10 = ArrayType.getPrimitiveArrayType(int[][].class)");
    ArrayType<int[][]> a10 = ArrayType.getPrimitiveArrayType(int[][].class);
    printArrayType(a10);
    error += checkResult(index++, a10);
    System.out.println("\nArrayType<int[][][]> a11 = ArrayType.getArrayType(a10)");
    ArrayType<int[][][]> a11 = ArrayType.getArrayType(a10);
    printArrayType(a11);
    error += checkResult(index++, a11);
    System.out.println("\nArrayType<float[]> a12 = ArrayType.getPrimitiveArrayType(float[].class)");
    ArrayType<float[]> a12 = ArrayType.getPrimitiveArrayType(float[].class);
    printArrayType(a12);
    error += checkResult(index++, a12);
    System.out.println("\nArrayType<float[][]> a13 = ArrayType.getArrayType(a12)");
    ArrayType<float[][]> a13 = ArrayType.getArrayType(a12);
    printArrayType(a13);
    error += checkResult(index++, a13);
    System.out.println("\nArrayType<ObjectName[]> a14 = ArrayType.getArrayType(SimpleType.OBJECTNAME)");
    ArrayType<ObjectName[]> a14 = ArrayType.getArrayType(SimpleType.OBJECTNAME);
    printArrayType(a14);
    error += checkResult(index++, a14);
    System.out.println("\nArrayType<ObjectName[][]> a15 = ArrayType.getArrayType(a14)");
    ArrayType<ObjectName[][]> a15 = ArrayType.getArrayType(a14);
    printArrayType(a15);
    error += checkResult(index++, a15);
    System.out.println("\nArrayType<String[][][]> a16 = new ArrayType<String[][][]>(3, SimpleType.STRING)");
    ArrayType<String[][][]> a16 = new ArrayType<String[][][]>(3, SimpleType.STRING);
    printArrayType(a16);
    error += checkResult(index++, a16);
    System.out.println("\nArrayType<String[]> a17 = new ArrayType<String[]>(1, SimpleType.STRING)");
    System.out.println("ArrayType<String[][]> a18 = new ArrayType<String[][]>(1, a17)");
    System.out.println("ArrayType<String[][][]> a19 = new ArrayType<String[][][]>(1, a18)");
    ArrayType<String[]> a17 = new ArrayType<String[]>(1, SimpleType.STRING);
    ArrayType<String[][]> a18 = new ArrayType<String[][]>(1, a17);
    ArrayType<String[][][]> a19 = new ArrayType<String[][][]>(1, a18);
    printArrayType(a19);
    error += checkResult(index++, a19);
    //
    // Serialization tests
    //
    System.out.println("\n>>> Serialization tests\n");
    ArrayType<int[]> i1 = ArrayType.getPrimitiveArrayType(int[].class);
    ArrayType<int[]> i2 = null;
    ArrayType<boolean[][]> b1 = ArrayType.getPrimitiveArrayType(boolean[][].class);
    ArrayType<boolean[][]> b2 = null;
    ArrayType<Long[]> l1 = ArrayType.getArrayType(SimpleType.LONG);
    ArrayType<Long[]> l2 = null;
    ArrayType<Double[]> d1 = ArrayType.getArrayType(SimpleType.DOUBLE);
    ArrayType<Double[]> d2 = null;
    // serialize the objects
    try {
        FileOutputStream fo = new FileOutputStream("serial.tmp");
        ObjectOutputStream so = new ObjectOutputStream(fo);
        System.out.println("Serialize ArrayType<int[]> i1 = ArrayType.getPrimitiveArrayType(int[].class)");
        so.writeObject(i1);
        System.out.println("Serialize ArrayType<boolean[][]> b1 = ArrayType.getPrimitiveArrayType(boolean[][].class)");
        so.writeObject(b1);
        System.out.println("Serialize ArrayType<Long[]> l1 = ArrayType.getArrayType(SimpleType.LONG)");
        so.writeObject(l1);
        System.out.println("Serialize ArrayType<Double[]> d1 = ArrayType.getArrayType(SimpleType.DOUBLE)");
        so.writeObject(d1);
        so.flush();
    } catch (Exception e) {
        System.out.println(e);
        System.exit(1);
    }
    // deserialize the objects
    try {
        FileInputStream fi = new FileInputStream("serial.tmp");
        ObjectInputStream si = new ObjectInputStream(fi);
        System.out.println("Deserialize ArrayType<int[]> i1 = ArrayType.getPrimitiveArrayType(int[].class)");
        i2 = (ArrayType<int[]>) si.readObject();
        System.out.println("Deserialize ArrayType<boolean[][]> b1 = ArrayType.getPrimitiveArrayType(boolean[][].class)");
        b2 = (ArrayType<boolean[][]>) si.readObject();
        System.out.println("Deserialize ArrayType<Long[]> l1 = ArrayType.getArrayType(SimpleType.LONG)");
        l2 = (ArrayType<Long[]>) si.readObject();
        System.out.println("Deserialize ArrayType<Double[]> d1 = ArrayType.getArrayType(SimpleType.DOUBLE)");
        d2 = (ArrayType<Double[]>) si.readObject();
    } catch (Exception e) {
        System.out.println(e);
        System.exit(1);
    }
    if (i1.toString().equals(toStringResult[index++]) && i1.toString().equals(i2.toString())) {
        System.out.println("Test passed for ArrayType<int[]> i1 = ArrayType.getPrimitiveArrayType(int[].class)");
    } else {
        System.out.println("Test failed for ArrayType<int[]> i1 = ArrayType.getPrimitiveArrayType(int[].class)");
        error++;
    }
    if (b1.toString().equals(toStringResult[index++]) && b1.toString().equals(b2.toString())) {
        System.out.println("Test passed for ArrayType<boolean[][]> b1 = ArrayType.getPrimitiveArrayType(boolean[][].class)");
    } else {
        System.out.println("Test failed for ArrayType<boolean[][]> b1 = ArrayType.getPrimitiveArrayType(boolean[][].class)");
        error++;
    }
    if (l1.toString().equals(toStringResult[index++]) && l1.toString().equals(l2.toString())) {
        System.out.println("Test passed for ArrayType<Long[]> l1 = ArrayType.getArrayType(SimpleType.LONG)");
    } else {
        System.out.println("Test failed for ArrayType<Long[]> l1 = ArrayType.getArrayType(SimpleType.LONG)");
        error++;
    }
    if (d1.toString().equals(toStringResult[index++]) && d1.toString().equals(d2.toString())) {
        System.out.println("Test passed for ArrayType<Double[]> d1 = ArrayType.getArrayType(SimpleType.DOUBLE)");
    } else {
        System.out.println("Test failed for ArrayType<Double[]> d1 = ArrayType.getArrayType(SimpleType.DOUBLE)");
        error++;
    }
    //
    // Test getters
    //
    System.out.println("\n>>> Getter tests");
    System.out.println("\nArrayType<Integer[][]> g1 = new ArrayType<Integer[][]>(2, SimpleType.INTEGER)");
    ArrayType<Integer[][]> g1 = new ArrayType<Integer[][]>(2, SimpleType.INTEGER);
    printArrayType(g1);
    error += checkGetters(g1, "[[Ljava.lang.Integer;", "2-dimension array of java.lang.Integer", "[[Ljava.lang.Integer;", true, false, 2);
    System.out.println("\nArrayType<int[][]> g2 = ArrayType.getPrimitiveArrayType(int[][].class)");
    ArrayType<int[][]> g2 = ArrayType.getPrimitiveArrayType(int[][].class);
    printArrayType(g2);
    error += checkGetters(g2, "[[I", "2-dimension array of int", "[[I", true, true, 2);
    if (error > 0) {
        final String msg = "\nTest FAILED! Got " + error + " error(s)";
        System.out.println(msg);
        throw new IllegalArgumentException(msg);
    } else {
        System.out.println("\nTest PASSED!");
    }
}
Also used : ObjectOutputStream(java.io.ObjectOutputStream) ArrayType(javax.management.openmbean.ArrayType) OpenDataException(javax.management.openmbean.OpenDataException) OpenDataException(javax.management.openmbean.OpenDataException) FileInputStream(java.io.FileInputStream) ObjectName(javax.management.ObjectName) FileOutputStream(java.io.FileOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with OpenDataException

use of javax.management.openmbean.OpenDataException in project jackrabbit-oak by apache.

the class ConsolidatedListenerMBeanImpl method getObserversStats.

@Override
public TabularData getObserversStats() {
    TabularDataSupport tds;
    try {
        int id = 0;
        TabularType tt = new TabularType(ObserverStatsData.class.getName(), "Consolidated Observer Stats", ObserverStatsData.TYPE, new String[] { "index" });
        tds = new TabularDataSupport(tt);
        for (BackgroundObserverMBean o : collectNonJcrObservers()) {
            tds.put(new ObserverStatsData(++id, o).toCompositeData());
        }
    } catch (OpenDataException e) {
        throw new IllegalStateException(e);
    }
    return tds;
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) BackgroundObserverMBean(org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean)

Example 4 with OpenDataException

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

the class JmxReference method createReferenceType.

private static CompositeType createReferenceType() {
    try {
        String description = "This type encapsulates Scr references";
        String[] itemNames = ScrServiceMBean.REFERENCE;
        OpenType[] itemTypes = new OpenType[itemNames.length];
        String[] itemDescriptions = new String[itemNames.length];
        itemTypes[0] = SimpleType.STRING;
        itemTypes[1] = SimpleType.BOOLEAN;
        itemTypes[2] = SimpleType.STRING;
        itemTypes[3] = SimpleType.STRING;
        itemTypes[4] = SimpleType.STRING;
        itemTypes[5] = new ArrayType(1, SimpleType.STRING);
        itemDescriptions[0] = "The name of the reference";
        itemDescriptions[1] = "The state of the reference";
        itemDescriptions[2] = "The cardinality of the reference";
        itemDescriptions[3] = "The availability of the reference";
        itemDescriptions[4] = "The policy of the reference";
        itemDescriptions[5] = "The bound services";
        return new CompositeType("Reference", description, itemNames, itemDescriptions, itemTypes);
    } catch (OpenDataException e) {
        throw new IllegalStateException("Unable to build reference type", e);
    }
}
Also used : ArrayType(javax.management.openmbean.ArrayType) OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) CompositeType(javax.management.openmbean.CompositeType)

Example 5 with OpenDataException

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

the class PackagesMBeanImpl method getImports.

@Override
public TabularData getImports() {
    try {
        String[] names = new String[] { "PackageName", "Filter", "Optional", "ID", "Bundle Name", "Resolvable" };
        CompositeType bundleType = new CompositeType("PackageImports", "Imported packages", names, names, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.LONG, SimpleType.STRING, SimpleType.BOOLEAN });
        TabularType tableType = new TabularType("PackageImports", "Imported packages", bundleType, new String[] { "Filter", "ID" });
        TabularData table = new TabularDataSupport(tableType);
        List<PackageRequirement> imports = packageService.getImports();
        for (PackageRequirement req : imports) {
            Object[] data = new Object[] { req.getPackageName(), req.getFilter(), req.isOptional(), req.getBundle().getBundleId(), req.getBundle().getSymbolicName(), req.isResolveable() };
            CompositeData comp = new CompositeDataSupport(bundleType, names, data);
            try {
                table.put(comp);
            } catch (KeyAlreadyExistsException e) {
                throw new RuntimeException("Id: " + req.getBundle().getBundleId() + ", filter: " + req.getFilter(), e);
            }
        }
        return table;
    } catch (RuntimeException e) {
        // To avoid the exception gets swallowed by jmx
        LOGGER.error(e.getMessage(), e);
        throw e;
    } catch (OpenDataException e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : PackageRequirement(org.apache.karaf.packages.core.PackageRequirement) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) KeyAlreadyExistsException(javax.management.openmbean.KeyAlreadyExistsException) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

OpenDataException (javax.management.openmbean.OpenDataException)136 CompositeType (javax.management.openmbean.CompositeType)91 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)67 CompositeData (javax.management.openmbean.CompositeData)54 OpenType (javax.management.openmbean.OpenType)51 TabularDataSupport (javax.management.openmbean.TabularDataSupport)30 TabularType (javax.management.openmbean.TabularType)30 HashMap (java.util.HashMap)13 Map (java.util.Map)11 TabularData (javax.management.openmbean.TabularData)10 ObjectName (javax.management.ObjectName)8 ArrayType (javax.management.openmbean.ArrayType)8 Type (java.lang.reflect.Type)5 ArrayList (java.util.ArrayList)5 Method (java.lang.reflect.Method)4 Comparator (java.util.Comparator)4 MBeanServer (javax.management.MBeanServer)4 SimpleType (javax.management.openmbean.SimpleType)4 IOException (java.io.IOException)3 InvalidObjectException (java.io.InvalidObjectException)3