Example usage for javax.management.openmbean CompositeData get

List of usage examples for javax.management.openmbean CompositeData get

Introduction

In this page you can find the example usage for javax.management.openmbean CompositeData get.

Prototype

public Object get(String key);

Source Link

Document

Returns the value of the item whose name is key .

Usage

From source file:com.heliosapm.opentsdb.TSDBSubmitterImpl.java

/**
 * Decomposes a composite data type so it can be traced
 * @param objectName The ObjectName of the MBean the composite data came from
 * @param cd The composite data instance
 * @return A map of values keyed by synthesized ObjectNames that represent the structure down to the numeric composite data items
 *//*  w ww  .  j  a  v a2 s.co  m*/
protected Map<ObjectName, Number> fromOpenType(final ObjectName objectName, final CompositeData cd) {
    if (objectName == null)
        throw new IllegalArgumentException("The passed ObjectName was null");
    if (cd == null)
        throw new IllegalArgumentException("The passed CompositeData was null");
    final Map<ObjectName, Number> map = new HashMap<ObjectName, Number>();
    final CompositeType ct = cd.getCompositeType();
    for (final String key : ct.keySet()) {
        final Object value = cd.get(key);
        if (value == null || !(value instanceof Number))
            continue;
        StringBuilder b = new StringBuilder(objectName.toString());
        b.append(",ctype=").append(simpleName(ct.getTypeName()));
        b.append(",metric=").append(key);
        ObjectName on = JMXHelper.objectName(clean(b));
        map.put(on, (Number) value);

    }
    return map;
}

From source file:org.apache.geode.tools.pulse.internal.data.JMXDataUpdater.java

/**
 * function used to get attribute values of Cluster System and map them to cluster vo
 * //w w w  . j  av  a2s .c om
 * @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);
    }
}

From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java

/**
 * function used to get attribute values of Cluster System and map them to
 * cluster vo/* w ww. ja  v  a 2  s  .  c o m*/
 * 
 * @param mbeanName
 *          Cluster System MBean
 * @throws IOException
 * 
 */
private void updateClusterSystem(ObjectName mbeanName) throws IOException {
    try {
        if (!this.isAddedNotiListner) {
            this.mbs.addNotificationListener(mbeanName, this, null, new Object());
            this.isAddedNotiListner = true;
        }

        if (PulseConstants.PRODUCT_NAME_GEMFIREXD.equalsIgnoreCase(PulseController.getPulseProductSupport())) {
            // Reset to zero
            cluster.setServerCount(0);
            cluster.setTotalRegionCount(0);
        } else {
            String[] serverCnt = (String[]) (this.mbs.invoke(mbeanName,
                    PulseConstants.MBEAN_OPERATION_LISTCACHESERVER, 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);

            if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT)) {
                cluster.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMCLIENTS)) {
                cluster.setClientConnectionCount(
                        getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISTRIBUTEDSYSTEMID)) {
                cluster.setClusterId(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_LOCATORCOUNT)) {
                cluster.setLocatorCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMRUNNIGFUNCTION)) {
                try {
                    cluster.setRunningFunctionCount(
                            getIntegerAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setRunningFunctionCount(0);
                    continue;
                }
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_REGISTEREDCQCOUNT)) {
                cluster.setRegisteredCQCount(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMSUBSCRIPTIONS)) {
                cluster.setSubscriptionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMTXNCOMMITTED)) {
                cluster.setTxnCommittedCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMTXNROLLBACK)) {
                cluster.setTxnRollbackCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALHEAPSIZE)) {
                cluster.setTotalHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(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());
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONENTRYCOUNT)) {
                cluster.setTotalRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_CURRENTENTRYCOUNT)) {
                cluster.setCurrentQueryCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(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());
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE)) {
                cluster.setDiskWritesRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
                cluster.getThroughoutWritesTrend().add(cluster.getDiskWritesRate());
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES)) {
                try {
                    cluster.setWritePerSec(getFloatAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setWritePerSec(0);
                    continue;
                }
                cluster.getWritePerSecTrend().add(cluster.getWritePerSec());
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS)) {
                try {
                    cluster.setReadPerSec(getFloatAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setReadPerSec(0);
                    continue;
                }
                cluster.getReadPerSecTrend().add(cluster.getReadPerSec());

            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_QUERYREQUESTRATE)) {
                cluster.setQueriesPerSec(getFloatAttribute(attribute.getValue(), attribute.getName()));
                cluster.getQueriesPerSecTrend().add(cluster.getQueriesPerSec());

            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE)) {
                cluster.setDiskReadsRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
                cluster.getThroughoutReadsTrend().add(cluster.getDiskReadsRate());
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES)) {
                cluster.setGarbageCollectionCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                cluster.getGarbageCollectionTrend().add(cluster.getGarbageCollectionCount());

            }

            // For GemFireXD or GemFire
            if (PulseConstants.PRODUCT_NAME_GEMFIREXD
                    .equalsIgnoreCase(PulseController.getPulseProductSupport())) {
                // For GemFireXD
                // Do nothing
            } else {
                // For GemFire
                if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT)) {
                    cluster.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                }
            }

        }

        // GEMFIREXD attributes
        if (PulseConstants.PRODUCT_NAME_GEMFIREXD.equalsIgnoreCase(PulseController.getPulseProductSupport())) {

            try { // get GemFireXD cluster mbean

                ObjectName sfMemberMbeansObjectName = new ObjectName(PulseConstants.OBJECT_NAME_SF_CLUSTER);

                Set<ObjectName> sfCluserMBeans = this.mbs.queryNames(sfMemberMbeansObjectName, null);

                for (ObjectName sfCluserMBean : sfCluserMBeans) {

                    AttributeList attrList = this.mbs.getAttributes(sfCluserMBean,
                            PulseConstants.SF_CLUSTER_MBEAN_ATTRIBUTES);

                    for (int i = 0; i < attrList.size(); i++) {

                        Attribute attribute = (Attribute) attrList.get(i);

                        if (attribute.getName()
                                .equals(PulseConstants.MBEAN_ATTRIBUTE_PROCEDURECALLSINPROGRESS)) {
                            try {
                                cluster.setRunningFunctionCount(
                                        getIntegerAttribute(attribute.getValue(), attribute.getName()));
                            } catch (Exception e) {
                                cluster.setRunningFunctionCount(0);
                                continue;
                            }
                        } else if (attribute.getName()
                                .equals(PulseConstants.MBEAN_ATTRIBUTE_NETWORKSERVERCLIENTCONNECTIONSTATS)) {
                            // set number of cluster's clients
                            CompositeData nscConnStats = (CompositeData) attribute.getValue();

                            cluster.setClientConnectionCount(getLongAttribute(
                                    nscConnStats.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSOPEN),
                                    PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSOPEN));
                        }
                    }
                    break;
                }

            } catch (MalformedObjectNameException e) {
                LOGGER.warning(e);
            } catch (NullPointerException e) {
                LOGGER.warning(e);
            }

        }

    } catch (InstanceNotFoundException infe) {
        LOGGER.warning(infe);
    } catch (ReflectionException re) {
        LOGGER.warning(re);
    } catch (MBeanException anfe) {
        LOGGER.warning(anfe);
    }
}

From source file:org.apache.geode.tools.pulse.internal.data.JMXDataUpdater.java

/**
 * function used for getting member clients from mbean and update the clients information in
 * member object's client arraylist//from  w  w  w. j  av  a 2s . c  o  m
 */
