Search in sources :

Example 71 with TabularData

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"));
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Iterator(java.util.Iterator) NotificationListener(javax.management.NotificationListener) MBeanParameterInfo(javax.management.MBeanParameterInfo) Test(org.junit.Test)

Example 72 with TabularData

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;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) InvalidObjectException(java.io.InvalidObjectException) TabularData(javax.management.openmbean.TabularData)

Example 73 with TabularData

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;
}
Also used : TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Comparator(java.util.Comparator) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) SortedMap(java.util.SortedMap) Map(java.util.Map) SortedMap(java.util.SortedMap) CompositeType(javax.management.openmbean.CompositeType)

Example 74 with TabularData

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);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) CompositeData(javax.management.openmbean.CompositeData) InstanceNotFoundException(javax.management.InstanceNotFoundException) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) TabularData(javax.management.openmbean.TabularData) Collection(java.util.Collection) MBeanException(javax.management.MBeanException)

Example 75 with TabularData

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());
}
Also used : LocalIndexFile(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile) File(java.io.File) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) FilterDirectory(org.apache.lucene.store.FilterDirectory) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Aggregations

TabularData (javax.management.openmbean.TabularData)183 CompositeData (javax.management.openmbean.CompositeData)91 TabularDataSupport (javax.management.openmbean.TabularDataSupport)67 ObjectName (javax.management.ObjectName)54 MBeanServer (javax.management.MBeanServer)50 CompositeType (javax.management.openmbean.CompositeType)47 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)43 Test (org.junit.Test)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)21 HashMap (java.util.HashMap)20 TabularType (javax.management.openmbean.TabularType)17 Bundle (org.osgi.framework.Bundle)17 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)15 Collection (java.util.Collection)13 IOException (java.io.IOException)11 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)9 List (java.util.List)8 ServiceReference (org.osgi.framework.ServiceReference)8