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());
}
}
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations