Search in sources :

Example 61 with TabularDataSupport

use of javax.management.openmbean.TabularDataSupport in project druid by alibaba.

the class JdbcStatManager method getDataSourceList.

@Override
public TabularData getDataSourceList() throws JMException {
    CompositeType rowType = getDataSourceCompositeType();
    String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
    TabularType tabularType = new TabularType("DataSourceStat", "DataSourceStat", rowType, indexNames);
    TabularData data = new TabularDataSupport(tabularType);
    {
        final ConcurrentMap<String, DataSourceProxyImpl> dataSources = DruidDriver.getProxyDataSources();
        for (DataSourceProxyImpl dataSource : dataSources.values()) {
            data.put(dataSource.getCompositeData());
        }
    }
    final Set<DruidDataSource> dataSources = DruidDataSourceStatManager.getDruidDataSourceInstances();
    for (DruidDataSource dataSource : dataSources) {
        data.put(dataSource.getCompositeData());
    }
    return data;
}
Also used : DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) ConcurrentMap(java.util.concurrent.ConcurrentMap) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 62 with TabularDataSupport

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

the class MXBeanNotifTest method run.

public void run(Map<String, Object> args) {
    System.out.println("MXBeanNotifTest::run: Start");
    int errorCount = 0;
    try {
        parseArgs(args);
        notifList = new ArrayBlockingQueue<Notification>(numOfNotifications);
        // JMX MbeanServer used inside single VM as if remote.
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        cs.start();
        JMXServiceURL addr = cs.getAddress();
        JMXConnector cc = JMXConnectorFactory.connect(addr);
        MBeanServerConnection mbsc = cc.getMBeanServerConnection();
        // ----
        System.out.println("MXBeanNotifTest::run: Create and register the MBean");
        ObjectName objName = new ObjectName("sqe:type=Basic,protocol=rmi");
        mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
        System.out.println("---- OK\n");
        // ----
        System.out.println("MXBeanNotifTest::run: Add me as notification listener");
        mbsc.addNotificationListener(objName, this, null, null);
        // ----
        System.out.println("MXBeanNotifTest::run: Retrieve the Descriptor" + " that should be in MBeanNotificationInfo");
        TabularData tabData = (TabularData) mbsc.getAttribute(objName, "NotifDescriptorAsMapAtt");
        Map<String, String> descrMap = new HashMap<>();
        for (Iterator<?> it = tabData.values().iterator(); it.hasNext(); ) {
            CompositeData compData = (CompositeData) it.next();
            descrMap.put((String) compData.get("key"), (String) compData.get("value"));
        }
        Descriptor refNotifDescriptor = new ImmutableDescriptor(descrMap);
        System.out.println("---- OK\n");
        // ----
        // Because the MBean holding the targeted attribute is MXBean, we
        // should use for the setAttribute a converted form for the
        // attribute value as described by the MXBean mapping rules.
        // This explains all that lovely stuff for creating a
        // TabularDataSupport.
        //
        // WARNING : the MBeanInfo of the MXBean used on opposite side
        // is computed when the MBean is registered.
        // It means the Descriptor considered for the MBeanNotificationInfo
        // is not the one we set in the lines below, it is too late.
        // However, we check that set is harmless when we check
        // the MBeanNotificationInfo.
        //
        System.out.println("MXBeanNotifTest::run: Set a Map<String, String>" + " attribute");
        String typeName = "java.util.Map<java.lang.String,java.lang.String>";
        String[] keyValue = new String[] { "key", "value" };
        OpenType<?>[] openTypes = new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING };
        CompositeType rowType = new CompositeType(typeName, typeName, keyValue, keyValue, openTypes);
        TabularType tabType = new TabularType(typeName, typeName, rowType, new String[] { "key" });
        TabularDataSupport convertedDescrMap = new TabularDataSupport(tabType);
        for (int i = 0; i < numOfNotifDescriptorElements; i++) {
            Object[] descrValue = { "field" + i, "value" + i };
            CompositeData data = new CompositeDataSupport(rowType, keyValue, descrValue);
            convertedDescrMap.put(data);
        }
        Attribute descrAtt = new Attribute("NotifDescriptorAsMapAtt", convertedDescrMap);
        mbsc.setAttribute(objName, descrAtt);
        System.out.println("---- OK\n");
        // ----
        System.out.println("MXBeanNotifTest::run: Compare the Descriptor from" + " the MBeanNotificationInfo against a reference");
        MBeanInfo mbInfo = mbsc.getMBeanInfo(objName);
        errorCount += checkMBeanInfo(mbInfo, refNotifDescriptor);
        System.out.println("---- DONE\n");
        // ----
        System.out.println("Check isInstanceOf(Basic)");
        if (!mbsc.isInstanceOf(objName, BASIC_MXBEAN_CLASS_NAME)) {
            errorCount++;
            System.out.println("---- ERROR isInstanceOf returned false\n");
        } else {
            System.out.println("---- OK\n");
        }
        // ----
        System.out.println("Check isInstanceOf(BasicMXBean)");
        if (!mbsc.isInstanceOf(objName, BASIC_MXBEAN_INTERFACE_NAME)) {
            errorCount++;
            System.out.println("---- ERROR isInstanceOf returned false\n");
        } else {
            System.out.println("---- OK\n");
        }
        // ----
        System.out.println("MXBeanNotifTest::run: Ask for " + numOfNotifications + " notification(s)");
        Object[] sendNotifParam = new Object[1];
        String[] sendNotifSig = new String[] { "java.lang.String" };
        for (int i = 0; i < numOfNotifications; i++) {
            // Select which type of notification we ask for
            if (i % 2 == 0) {
                sendNotifParam[0] = Basic.NOTIF_TYPE_0;
            } else {
                sendNotifParam[0] = Basic.NOTIF_TYPE_1;
            }
            // Trigger notification emission
            mbsc.invoke(objName, "sendNotification", sendNotifParam, sendNotifSig);
            // Wait for it then check it when it comes early enough
            Notification notif = notifList.poll(timeForNotificationInSeconds, TimeUnit.SECONDS);
            // notifications are delivered with, we prefer to secure it.
            if (i == 0 && notif == null) {
                System.out.println("MXBeanNotifTest::run: Wait extra " + timeForNotificationInSeconds + " second(s) the " + " very first notification");
                notif = notifList.poll(timeForNotificationInSeconds, TimeUnit.SECONDS);
            }
            if (notif == null) {
                errorCount++;
                System.out.println("---- ERROR No notification received" + " within allocated " + timeForNotificationInSeconds + " second(s) !");
            } else {
                errorCount += checkNotification(notif, (String) sendNotifParam[0], Basic.NOTIFICATION_MESSAGE, objName);
            }
        }
        int toc = 0;
        while (notifList.size() < 2 && toc < 10) {
            Thread.sleep(499);
            toc++;
        }
        System.out.println("---- DONE\n");
    } catch (Exception e) {
        Utils.printThrowable(e, true);
        throw new RuntimeException(e);
    }
    if (errorCount == 0) {
        System.out.println("MXBeanNotifTest::run: Done without any error");
    } else {
        System.out.println("MXBeanNotifTest::run: Done with " + errorCount + " error(s)");
        throw new RuntimeException("errorCount = " + errorCount);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) ImmutableDescriptor(javax.management.ImmutableDescriptor) MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) Attribute(javax.management.Attribute) CompositeData(javax.management.openmbean.CompositeData) TabularType(javax.management.openmbean.TabularType) Notification(javax.management.Notification) TabularData(javax.management.openmbean.TabularData) JMXConnector(javax.management.remote.JMXConnector) MBeanServer(javax.management.MBeanServer) JMXServiceURL(javax.management.remote.JMXServiceURL) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) JMXConnectorServer(javax.management.remote.JMXConnectorServer) ObjectName(javax.management.ObjectName) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor) MBeanServerConnection(javax.management.MBeanServerConnection) CompositeType(javax.management.openmbean.CompositeType)

Example 63 with TabularDataSupport

use of javax.management.openmbean.TabularDataSupport in project tesb-studio-se by Talend.

the class JMXUtil method getBundlesList.

public static long[] getBundlesList() throws Exception {
    String KARAF_BUNDLE_MBEAN = "org.apache.karaf:type=bundle,name=trun";
    ObjectName objectBundle = new ObjectName(KARAF_BUNDLE_MBEAN);
    Set<Object> existsBundles = ((TabularDataSupport) mbsc.getAttribute(objectBundle, "Bundles")).keySet();
    Object[] bundleIds = existsBundles.toArray();
    long[] bundleIDs = new long[existsBundles.size()];
    for (int i = 0; i < bundleIds.length; i++) {
        String id = bundleIds[i].toString();
        bundleIDs[i] = Long.parseLong(id.substring(1, id.length() - 1));
    }
    return bundleIDs;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) ObjectName(javax.management.ObjectName)

Example 64 with TabularDataSupport

use of javax.management.openmbean.TabularDataSupport in project tesb-studio-se by Talend.

the class JMXUtil method getBundlesName.

public static String[] getBundlesName() throws Exception {
    String KARAF_BUNDLE_MBEAN = "org.apache.karaf:type=bundle,name=trun";
    ObjectName objectBundle = new ObjectName(KARAF_BUNDLE_MBEAN);
    Collection<Object> values = ((TabularDataSupport) mbsc.getAttribute(objectBundle, "Bundles")).values();
    Object[] bundles = values.toArray();
    String[] bundleNames = new String[values.size()];
    for (int i = 0; i < bundles.length; i++) {
        bundleNames[i] = String.valueOf(((javax.management.openmbean.CompositeDataSupport) bundles[i]).get("Name"));
    }
    return bundleNames;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) ObjectName(javax.management.ObjectName)

Example 65 with TabularDataSupport

use of javax.management.openmbean.TabularDataSupport in project aries by apache.

the class ProvisioningService method listInformation.

/**
     * @see org.osgi.jmx.service.provisioning.ProvisioningServiceMBean#listInformation()
     */
@SuppressWarnings("unchecked")
public TabularData listInformation() throws IOException {
    TabularData propertiesTable = new TabularDataSupport(PROPERTIES_TYPE);
    Dictionary<String, Object> information = (Dictionary<String, Object>) provisioningService.getInformation();
    if (information != null) {
        Enumeration<String> keys = information.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            propertiesTable.put(PropertyData.newInstance(key, information.get(key)).toCompositeData());
        }
    }
    return propertiesTable;
}
Also used : Dictionary(java.util.Dictionary) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularData(javax.management.openmbean.TabularData)

Aggregations

TabularDataSupport (javax.management.openmbean.TabularDataSupport)103 TabularData (javax.management.openmbean.TabularData)67 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)60 CompositeData (javax.management.openmbean.CompositeData)51 CompositeType (javax.management.openmbean.CompositeType)50 TabularType (javax.management.openmbean.TabularType)36 Map (java.util.Map)27 OpenDataException (javax.management.openmbean.OpenDataException)24 HashMap (java.util.HashMap)11 Bundle (org.osgi.framework.Bundle)10 IOException (java.io.IOException)7 ObjectName (javax.management.ObjectName)7 OpenType (javax.management.openmbean.OpenType)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 Test (org.junit.Test)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 MBeanException (javax.management.MBeanException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)4 Dictionary (java.util.Dictionary)4