private void updateMemberClient(ObjectName mbeanName) throws IOException {

    try {
        String memberName = mbeanName.getKeyProperty(PulseConstants.MBEAN_KEY_PROPERTY_MEMBER);

        if (cluster.getMembersHMap().containsKey(memberName)) {
            Cluster.Member existingMember = cluster.getMembersHMap().get(memberName);
            HashMap<String, Cluster.Client> memberClientsHM = new HashMap<String, Cluster.Client>();

            existingMember
                    .setMemberPort("" + this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_PORT));

            this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_HOSTNAMEFORCLIENTS_ALT);
            existingMember.setHostnameForClients((String) this.mbs.getAttribute(mbeanName,
                    PulseConstants.MBEAN_ATTRIBUTE_HOSTNAMEFORCLIENTS_ALT));
            existingMember.setBindAddress(
                    (String) this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_BINDADDRESS));

            CompositeData[] compositeData = (CompositeData[]) (this.mbs.invoke(mbeanName,
                    PulseConstants.MBEAN_OPERATION_SHOWALLCLIENTS, null, null));
            for (CompositeData cmd : compositeData) {
                Cluster.Client client = new Cluster.Client();
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CLIENTID)) {
                    client.setId((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CLIENTID));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NAME)) {
                    client.setName((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NAME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME)) {
                    client.setHost((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE)) {
                    client.setQueueSize((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME)) {
                    client.setProcessCpuTime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_UPTIME)) {
                    client.setUptime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_UPTIME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS)) {
                    client.setThreads((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS)) {
                    client.setGets((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS)) {
                    client.setPuts((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) {
                    client.setCpus((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CPUS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) {
                    client.setCpuUsage(0);
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CONNECTED)) {
                    client.setConnected((Boolean) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTED));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CLIENTCQCOUNT)) {
                    client.setClientCQCount((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CLIENTCQCOUNT));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_SUBSCRIPTIONENABLED)) {
                    client.setSubscriptionEnabled(
                            (Boolean) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_SUBSCRIPTIONENABLED));
                }
                memberClientsHM.put(client.getId(), client);
            }
            existingMember.updateMemberClientsHMap(memberClientsHM);
        }
    } catch (InstanceNotFoundException | ReflectionException | AttributeNotFoundException
            | MBeanException infe) {
        logger.warn(infe);
    }
}

From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java

/**
 * function used for getting member clients from mbean and update the clients
 * information in member object's client arraylist
 * /*w w w.j  ava 2 s .c  om*/
 * @param mbeanName
 * @param memberName
 * @throws InstanceNotFoundException
 * @throws IntrospectionException
 * @throws ReflectionException
 * @throws IOException
 * @throws MBeanException
 * @throws AttributeNotFoundException
 * 
 */
private void updateMemberClient(ObjectName mbeanName) throws IOException {

    try {
        String memberName = mbeanName.getKeyProperty(PulseConstants.MBEAN_KEY_PROPERTY_MEMBER);

        if (cluster.getMembersHMap().containsKey(memberName)) {
            Cluster.Member existingMember = cluster.getMembersHMap().get(memberName);
            HashMap<String, Cluster.Client> memberClientsHM = new HashMap<String, Cluster.Client>();

            existingMember
                    .setMemberPort("" + this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_PORT));

            CompositeData[] compositeData = (CompositeData[]) (this.mbs.invoke(mbeanName,
                    PulseConstants.MBEAN_OPERATION_SHOWALLCLIENTS, null, null));
            for (CompositeData cmd : compositeData) {
                Cluster.Client client = new Cluster.Client();
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CLIENTID)) {
                    client.setId((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CLIENTID));
                } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NAME)) {
                    client.setName((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NAME));
                } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME)) {
                    client.setHost((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME));
                } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE)) {
                    client.setQueueSize((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE));
                } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME)) {
                    client.setProcessCpuTime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME));
                } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_UPTIME)) {
                    client.setUptime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_UPTIME));
                } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS)) {
                    client.setThreads((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS));
                } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS)) {
                    client.setGets((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS));
                } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS)) {
                    client.setPuts((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS));
                } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) {
                    client.setCpus((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CPUS));
                } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) {
                    client.setCpuUsage(0);
                }
                memberClientsHM.put(client.getId(), client);
            }
            existingMember.updateMemberClientsHMap(memberClientsHM);
        }
    } catch (InstanceNotFoundException infe) {
        LOGGER.warning(infe);
    } catch (ReflectionException re) {
        LOGGER.warning(re);
    } catch (MBeanException me) {
        LOGGER.warning(me);
    } catch (AttributeNotFoundException anfe) {
        LOGGER.warning(anfe);
    }
}

From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java

