Search in sources :

Example 11 with CompositeDataSupport

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

the class TestRollingUpgrade method getBean.

private static CompositeDataSupport getBean() throws MalformedObjectNameException, MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName mxbeanName = new ObjectName("Hadoop:service=NameNode,name=NameNodeInfo");
    return (CompositeDataSupport) mbs.getAttribute(mxbeanName, "RollingUpgradeStatus");
}
Also used : CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 12 with CompositeDataSupport

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

the class TestRollingUpgrade method checkMxBeanIsNull.

private static void checkMxBeanIsNull() throws Exception {
    CompositeDataSupport ruBean = getBean();
    assertNull(ruBean);
}
Also used : CompositeDataSupport(javax.management.openmbean.CompositeDataSupport)

Example 13 with CompositeDataSupport

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

the class TestRollingUpgrade method checkMxBean.

private static void checkMxBean() throws Exception {
    CompositeDataSupport ruBean = getBean();
    assertNotEquals(0l, ruBean.get("startTime"));
    assertEquals(0l, ruBean.get("finalizeTime"));
}
Also used : CompositeDataSupport(javax.management.openmbean.CompositeDataSupport)

Example 14 with CompositeDataSupport

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

the class JMXAccessorTask method createProperty.

/**
     * create result as property with name from property prefix When result is
     * an array and isSeparateArrayResults is true, resultproperty used as
     * prefix (<code>resultproperty.0-array.length</code> and store the
     * result array length at <code>resultproperty.length</code>. Other
     * option is that you delimit your result with a delimiter
     * (java.util.StringTokenizer is used).
     *
     * @param propertyPrefix Prefix for the property
     * @param result The result
     */
