use of javax.management.openmbean.TabularType in project jackrabbit-oak by apache.
the class TrackingCorruptIndexHandler method getFailingIndexStats.
//~-----------------------------------------------------< MBean Support >
public TabularData getFailingIndexStats(String asyncName) {
TabularDataSupport tds;
try {
TabularType tt = new TabularType(TrackingCorruptIndexHandler.class.getName(), "Failing Index Stats", FailingIndexStats.TYPE, new String[] { "path" });
tds = new TabularDataSupport(tt);
Map<String, CorruptIndexInfo> infos = getFailingIndexData(asyncName);
for (Map.Entry<String, CorruptIndexInfo> e : infos.entrySet()) {
FailingIndexStats stats = new FailingIndexStats(e.getValue());
tds.put(stats.toCompositeData());
}
} catch (OpenDataException e) {
throw new IllegalStateException(e);
}
return tds;
}
use of javax.management.openmbean.TabularType in project jackrabbit-oak by apache.
the class ConsolidatedListenerMBeanImpl method getListenerStats.
@Override
public TabularData getListenerStats() {
TabularDataSupport tds;
try {
int id = 0;
TabularType tt = new TabularType(ListenerStatsData.class.getName(), "Consolidated Listener Stats", ListenerStatsData.TYPE, new String[] { "index" });
tds = new TabularDataSupport(tt);
for (ListenerMBeans beans : getListenerMBeans()) {
tds.put(new ListenerStatsData(++id, beans).toCompositeData());
}
} catch (OpenDataException e) {
throw new IllegalStateException(e);
}
return tds;
}
use of javax.management.openmbean.TabularType in project jackrabbit-oak by apache.
the class ConsolidatedListenerMBeanImpl method getLeaderBoard.
@Override
public TabularData getLeaderBoard() {
TabularDataSupport tds;
try {
int id = 0;
TabularType tt = new TabularType(LeaderBoardData.class.getName(), "Leaderboard", LeaderBoardData.TYPE, new String[] { "index" });
tds = new TabularDataSupport(tt);
List<LeaderBoardData> leaderBoard = Lists.newArrayList();
for (Map.Entry<ObjectName, EventListenerMBean> e : eventListeners.entrySet()) {
String listenerId = getListenerId(e.getKey());
EventListenerMBean mbean = e.getValue();
FilterConfigMBean filterConfigMBean = null;
for (Map.Entry<ObjectName, FilterConfigMBean> ef : filterConfigs.entrySet()) {
if (Objects.equal(getListenerId(ef.getKey()), listenerId)) {
filterConfigMBean = ef.getValue();
break;
}
}
leaderBoard.add(new LeaderBoardData(++id, mbean, filterConfigMBean));
}
sort(leaderBoard);
for (LeaderBoardData data : leaderBoard) {
tds.put(data.toCompositeData());
}
} catch (OpenDataException e) {
throw new IllegalStateException(e);
}
return tds;
}
use of javax.management.openmbean.TabularType in project jackrabbit by apache.
the class QueryStatManager method asTabularData.
private TabularData asTabularData(QueryStatDto[] data) {
TabularDataSupport tds = null;
try {
CompositeType ct = QueryStatCompositeTypeFactory.getCompositeType();
TabularType tt = new TabularType(QueryStatDto.class.getName(), "Query History", ct, QueryStatCompositeTypeFactory.index);
tds = new TabularDataSupport(tt);
for (QueryStatDto q : data) {
tds.put(new CompositeDataSupport(ct, QueryStatCompositeTypeFactory.names, QueryStatCompositeTypeFactory.getValues(q)));
}
return tds;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of javax.management.openmbean.TabularType 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);
}
}
Aggregations