/**
 * function used to iterate through all member attributes and return the
 * updated member//from w  w  w . java  2s.  c  om
 * 
 * @param attrs
 * @param mbeanName
 * @param member
 * @return
 * @throws IOException
 * @throws ReflectionException
 * @throws InstanceNotFoundException
 */
private Cluster.Member initializeMember(ObjectName mbeanName, Cluster.Member member)
        throws InstanceNotFoundException, ReflectionException, IOException {

    AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.MEMBER_MBEAN_ATTRIBUTES);

    for (int i = 0; i < attributeList.size(); i++) {

        Attribute attribute = (Attribute) attributeList.get(i);

        if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MANAGER)) {
            member.setManager(getBooleanAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT)) {
            member.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_LOCATOR)) {
            member.setLocator(getBooleanAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALDISKUSAGE)) {
            member.setTotalDiskUsage(getLongAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_SERVER)) {
            member.setServer(getBooleanAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALFILEDESCRIPTOROPEN)) {
            member.setTotalFileDescriptorOpen(getLongAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_LOADAVERAGE)) {
            member.setLoadAverage(getDoubleAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE)) {
            member.setThroughputWrites(getFloatAttribute(attribute.getValue(), attribute.getName()));
            member.getThroughputWritesTrend().add(member.getThroughputWrites());
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE)) {
            member.setThroughputReads(getFloatAttribute(attribute.getValue(), attribute.getName()));
            member.getThroughputReadsTrend().add(member.getThroughputReads());
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES)) {
            member.setGarbageCollectionCount(getLongAttribute(attribute.getValue(), attribute.getName()));
            member.getGarbageCollectionSamples().add(member.getGarbageCollectionCount());
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_CURRENTHEAPSIZE)) {
            member.setCurrentHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
            member.getHeapUsageSamples().add(member.getCurrentHeapSize());
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MAXIMUMHEAPSIZE)) {
            member.setMaxHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMTHREADS)) {
            member.setNumThreads(getIntegerAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MEMBERUPTIME)) {
            member.setUptime(getLongAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_HOST)) {
            member.setHost(getStringAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALBYTESONDISK)) {
            member.setTotalBytesOnDisk(getLongAttribute(attribute.getValue(), attribute.getName()));
            member.getTotalBytesOnDiskSamples().add(member.getTotalBytesOnDisk());
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_CPUUSAGE)) {
            member.setCpuUsage(getFloatAttribute(attribute.getValue(), attribute.getName()));
            member.getCpuUsageSamples().add(member.getCpuUsage());
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_HOSTCPUUSAGE)) {
            // Float value is expected for host cpu usage.
            // TODO Remove Float.valueOf() when float value is provided in mbean
            member.setHostCpuUsage(
                    Float.valueOf(getIntegerAttribute(attribute.getValue(), attribute.getName())));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MEMBER)) {
            member.setName(getStringAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_ID)) {
            member.setId(getStringAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS)) {
            member.setGetsRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            member.getGetsPerSecond().add(member.getGetsRate());
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES)) {
            member.setPutsRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            member.getPutsPerSecond().add(member.getPutsRate());
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_OFFHEAPFREESIZE)) {
            member.setOffHeapFreeSize(getLongAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_OFFHEAPUSEDSIZE)) {
            member.setOffHeapUsedSize(getLongAttribute(attribute.getValue(), attribute.getName()));
        }
    }

    // GemFireXD specific attributes
    if (PulseController.getPulseProductSupport().equalsIgnoreCase(PulseConstants.PRODUCT_NAME_GEMFIREXD)) {

        try {
            // get GemFireXD mbeans
            String memberName = mbeanName.getKeyProperty(PulseConstants.MBEAN_KEY_PROPERTY_MEMBER);

            ObjectName sfMemberMbeansObjectName = new ObjectName(
                    PulseConstants.OBJECT_NAME_SF_MEMBER_PATTERN + memberName);

            Set<ObjectName> sfMemberMBeans = this.mbs.queryNames(sfMemberMbeansObjectName, null);
            for (ObjectName sfMemberMBean : sfMemberMBeans) {

                AttributeList attrList = this.mbs.getAttributes(sfMemberMBean,
                        PulseConstants.SF_MEMBER_MBEAN_ATTRIBUTES);
                for (int i = 0; i < attrList.size(); i++) {

                    Attribute attribute = (Attribute) attrList.get(i);

                    if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DATASTORE)) {
                        member.setServer(getBooleanAttribute(attribute.getValue(), attribute.getName()));

                        // Update Server count
                        if (member.isServer()) {
                            cluster.setServerCount(cluster.getServerCount() + 1);
                        }
                    } else if (attribute.getName()
                            .equals(PulseConstants.MBEAN_ATTRIBUTE_NETWORKSERVERCLIENTCONNECTIONSTATS)) {

                        CompositeData nscConnStats = (CompositeData) attribute.getValue();

                        // Update GemFireXD client count
                        member.setNumGemFireXDClients(getLongAttribute(
                                nscConnStats.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSOPEN),
                                PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSOPEN));
                    }
                }
                break;
            }

        } catch (MalformedObjectNameException e) {
            LOGGER.warning(e);
        } catch (NullPointerException e) {
            LOGGER.warning(e);
        }

    }

    return member;
}

