Search in sources :

Example 26 with TabularType

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

the class TypeNameTest method main.

public static void main(String[] args) throws Exception {
    TestMXBean testImpl = (TestMXBean) Proxy.newProxyInstance(TestMXBean.class.getClassLoader(), new Class<?>[] { TestMXBean.class }, nullIH);
    Object mxbean = new StandardMBean(testImpl, TestMXBean.class, true);
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    mbs.registerMBean(mxbean, name);
    MBeanInfo mbi = mbs.getMBeanInfo(name);
    MBeanAttributeInfo[] mbais = mbi.getAttributes();
    boolean sawTabular = false;
    for (MBeanAttributeInfo mbai : mbais) {
        String attrName = mbai.getName();
        String attrTypeName = (String) mbai.getDescriptor().getFieldValue("originalType");
        String fieldName = attrName + "Name";
        Field nameField = TestMXBean.class.getField(fieldName);
        String expectedTypeName = (String) nameField.get(null);
        if (expectedTypeName.equals(attrTypeName)) {
            System.out.println("OK: " + attrName + ": " + attrTypeName);
        } else {
            fail("For attribute " + attrName + " expected type name \"" + expectedTypeName + "\", found type name \"" + attrTypeName + "\"");
        }
        if (mbai.getType().equals(TabularData.class.getName())) {
            sawTabular = true;
            TabularType tt = (TabularType) mbai.getDescriptor().getFieldValue("openType");
            if (tt.getTypeName().equals(attrTypeName)) {
                System.out.println("OK: TabularType name for " + attrName);
            } else {
                fail("For attribute " + attrName + " expected TabularType " + "name \"" + attrTypeName + "\", found \"" + tt.getTypeName());
            }
        }
    }
    if (!sawTabular)
        fail("Test bug: did not test TabularType name");
    if (failure == null)
        System.out.println("TEST PASSED");
    else
        throw new Exception("TEST FAILED: " + failure);
}
Also used : MBeanInfo(javax.management.MBeanInfo) StandardMBean(javax.management.StandardMBean) TabularType(javax.management.openmbean.TabularType) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Field(java.lang.reflect.Field) MBeanServer(javax.management.MBeanServer)

Example 27 with TabularType

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

the class BundlesMBeanImpl method getDiag.

