Search in sources :

Example 1 with OpenType

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

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

the class JdbcStatManager method getDataSourceCompositeType.

public static CompositeType getDataSourceCompositeType() throws JMException {
    if (COMPOSITE_TYPE != null) {
        return COMPOSITE_TYPE;
    }
    OpenType<?>[] indexTypes = new OpenType<?>[] { //
    SimpleType.LONG, //
    SimpleType.STRING, //
    SimpleType.STRING, //
    new ArrayType<SimpleType<String>>(SimpleType.STRING, false), //
    SimpleType.DATE, //
    SimpleType.STRING, //
    SimpleType.STRING, //
    SimpleType.INTEGER, //
    SimpleType.INTEGER, //
    SimpleType.STRING, //
    SimpleType.LONG, //
    SimpleType.INTEGER, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.DATE, //
    SimpleType.LONG, //
    SimpleType.DATE, //
    SimpleType.STRING, //
    SimpleType.STRING, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.INTEGER, //
    SimpleType.INTEGER, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.DATE, //
    SimpleType.STRING, //
    SimpleType.STRING, //
    SimpleType.LONG, //
    SimpleType.INTEGER, //
    SimpleType.DATE, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.INTEGER, //
    SimpleType.INTEGER, //
    SimpleType.LONG, SimpleType.DATE, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.DATE, //
    SimpleType.STRING, SimpleType.STRING, //
    SimpleType.LONG, //
    SimpleType.STRING, //
    SimpleType.STRING, //
    SimpleType.LONG, //
    SimpleType.INTEGER, //
    SimpleType.LONG, //
    SimpleType.DATE, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    new ArrayType<Long>(SimpleType.LONG, true), // 55 -
    new ArrayType<Long>(SimpleType.LONG, true) };
    String[] indexNames = { // 0 - 4
    "ID", "URL", "Name", "FilterClasses", //
    "CreatedTime", // 5 - 9
    "RawUrl", "RawDriverClassName", "RawDriverMajorVersion", "RawDriverMinorVersion", //
    "Properties", // 10 - 14
    "ConnectionActiveCount", "ConnectionActiveCountMax", "ConnectionCloseCount", "ConnectionCommitCount", //
    "ConnectionRollbackCount", // 15 - 19
    "ConnectionConnectLastTime", "ConnectionConnectErrorCount", "ConnectionConnectErrorLastTime", "ConnectionConnectErrorLastMessage", //
    "ConnectionConnectErrorLastStackTrace", // 20 - 24
    "StatementCreateCount", "StatementPrepareCount", "StatementPreCallCount", "StatementExecuteCount", //
    "StatementRunningCount", // 25 - 29
    "StatementConcurrentMax", "StatementCloseCount", "StatementErrorCount", "StatementLastErrorTime", //
    "StatementLastErrorMessage", // 30 - 34
    "StatementLastErrorStackTrace", "StatementExecuteMillisTotal", "ConnectionConnectingCount", "StatementExecuteLastTime", //
    "ResultSetCloseCount", // 35 -39
    "ResultSetOpenCount", "ResultSetOpenningCount", "ResultSetOpenningMax", "ResultSetFetchRowCount", //
    "ResultSetLastOpenTime", //
    "ResultSetErrorCount", //
    "ResultSetOpenningMillisTotal", //
    "ResultSetLastErrorTime", //
    "ResultSetLastErrorMessage", //
    "ResultSetLastErrorStackTrace", //
    "ConnectionConnectCount", //
    "ConnectionErrorLastMessage", //
    "ConnectionErrorLastStackTrace", //
    "ConnectionConnectMillisTotal", "ConnectionConnectingCountMax", //
    "ConnectionConnectMillisMax", //
    "ConnectionErrorLastTime", //
    "ConnectionAliveMillisMax", //
    "ConnectionAliveMillisMin", //
    "ConnectionHistogram", // 55 -
    "StatementHistogram" };
    COMPOSITE_TYPE = new CompositeType("DataSourceStatistic", "DataSource Statistic", indexNames, indexNames, indexTypes);
    return COMPOSITE_TYPE;
}
Also used : ArrayType(javax.management.openmbean.ArrayType) OpenType(javax.management.openmbean.OpenType) CompositeType(javax.management.openmbean.CompositeType)

Example 3 with OpenType

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

the class DruidDataSourceStatManager method getDruidDataSourceCompositeType.