From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java

/**
 * function used to get attribute values of Member Region and map them to
 * Member vo//from  ww w . j  a  v  a  2  s.com
 * 
 * @param mbeanName
 *          Member Region MBean
 */
private void updateMemberRegion(ObjectName mbeanName) throws IOException {

    try {
        String memberName = mbeanName.getKeyProperty(PulseConstants.MBEAN_KEY_PROPERTY_MEMBER);

        Cluster.Member member = cluster.getMembersHMap().get(memberName);

        AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.REGION_MBEAN_ATTRIBUTES);

        // retrieve the full path of the region
        String regionFullPathKey = null;
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute attribute = (Attribute) attributeList.get(i);

            if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_FULLPATH)) {
                regionFullPathKey = getStringAttribute(attribute.getValue(), attribute.getName());
                break;
            }
        }

        // if member does not exists defined for this region then create a member
        if (null == member) {
            member = new Cluster.Member();
            member.setName(memberName);
            cluster.getMembersHMap().put(memberName, member);
        }

        // if region with given path exists then update same else add new region
        Cluster.Region region = member.getMemberRegions().get(regionFullPathKey);
        if (null == region) {
            region = new Cluster.Region();
            member.getMemberRegions().put(regionFullPathKey, region);
            member.setTotalRegionCount(member.getTotalRegionCount() + 1);

            // Initialize region attributes
            CompositeData compositeData = (CompositeData) (mbs.invoke(mbeanName,
                    PulseConstants.MBEAN_OPERATION_LISTREGIONATTRIBUTES, null, null));

            if (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_SCOPE)) {
                region.setScope((String) compositeData.get(PulseConstants.COMPOSITE_DATA_KEY_SCOPE));
            }
            if (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_DISKSTORENAME)) {
                region.setDiskStoreName(
                        (String) compositeData.get(PulseConstants.COMPOSITE_DATA_KEY_DISKSTORENAME));
            }
            if (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_DISKSYNCHRONOUS)) {
                region.setDiskSynchronous(
                        (Boolean) compositeData.get(PulseConstants.COMPOSITE_DATA_KEY_DISKSYNCHRONOUS));
            }
        }
        region.setFullPath(regionFullPathKey); // use already retrieved values

        // update the existing or new region
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute attribute = (Attribute) attributeList.get(i);

            if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_FULLPATH)) {
                region.setFullPath(getStringAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE)) {
                region.setDiskReadsRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE)) {
                region.setDiskWritesRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_GETSRATE)) {
                region.setGetsRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_LRUEVICTIONRATE)) {
                region.setLruEvictionRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE)) {
                region.setPutsRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS)) {
                region.setAverageReads(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES)) {
                region.setAverageWrites(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_REGIONTYPE)) {
                region.setRegionType(getStringAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT)) {
                region.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE)) {
                region.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_ENTRYCOUNT)) {
                region.setSystemRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NAME)) {
                region.setName(getStringAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PERSISTENTENABLED)) {
                region.setPersistentEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_GATEWAYENABLED)) {
                region.setWanEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
            }
        }

        // Remove deleted regions from member's regions list
        for (Iterator<String> it = cluster.getDeletedRegions().iterator(); it.hasNext();) {
            String deletedRegion = it.next();
            if (member.getMemberRegions().get(deletedRegion) != null) {
                member.getMemberRegions().remove(deletedRegion);
            }
            member.setTotalRegionCount(member.getMemberRegions().size());
        }
    } catch (InstanceNotFoundException infe) {
        LOGGER.warning(infe);
    } catch (ReflectionException re) {
        LOGGER.warning(re);
    } catch (MBeanException anfe) {
        LOGGER.warning(anfe);
    }
}