@Override
public TabularData getDiag() throws MBeanException {
    try {
        CompositeType diagType = new CompositeType("Diag", "OSGi Bundle Diag", new String[] { "Name", "Status", "Diag" }, new String[] { "Bundle Name", "Current Status", "Diagnostic" }, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
        TabularType tableType = new TabularType("Diagnostics", "Tables of all bundles diagnostic", diagType, new String[] { "Name" });
        TabularData table = new TabularDataSupport(tableType);
        Bundle[] bundles = bundleContext.getBundles();
        for (Bundle bundle : bundles) {
            BundleInfo bundleInfo = bundleService.getInfo(bundle);
            String name = ShellUtil.getBundleName(bundle);
            String status = bundleInfo.getState().toString();
            String diag = bundleService.getDiag(bundle);
            CompositeData data = new CompositeDataSupport(diagType, new String[] { "Name", "Status", "Diag" }, new Object[] { name, status, diag });
            table.put(data);
        }
        return table;
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : BundleInfo(org.apache.karaf.bundle.core.BundleInfo) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Bundle(org.osgi.framework.Bundle) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 28 with TabularType

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

the class BundlesMBeanImpl method getBundles.

public TabularData getBundles() throws MBeanException {
    try {
        CompositeType bundleType = new CompositeType("Bundle", "OSGi Bundle", new String[] { "ID", "Name", "Symbolic Name", "Version", "Start Level", "State", "Update Location" }, new String[] { "ID of the Bundle", "Name of the Bundle", "Symbolic Name of the Bundle", "Version of the Bundle", "Start Level of the Bundle", "Current State of the Bundle", "Update location of the Bundle" }, new OpenType[] { SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING });
        TabularType tableType = new TabularType("Bundles", "Tables of all bundles", bundleType, new String[] { "ID" });
        TabularData table = new TabularDataSupport(tableType);
        Bundle[] bundles = bundleContext.getBundles();
        for (Bundle bundle : bundles) {
            try {
                BundleInfo info = bundleService.getInfo(bundle);
                String bundleStateString = info.getState().toString();
                CompositeData data = new CompositeDataSupport(bundleType, new String[] { "ID", "Name", "Symbolic Name", "Version", "Start Level", "State", "Update Location" }, new Object[] { info.getBundleId(), info.getName(), info.getSymbolicName(), info.getVersion(), info.getStartLevel(), bundleStateString, info.getUpdateLocation() });
                table.put(data);
            } catch (Exception e) {
                LOG.error(e.getMessage(), e);
            }
        }
        return table;
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : BundleInfo(org.apache.karaf.bundle.core.BundleInfo) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Bundle(org.osgi.framework.Bundle) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 29 with TabularType

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

the class PackagesMBeanImpl method getExports.

public TabularData getExports() {
    try {
        String[] names = new String[] { "Name", "Version", "ID", "Bundle Name" };
        CompositeType bundleType = new CompositeType("PackageExport", "Exported packages", names, new String[] { "Package name", "Version of the Package", "ID of the Bundle", "Bundle symbolic name" }, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.STRING });
        TabularType tableType = new TabularType("PackageExports", "Exported packages", bundleType, new String[] { "Name", "Version", "ID" });
        TabularData table = new TabularDataSupport(tableType);
        List<PackageVersion> exports = packageService.getExports();
        for (PackageVersion export : exports) {
            for (Bundle bundle : export.getBundles()) {
                Object[] data = new Object[] { export.getPackageName(), export.getVersion().toString(), bundle.getBundleId(), bundle.getSymbolicName() };
                CompositeData comp = new CompositeDataSupport(bundleType, names, data);
                LOGGER.debug("Adding CompositeDataSupport {}", comp);
                table.put(comp);
            }
        }
        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 : Bundle(org.osgi.framework.Bundle) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) PackageVersion(org.apache.karaf.packages.core.PackageVersion) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 30 with TabularType

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

the class ObrMBeanImpl method getBundles.

public TabularData getBundles() throws MBeanException {
    try {
        CompositeType bundleType = new CompositeType("OBR Resource", "Bundle available in the OBR", new String[] { "presentationname", "symbolicname", "version" }, new String[] { "Presentation Name", "Symbolic Name", "Version" }, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
        TabularType tableType = new TabularType("OBR Resources", "Table of all resources/bundles available in the OBR", bundleType, new String[] { "symbolicname", "version" });
        TabularData table = new TabularDataSupport(tableType);
        Resource[] resources = repositoryAdmin.discoverResources("(|(presentationname=*)(symbolicname=*))");
        for (Resource resource : resources) {
            try {
                CompositeData data = new CompositeDataSupport(bundleType, new String[] { "presentationname", "symbolicname", "version" }, new Object[] { resource.getPresentationName(), resource.getSymbolicName(), resource.getVersion().toString() });
                table.put(data);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return table;
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Resource(org.apache.felix.bundlerepository.Resource) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MBeanException(javax.management.MBeanException) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Aggregations

TabularType (javax.management.openmbean.TabularType)42 TabularDataSupport (javax.management.openmbean.TabularDataSupport)37 CompositeType (javax.management.openmbean.CompositeType)26 OpenDataException (javax.management.openmbean.OpenDataException)22 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)20 TabularData (javax.management.openmbean.TabularData)18 CompositeData (javax.management.openmbean.CompositeData)14 Map (java.util.Map)8 OpenType (javax.management.openmbean.OpenType)8 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 MBeanException (javax.management.MBeanException)5 ObjectName (javax.management.ObjectName)4 Bundle (org.osgi.framework.Bundle)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 MBeanInfo (javax.management.MBeanInfo)3 Field (java.lang.reflect.Field)2