public static CompositeType getDruidDataSourceCompositeType() throws JMException {
    if (COMPOSITE_TYPE != null) {
        return COMPOSITE_TYPE;
    }
    OpenType<?>[] indexTypes = new OpenType<?>[] { //
    SimpleType.STRING, //
    SimpleType.STRING, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.INTEGER, //
    SimpleType.INTEGER, //
    SimpleType.INTEGER, //
    SimpleType.INTEGER, //
    SimpleType.INTEGER, //
    SimpleType.INTEGER, //
    SimpleType.INTEGER, //
    SimpleType.BOOLEAN, //
    SimpleType.BOOLEAN, //
    SimpleType.BOOLEAN, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.STRING, //
    SimpleType.STRING, //
    SimpleType.INTEGER, //
    SimpleType.STRING, //
    SimpleType.STRING, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    JMXUtils.getThrowableCompositeType(), //
    JMXUtils.getThrowableCompositeType(), //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.LONG, //
    SimpleType.STRING, //
    SimpleType.DATE, //
    SimpleType.DATE, //
    SimpleType.LONG, //
    SimpleType.LONG };
    String[] indexNames = { //
    "Name", //
    "URL", //
    "CreateCount", //
    "DestroyCount", //
    "ConnectCount", //
    "CloseCount", //
    "ActiveCount", //
    "PoolingCount", //
    "LockQueueLength", //
    "WaitThreadCount", //
    "InitialSize", //
    "MaxActive", //
    "MinIdle", //
    "PoolPreparedStatements", //
    "TestOnBorrow", //
    "TestOnReturn", //
    "MinEvictableIdleTimeMillis", //
    "ConnectErrorCount", //
    "CreateTimespanMillis", //
    "DbType", //
    "ValidationQuery", //
    "ValidationQueryTimeout", //
    "DriverClassName", //
    "Username", //
    "RemoveAbandonedCount", //
    "NotEmptyWaitCount", //
    "NotEmptyWaitNanos", //
    "ErrorCount", //
    "ReusePreparedStatementCount", //
    "StartTransactionCount", //
    "CommitCount", //
    "RollbackCount", //
    "LastError", //
    "LastCreateError", //
    "PreparedStatementCacheDeleteCount", //
    "PreparedStatementCacheAccessCount", //
    "PreparedStatementCacheMissCount", //
    "PreparedStatementCacheHitCount", //
    "PreparedStatementCacheCurrentCount", //
    "Version", //
    "LastErrorTime", //
    "LastCreateErrorTime", //
    "CreateErrorCount", //
    "DiscardCount" };
    String[] indexDescriptions = indexNames;
    COMPOSITE_TYPE = new CompositeType("DataSourceStatistic", "DataSource Statistic", indexNames, indexDescriptions, indexTypes);
    return COMPOSITE_TYPE;
}
Also used : OpenType(javax.management.openmbean.OpenType) CompositeType(javax.management.openmbean.CompositeType)

Example 4 with OpenType

use of javax.management.openmbean.OpenType 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 5 with OpenType

use of javax.management.openmbean.OpenType in project deltaspike by apache.

the class DeltaSpikeConfigInfo method getConfigSources.

@Override
public TabularData getConfigSources() {
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(appConfigClassLoader);
        String typeName = "ConfigSources";
        OpenType<?>[] types = new OpenType<?>[] { SimpleType.INTEGER, SimpleType.STRING };
        String[] keys = new String[] { "Ordinal", "ConfigSource" };
        CompositeType ct = new CompositeType(typeName, typeName, keys, keys, types);
        TabularType type = new TabularType(typeName, typeName, ct, keys);
        TabularDataSupport configSourceInfo = new TabularDataSupport(type);
        ConfigSource[] configSources = ConfigResolver.getConfigSources();
        for (ConfigSource configSource : configSources) {
            configSourceInfo.put(new CompositeDataSupport(ct, keys, new Object[] { configSource.getOrdinal(), configSource.getConfigName() }));
        }
        return configSourceInfo;
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    } finally {
        // set back the original TCCL
        Thread.currentThread().setContextClassLoader(originalCl);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

OpenType (javax.management.openmbean.OpenType)28 CompositeType (javax.management.openmbean.CompositeType)23 OpenDataException (javax.management.openmbean.OpenDataException)15 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)10 TabularType (javax.management.openmbean.TabularType)10 TabularDataSupport (javax.management.openmbean.TabularDataSupport)7 ObjectName (javax.management.ObjectName)6 ArrayType (javax.management.openmbean.ArrayType)6 CompositeData (javax.management.openmbean.CompositeData)6 GenericArrayType (java.lang.reflect.GenericArrayType)5 ParameterizedType (java.lang.reflect.ParameterizedType)5 MBeanServer (javax.management.MBeanServer)5 Method (java.lang.reflect.Method)4 Type (java.lang.reflect.Type)4 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)4 MBeanInfo (javax.management.MBeanInfo)4 Descriptor (javax.management.Descriptor)3 ImmutableDescriptor (javax.management.ImmutableDescriptor)3 JMException (javax.management.JMException)3 MBeanOperationInfo (javax.management.MBeanOperationInfo)3