use of javax.management.openmbean.TabularData in project deltaspike by apache.
the class SimpleRegistrationTest method checkMBean.
@Test
public void checkMBean() throws Exception {
assertEquals(0, myMBean.getCounter());
myMBean.resetTo(2);
final ObjectName on = new ObjectName("org.apache.deltaspike:type=MBeans,name=" + MyMBean.class.getName());
assertTrue(server.isRegistered(on));
assertEquals(2, server.getAttribute(on, "counter"));
assertEquals(6, server.invoke(on, "multiply", new Object[] { 3 }, new String[0]));
myMBean.resetTo(5);
assertEquals(5, server.getAttribute(on, "counter"));
assertEquals(20, server.invoke(on, "multiply", new Object[] { 4 }, new String[0]));
server.setAttribute(on, new Attribute("counter", 10));
assertEquals(10, myMBean.getCounter());
final Collection<Notification> notifications = new ArrayList<Notification>();
server.addNotificationListener(on, new NotificationListener() {
@Override
public void handleNotification(final Notification notification, final Object handback) {
notifications.add(notification);
}
}, null, null);
myMBean.broadcast();
assertEquals(1, notifications.size());
assertEquals(10L, notifications.iterator().next().getSequenceNumber());
MBeanInfo mBeanInfo = server.getMBeanInfo(on);
Assert.assertNotNull(mBeanInfo);
MBeanOperationInfo[] operations = mBeanInfo.getOperations();
Assert.assertNotNull(operations);
Assert.assertTrue(operations.length > 0);
Assert.assertTrue("Empty Signature on operation: " + operations[1], operations[1].getSignature().length > 0);
MBeanParameterInfo parameterInfo = operations[1].getSignature()[0];
assertEquals("multiplier", parameterInfo.getName());
assertEquals("the multiplier", parameterInfo.getDescription());
{
// table support - through map
Object table = server.getAttribute(on, "table");
assertTrue(TabularData.class.isInstance(table));
final TabularData data = TabularData.class.cast(table);
assertEquals(1, data.size());
final CompositeData compositeData = CompositeData.class.cast(data.values().iterator().next());
assertEquals(2, compositeData.values().size());
assertEquals("value1", compositeData.get("key1"));
assertEquals("value2", compositeData.get("key2"));
}
{
// table support - through Table
Object table = server.getAttribute(on, "table2");
assertTrue(TabularData.class.isInstance(table));
final TabularData data = TabularData.class.cast(table);
assertEquals(2, data.size());
final Iterator<?> iterator = data.values().iterator();
{
final CompositeData compositeData = CompositeData.class.cast(iterator.next());
assertEquals(3, compositeData.values().size());
assertEquals("1", compositeData.get("a"));
assertEquals("2", compositeData.get("b"));
assertEquals("3", compositeData.get("c"));
}
{
final CompositeData compositeData = CompositeData.class.cast(iterator.next());
assertEquals(3, compositeData.values().size());
assertEquals("alpha", compositeData.get("a"));
assertEquals("beta", compositeData.get("b"));
assertEquals("gamma", compositeData.get("c"));
}
}
}
use of javax.management.openmbean.TabularData in project geode by apache.
the class TableConverter method fromNonNullOpenValue.
public Object fromNonNullOpenValue(Object openValue) throws InvalidObjectException {
final TabularData table = (TabularData) openValue;
final Collection<CompositeData> rows = (Collection<CompositeData>) table.values();
final Map<Object, Object> valueMap = sortedMap ? OpenTypeUtil.newSortedMap() : OpenTypeUtil.newMap();
for (CompositeData row : rows) {
final Object key = keyConverter.fromOpenValue(row.get("key"));
final Object value = valueConverter.fromOpenValue(row.get("value"));
if (valueMap.put(key, value) != null) {
final String msg = "Duplicate entry in TabularData: key=" + key;
throw new InvalidObjectException(msg);
}
}
return valueMap;
}
use of javax.management.openmbean.TabularData in project geode by apache.
the class TableConverter method toNonNullOpenValue.
Object toNonNullOpenValue(Object value) throws OpenDataException {
final Map<Object, Object> valueMap = (Map<Object, Object>) value;
if (valueMap instanceof SortedMap) {
Comparator comparator = ((SortedMap) valueMap).comparator();
if (comparator != null) {
final String msg = "Cannot convert SortedMap with non-null comparator: " + comparator;
IllegalArgumentException iae = new IllegalArgumentException(msg);
OpenDataException ode = new OpenDataException(msg);
ode.initCause(iae);
throw ode;
}
}
final TabularType tabularType = (TabularType) getOpenType();
final TabularData table = new TabularDataSupport(tabularType);
final CompositeType rowType = tabularType.getRowType();
for (Map.Entry entry : valueMap.entrySet()) {
final Object openKey = keyConverter.toOpenValue(entry.getKey());
final Object openValue = valueConverter.toOpenValue(entry.getValue());
final CompositeData row;
row = new CompositeDataSupport(rowType, keyValueArray, new Object[] { openKey, openValue });
table.put(row);
}
return table;
}
use of javax.management.openmbean.TabularData in project geode by apache.
the class JMXDataUpdater method updateClusterSystem.
/**
* function used to get attribute values of Cluster System and map them to cluster vo
*
* @param mbeanName Cluster System MBean
*/
private void updateClusterSystem(ObjectName mbeanName) throws IOException {
try {
if (!this.isAddedNotiListner) {
this.mbs.addNotificationListener(mbeanName, this, null, new Object());
this.isAddedNotiListner = true;
}
String[] serverCnt = (String[]) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_LISTSERVERS, null, null));
cluster.setServerCount(serverCnt.length);
TabularData table = (TabularData) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_VIEWREMOTECLUSTERSTATUS, null, null));
Collection<CompositeData> rows = (Collection<CompositeData>) table.values();
cluster.getWanInformationObject().clear();
for (CompositeData row : rows) {
final Object key = row.get("key");
final Object value = row.get("value");
cluster.getWanInformationObject().put((String) key, (Boolean) value);
}
AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.CLUSTER_MBEAN_ATTRIBUTES);
for (int i = 0; i < attributeList.size(); i++) {
Attribute attribute = (Attribute) attributeList.get(i);
String name = attribute.getName();
switch(name) {
case PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT:
cluster.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_NUMCLIENTS:
cluster.setClientConnectionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_DISTRIBUTEDSYSTEMID:
cluster.setClusterId(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_LOCATORCOUNT:
cluster.setLocatorCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_NUMRUNNIGFUNCTION:
try {
cluster.setRunningFunctionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
} catch (Exception e) {
cluster.setRunningFunctionCount(0);
continue;
}
break;
case PulseConstants.MBEAN_ATTRIBUTE_REGISTEREDCQCOUNT:
cluster.setRegisteredCQCount(getLongAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_NUMSUBSCRIPTIONS:
cluster.setSubscriptionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNCOMMITTED:
cluster.setTxnCommittedCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNROLLBACK:
cluster.setTxnRollbackCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_TOTALHEAPSIZE:
cluster.setTotalHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_USEDHEAPSIZE:
try {
cluster.setUsedHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
} catch (Exception e) {
cluster.setUsedHeapSize((long) 0);
continue;
}
cluster.getMemoryUsageTrend().add(cluster.getUsedHeapSize());
break;
case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONENTRYCOUNT:
cluster.setTotalRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_CURRENTENTRYCOUNT:
cluster.setCurrentQueryCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_TOTALDISKUSAGE:
try {
cluster.setTotalBytesOnDisk(getLongAttribute(attribute.getValue(), attribute.getName()));
} catch (Exception e) {
cluster.setTotalBytesOnDisk((long) 0);
continue;
}
cluster.getTotalBytesOnDiskTrend().add(cluster.getTotalBytesOnDisk());
break;
case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
cluster.setDiskWritesRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
cluster.getThroughoutWritesTrend().add(cluster.getDiskWritesRate());
break;
case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES:
try {
cluster.setWritePerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
} catch (Exception e) {
cluster.setWritePerSec(0);
continue;
}
cluster.getWritePerSecTrend().add(cluster.getWritePerSec());
break;
case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS:
try {
cluster.setReadPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
} catch (Exception e) {
cluster.setReadPerSec(0);
continue;
}
cluster.getReadPerSecTrend().add(cluster.getReadPerSec());
break;
case PulseConstants.MBEAN_ATTRIBUTE_QUERYREQUESTRATE:
cluster.setQueriesPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
cluster.getQueriesPerSecTrend().add(cluster.getQueriesPerSec());
break;
case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
cluster.setDiskReadsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
cluster.getThroughoutReadsTrend().add(cluster.getDiskReadsRate());
break;
case PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES:
long trendVal = determineCurrentJVMPauses(PulseConstants.JVM_PAUSES_TYPE_CLUSTER, "", getLongAttribute(attribute.getValue(), attribute.getName()));
cluster.setGarbageCollectionCount(trendVal);
cluster.getGarbageCollectionTrend().add(cluster.getGarbageCollectionCount());
break;
case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT:
cluster.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
}
}
} catch (InstanceNotFoundException | ReflectionException | MBeanException infe) {
logger.warn(infe);
}
}
use of javax.management.openmbean.TabularData in project jackrabbit-oak by apache.
the class IndexCopierTest method basicTestWithFS.
@Test
public void basicTestWithFS() throws Exception {
IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
IndexCopier c1 = new IndexCopier(sameThreadExecutor(), getWorkDir());
Directory remote = new RAMDirectory();
Directory wrapped = c1.wrapForRead("/foo", defn, remote, INDEX_DATA_CHILD_NAME);
byte[] t1 = writeFile(remote, "t1");
byte[] t2 = writeFile(remote, "t2");
assertEquals(2, wrapped.listAll().length);
assertTrue(wrapped.fileExists("t1"));
assertTrue(wrapped.fileExists("t2"));
assertEquals(t1.length, wrapped.fileLength("t1"));
assertEquals(t2.length, wrapped.fileLength("t2"));
readAndAssert(wrapped, "t1", t1);
//t1 should now be added to testDir
File indexDir = c1.getIndexDir(defn, "/foo", INDEX_DATA_CHILD_NAME);
assertTrue(new File(indexDir, "t1").exists());
TabularData td = c1.getIndexPathMapping();
assertEquals(1, td.size());
}
Aggregations