From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java

/**
 * function used to get attribute values of Cluster Region and map them to
 * cluster region vo/* w  w  w  .  ja  v a 2  s.c o  m*/
 * 
 * @param mbeanName
 *          Cluster Region MBean
 * @throws IOException
 * @throws ReflectionException
 * @throws IntrospectionException
 * @throws InstanceNotFoundException
 * @throws MBeanException
 * @throws AttributeNotFoundException
 */
private void updateClusterRegion(ObjectName mbeanName) throws IOException {

    try {

        AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.REGION_MBEAN_ATTRIBUTES);

        // retrieve the full path of the region
        String regionFullPath = null;
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute attribute = (Attribute) attributeList.get(i);

            if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_FULLPATH)) {
                regionFullPath = getStringAttribute(attribute.getValue(), attribute.getName());
                break;
            }
        }

        Cluster.Region region = cluster.getClusterRegions().get(regionFullPath);

        if (null == region) {
            region = new Cluster.Region();
        }

        for (int i = 0; i < attributeList.size(); i++) {

            Attribute attribute = (Attribute) attributeList.get(i);

            if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MEMBERS)) {
                String memName[] = (String[]) attribute.getValue();
                region.getMemberName().clear();
                for (int k = 0; k < memName.length; k++) {
                    region.getMemberName().add(memName[k]);
                }
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_FULLPATH)) {
                region.setFullPath(getStringAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE)) {
                region.setDiskReadsRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE)) {
                region.setDiskWritesRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_EMPTYNODES)) {
                region.setEmptyNode(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_GETSRATE)) {
                region.setGetsRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_LRUEVICTIONRATE)) {
                region.setLruEvictionRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE)) {
                region.setPutsRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS)) {
                region.setAverageReads(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES)) {
                region.setAverageWrites(getFloatAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_REGIONTYPE)) {
                region.setRegionType(getStringAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE)) {
                region.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_SYSTEMREGIONENTRYCOUNT)) {
                region.setSystemRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT)) {
                region.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PERSISTENTENABLED)) {
                region.setPersistentEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NAME)) {
                region.setName(getStringAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_GATEWAYENABLED)) {
                region.setWanEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKUSAGE)) {
                region.setDiskUsage(getLongAttribute(attribute.getValue(), attribute.getName()));
            }
        }

        CompositeData compositeData = (CompositeData) (this.mbs.invoke(mbeanName,
                PulseConstants.MBEAN_OPERATION_LISTREGIONATTRIBUTES, null, null));

        if (compositeData != null) {
            if (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_COMPRESSIONCODEC)) {
                String regCompCodec = (String) compositeData
                        .get(PulseConstants.COMPOSITE_DATA_KEY_COMPRESSIONCODEC);
                if (null != regCompCodec) {
                    region.setCompressionCodec(regCompCodec);
                }
            }
            if (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_ENABLEOFFHEAPMEMORY)) {
                region.setEnableOffHeapMemory(
                        (Boolean) compositeData.get(PulseConstants.COMPOSITE_DATA_KEY_ENABLEOFFHEAPMEMORY));
            }
            if (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_HDFSWRITEONLY)) {
                region.setHdfsWriteOnly(
                        (Boolean) compositeData.get(PulseConstants.COMPOSITE_DATA_KEY_HDFSWRITEONLY));
            }
        }

        // TODO : Uncomment below code when sql fire mbean attributes are
        // available
        /*
         * // IF GEMFIREXD if
         * (PulseConstants.PRODUCT_NAME_GEMFIREXD.equalsIgnoreCase(PulseController
         * .getPulseProductSupport())) {
         * 
         * try { String tableName = this.getTableNameFromRegionName(region
         * .getFullPath());
         * 
         * ObjectName tableObjName = new ObjectName(
         * PulseConstants.OBJECT_NAME_TABLE_AGGREGATE_PATTERN + tableName);
         * 
         * AttributeList tableAttributeList = this.mbs.getAttributes(
         * tableObjName, PulseConstants.SF_TABLE_MBEAN_ATTRIBUTES);
         * 
         * for (int i = 0; i < tableAttributeList.size(); i++) {
         * 
         * Attribute attribute = (Attribute) tableAttributeList.get(i);
         * 
         * if (attribute.getName().equals(
         * PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE)) {
         * System.out.println("[GemFireXD] setting entry size");
         * region.setEntrySize(getLongAttribute(attribute.getValue(),
         * attribute.getName())); } else if (attribute.getName().equals(
         * PulseConstants.MBEAN_ATTRIBUTE_NUMBEROFROWS)) {
         * System.out.println("[GemFireXD] setting num of rows");
         * region.setSystemRegionEntryCount(getLongAttribute(
         * attribute.getValue(), attribute.getName())); } } } catch
         * (MalformedObjectNameException e) { LOGGER.warning(e); } catch
         * (NullPointerException e) { LOGGER.warning(e); } }
         */

        // Add to map even if region is present. If region is already there it
        // will be a no-op.
        cluster.addClusterRegion(regionFullPath, region);
        cluster.getDeletedRegions().remove(region.getFullPath());
        // Memory Reads and writes
        region.getPutsPerSecTrend().add(region.getPutsRate());
        region.getGetsPerSecTrend().add(region.getGetsRate());
        // Disk Reads and Writes
        region.getDiskReadsPerSecTrend().add(region.getDiskReadsRate());
        region.getDiskWritesPerSecTrend().add(region.getDiskWritesRate());
        // Average Reads and Writes
        region.getAverageReadsTrend().add(region.getAverageReads());
        region.getAverageWritesTrend().add(region.getAverageWrites());

    } catch (InstanceNotFoundException infe) {
        LOGGER.warning(infe);
    } catch (ReflectionException re) {
        LOGGER.warning(re);
    } catch (MBeanException anfe) {
        LOGGER.warning(anfe);
    }
}

From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java

/**
 * function used to get attribute values of Cluster System and map them to
 * cluster vo//from www . j a v a2 s.  com
 *
 * @param mbeanName
 *          Cluster System MBean
 * @throws IOException
 *
 */
private void updateClusterSystem(ObjectName mbeanName) throws IOException {
    try {
        if (!this.isAddedNotiListner) {
            this.mbs.addNotificationListener(mbeanName, this, null, new Object());
            this.isAddedNotiListner = true;
        }

        if (PulseConstants.PRODUCT_NAME_SQLFIRE.equalsIgnoreCase(PulseController.getPulseProductSupport())) {
            // Reset to zero
            cluster.setServerCount(0);
            cluster.setTotalRegionCount(0);
        } else {
            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:
                if (!PulseConstants.PRODUCT_NAME_SQLFIRE
                        .equalsIgnoreCase(PulseController.getPulseProductSupport())) {
                    // for Gemfire
                    cluster.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                }
                break;
            }
        }

        // SQLFIRE attributes
        if (PulseConstants.PRODUCT_NAME_SQLFIRE.equalsIgnoreCase(PulseController.getPulseProductSupport())) {

            try { // get sqlfire cluster mbean

                ObjectName sfMemberMbeansObjectName = new ObjectName(PulseConstants.OBJECT_NAME_SF_CLUSTER);

                Set<ObjectName> sfCluserMBeans = this.mbs.queryNames(sfMemberMbeansObjectName, null);

                for (ObjectName sfCluserMBean : sfCluserMBeans) {

                    AttributeList attrList = this.mbs.getAttributes(sfCluserMBean,
                            PulseConstants.SF_CLUSTER_MBEAN_ATTRIBUTES);

                    for (int i = 0; i < attrList.size(); i++) {

                        Attribute attribute = (Attribute) attrList.get(i);

                        if (attribute.getName()
                                .equals(PulseConstants.MBEAN_ATTRIBUTE_PROCEDURECALLSINPROGRESS)) {
                            try {
                                cluster.setRunningFunctionCount(
                                        getIntegerAttribute(attribute.getValue(), attribute.getName()));
                            } catch (Exception e) {
                                cluster.setRunningFunctionCount(0);
                                continue;
                            }
                        } else if (attribute.getName()
                                .equals(PulseConstants.MBEAN_ATTRIBUTE_NETWORKSERVERCLIENTCONNECTIONSTATS)) {
                            // set number of cluster's clients
                            CompositeData nscConnStats = (CompositeData) attribute.getValue();

                            cluster.setClientConnectionCount(getLongAttribute(
                                    nscConnStats.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSACTIVE),
                                    PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSACTIVE));
                        }
                    }
                    break;
                }

            } catch (MalformedObjectNameException e) {
                LOGGER.warning(e);
            } catch (NullPointerException e) {
                LOGGER.warning(e);
            }

        }

    } catch (InstanceNotFoundException infe) {
        LOGGER.warning(infe);
    } catch (ReflectionException re) {
        LOGGER.warning(re);
    } catch (MBeanException anfe) {
        LOGGER.warning(anfe);
    }
}

