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