protected void createProperty(String propertyPrefix, Object result) {
    if (propertyPrefix == null)
        propertyPrefix = "";
    if (result instanceof CompositeDataSupport) {
        CompositeDataSupport data = (CompositeDataSupport) result;
        CompositeType compositeType = data.getCompositeType();
        Set<String> keys = compositeType.keySet();
        for (Iterator<String> iter = keys.iterator(); iter.hasNext(); ) {
            String key = iter.next();
            Object value = data.get(key);
            OpenType<?> type = compositeType.getType(key);
            if (type instanceof SimpleType<?>) {
                setProperty(propertyPrefix + "." + key, value);
            } else {
                createProperty(propertyPrefix + "." + key, value);
            }
        }
    } else if (result instanceof TabularDataSupport) {
        TabularDataSupport data = (TabularDataSupport) result;
        for (Iterator<Object> iter = data.keySet().iterator(); iter.hasNext(); ) {
            Object key = iter.next();
            for (Iterator<?> iter1 = ((List<?>) key).iterator(); iter1.hasNext(); ) {
                Object key1 = iter1.next();
                CompositeData valuedata = data.get(new Object[] { key1 });
                Object value = valuedata.get("value");
                OpenType<?> type = valuedata.getCompositeType().getType("value");
                if (type instanceof SimpleType<?>) {
                    setProperty(propertyPrefix + "." + key1, value);
                } else {
                    createProperty(propertyPrefix + "." + key1, value);
                }
            }
        }
    } else if (result.getClass().isArray()) {
        if (isSeparatearrayresults()) {
            int size = 0;
            for (int i = 0; i < Array.getLength(result); i++) {
                if (setProperty(propertyPrefix + "." + size, Array.get(result, i))) {
                    size++;
                }
            }
            if (size > 0) {
                setProperty(propertyPrefix + ".Length", Integer.toString(size));
            }
        }
    } else {
        String delim = getDelimiter();
        if (delim != null) {
            StringTokenizer tokenizer = new StringTokenizer(result.toString(), delim);
            int size = 0;
            for (; tokenizer.hasMoreTokens(); ) {
                String token = tokenizer.nextToken();
                if (setProperty(propertyPrefix + "." + size, token)) {
                    size++;
                }
            }
            if (size > 0)
                setProperty(propertyPrefix + ".Length", Integer.toString(size));
        } else {
            setProperty(propertyPrefix, result.toString());
        }
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeData(javax.management.openmbean.CompositeData) SimpleType(javax.management.openmbean.SimpleType) StringTokenizer(java.util.StringTokenizer) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Iterator(java.util.Iterator) CompositeType(javax.management.openmbean.CompositeType)

Example 15 with CompositeDataSupport

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

the class DruidAbstractDataSource method getCompositeData.

public CompositeDataSupport getCompositeData() throws JMException {
    JdbcDataSourceStat stat = this.getDataSourceStat();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("ID", getID());
    map.put("URL", this.getUrl());
    map.put("Name", this.getName());
    map.put("FilterClasses", getFilterClasses());
    map.put("CreatedTime", getCreatedTime());
    map.put("RawDriverClassName", getDriverClassName());
    map.put("RawUrl", getUrl());
    map.put("RawDriverMajorVersion", getRawDriverMajorVersion());
    map.put("RawDriverMinorVersion", getRawDriverMinorVersion());
    map.put("Properties", getProperties());
    // 0 - 4
    map.put("ConnectionActiveCount", (long) getActiveCount());
    map.put("ConnectionActiveCountMax", getActivePeak());
    map.put("ConnectionCloseCount", getCloseCount());
    map.put("ConnectionCommitCount", getCommitCount());
    map.put("ConnectionRollbackCount", getRollbackCount());
    // 5 - 9
    map.put("ConnectionConnectLastTime", stat.getConnectionStat().getConnectLastTime());
    map.put("ConnectionConnectErrorCount", this.getCreateCount());
    if (createError != null) {
        map.put("ConnectionConnectErrorLastTime", getLastCreateErrorTime());
        map.put("ConnectionConnectErrorLastMessage", createError.getMessage());
        map.put("ConnectionConnectErrorLastStackTrace", Utils.getStackTrace(createError));
    } else {
        map.put("ConnectionConnectErrorLastTime", null);
        map.put("ConnectionConnectErrorLastMessage", null);
        map.put("ConnectionConnectErrorLastStackTrace", null);
    }
    // 10 - 14
    map.put("StatementCreateCount", stat.getStatementStat().getCreateCount());
    map.put("StatementPrepareCount", stat.getStatementStat().getPrepareCount());
    map.put("StatementPreCallCount", stat.getStatementStat().getPrepareCallCount());
    map.put("StatementExecuteCount", stat.getStatementStat().getExecuteCount());
    map.put("StatementRunningCount", stat.getStatementStat().getRunningCount());
    // 15 - 19
    map.put("StatementConcurrentMax", stat.getStatementStat().getConcurrentMax());
    map.put("StatementCloseCount", stat.getStatementStat().getCloseCount());
    map.put("StatementErrorCount", stat.getStatementStat().getErrorCount());
    map.put("StatementLastErrorTime", null);
    map.put("StatementLastErrorMessage", null);
    // 20 - 24
    map.put("StatementLastErrorStackTrace", null);
    map.put("StatementExecuteMillisTotal", stat.getStatementStat().getMillisTotal());
    map.put("StatementExecuteLastTime", stat.getStatementStat().getExecuteLastTime());
    map.put("ConnectionConnectingCount", stat.getConnectionStat().getConnectingCount());
    map.put("ResultSetCloseCount", stat.getResultSetStat().getCloseCount());
    // 25 - 29
    map.put("ResultSetOpenCount", stat.getResultSetStat().getOpenCount());
    map.put("ResultSetOpenningCount", stat.getResultSetStat().getOpeningCount());
    map.put("ResultSetOpenningMax", stat.getResultSetStat().getOpeningMax());
    map.put("ResultSetFetchRowCount", stat.getResultSetStat().getFetchRowCount());
    map.put("ResultSetLastOpenTime", stat.getResultSetStat().getLastOpenTime());
    // 30 - 34
    map.put("ResultSetErrorCount", stat.getResultSetStat().getErrorCount());
    map.put("ResultSetOpenningMillisTotal", stat.getResultSetStat().getAliveMillisTotal());
    map.put("ResultSetLastErrorTime", stat.getResultSetStat().getLastErrorTime());
    map.put("ResultSetLastErrorMessage", null);
    map.put("ResultSetLastErrorStackTrace", null);
    // 35 - 39
    map.put("ConnectionConnectCount", this.getConnectCount());
    if (createError != null) {
        map.put("ConnectionErrorLastMessage", createError.getMessage());
        map.put("ConnectionErrorLastStackTrace", Utils.getStackTrace(createError));
    } else {
        map.put("ConnectionErrorLastMessage", null);
        map.put("ConnectionErrorLastStackTrace", null);
    }
    map.put("ConnectionConnectMillisTotal", stat.getConnectionStat().getConnectMillis());
    map.put("ConnectionConnectingCountMax", stat.getConnectionStat().getConnectingMax());
    // 40 - 44
    map.put("ConnectionConnectMillisMax", stat.getConnectionStat().getConnectMillisMax());
    map.put("ConnectionErrorLastTime", stat.getConnectionStat().getErrorLastTime());
    map.put("ConnectionAliveMillisMax", stat.getConnectionConnectAliveMillisMax());
    map.put("ConnectionAliveMillisMin", stat.getConnectionConnectAliveMillisMin());
    map.put("ConnectionHistogram", stat.getConnectionHistogramValues());
    map.put("StatementHistogram", stat.getStatementStat().getHistogramValues());
    return new CompositeDataSupport(JdbcStatManager.getDataSourceCompositeType(), map);
}
Also used : HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) JdbcDataSourceStat(com.alibaba.druid.stat.JdbcDataSourceStat)

Aggregations

CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)92 CompositeData (javax.management.openmbean.CompositeData)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)60 CompositeType (javax.management.openmbean.CompositeType)55 TabularData (javax.management.openmbean.TabularData)43 OpenDataException (javax.management.openmbean.OpenDataException)25 HashMap (java.util.HashMap)21 Map (java.util.Map)19 TabularType (javax.management.openmbean.TabularType)19 OpenType (javax.management.openmbean.OpenType)10 Test (org.junit.Test)8 ObjectName (javax.management.ObjectName)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 MBeanServer (javax.management.MBeanServer)6 IOException (java.io.IOException)5 MBeanException (javax.management.MBeanException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)3 MBeanInfo (javax.management.MBeanInfo)3 Bundle (org.osgi.framework.Bundle)3