From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java

/**
 * function used for getting member clients from mbean and update the clients
 * information in member object's client arraylist
 *///from   www . java  2s . c o  m
private void updateMemberClient(ObjectName mbeanName) throws IOException {

    try {
        String memberName = mbeanName.getKeyProperty(PulseConstants.MBEAN_KEY_PROPERTY_MEMBER);

        if (cluster.getMembersHMap().containsKey(memberName)) {
            Cluster.Member existingMember = cluster.getMembersHMap().get(memberName);
            HashMap<String, Cluster.Client> memberClientsHM = new HashMap<String, Cluster.Client>();

            existingMember
                    .setMemberPort("" + this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_PORT));

            this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_HOSTNAMEFORCLIENTS_ALT);
            existingMember.setHostnameForClients((String) this.mbs.getAttribute(mbeanName,
                    PulseConstants.MBEAN_ATTRIBUTE_HOSTNAMEFORCLIENTS_ALT));
            existingMember.setBindAddress(
                    (String) this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_BINDADDRESS));

            CompositeData[] compositeData = (CompositeData[]) (this.mbs.invoke(mbeanName,
                    PulseConstants.MBEAN_OPERATION_SHOWALLCLIENTS, null, null));
            for (CompositeData cmd : compositeData) {
                Cluster.Client client = new Cluster.Client();
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CLIENTID)) {
                    client.setId((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CLIENTID));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NAME)) {
                    client.setName((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NAME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME)) {
                    client.setHost((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE)) {
                    client.setQueueSize((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME)) {
                    client.setProcessCpuTime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_UPTIME)) {
                    client.setUptime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_UPTIME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS)) {
                    client.setThreads((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS)) {
                    client.setGets((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS)) {
                    client.setPuts((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) {
                    client.setCpus((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CPUS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) {
                    client.setCpuUsage(0);
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CONNECTED)) {
                    client.setConnected((Boolean) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTED));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CLIENTCQCOUNT)) {
                    client.setClientCQCount((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CLIENTCQCOUNT));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_SUBSCRIPTIONENABLED)) {
                    client.setSubscriptionEnabled(
                            (Boolean) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_SUBSCRIPTIONENABLED));
                }
                memberClientsHM.put(client.getId(), client);
            }
            existingMember.updateMemberClientsHMap(memberClientsHM);
        }
    } catch (InstanceNotFoundException infe) {
        LOGGER.warning(infe);
    } catch (ReflectionException re) {
        LOGGER.warning(re);
    } catch (MBeanException me) {
        LOGGER.warning(me);
    } catch (AttributeNotFoundException anfe) {
        LOGGER.warning(anfe);
    }
}