Example usage for javax.management Attribute getValue

List of usage examples for javax.management Attribute getValue

Introduction

In this page you can find the example usage for javax.management Attribute getValue.

Prototype

public Object getValue() 

Source Link

Document

Returns an Object that is the value of this attribute.

Usage

From source file:dk.netarkivet.harvester.harvesting.controller.BnfHeritrixController.java

/**
 * Retrieve the values of the crawl service job attributes and
 * add them to the CrawlProgressMessage being put together.
 * @param cpm the crawlProgress message being prepared
 *///from w w w.  jav a  2s .c  o  m
private void fetchCrawlServiceJobAttributes(CrawlProgressMessage cpm) {
    String progressStats = (String) executeMBeanOperation(CrawlServiceJobOperation.progressStatistics);
    CrawlServiceJobInfo jStatus = cpm.getJobStatus();
    String newProgressStats = "?";
    if (progressStats != null) {
        newProgressStats = progressStats;
    }
    jStatus.setProgressStatistics(newProgressStats);

    if (progressStatisticsLegend == null) {
        progressStatisticsLegend = (String) executeMBeanOperation(
                CrawlServiceJobOperation.progressStatisticsLegend);
    }

    List<Attribute> jobAtts = getMBeanAttributes(CrawlServiceJobAttribute.values());

    for (Attribute att : jobAtts) {
        Object value = att.getValue();
        CrawlServiceJobAttribute aCrawlServiceJobAttribute = CrawlServiceJobAttribute.fromString(att.getName());
        switch (aCrawlServiceJobAttribute) {
        case CrawlTime:
            Long elapsedSeconds = -1L;
            if (value != null) {
                elapsedSeconds = (Long) value;
            }
            jStatus.setElapsedSeconds(elapsedSeconds);
            break;
        case CurrentDocRate:
            Double processedDocsPerSec = new Double(-1L);
            if (value != null) {
                processedDocsPerSec = (Double) value;
            }
            jStatus.setCurrentProcessedDocsPerSec(processedDocsPerSec);
            break;
        case CurrentKbRate:
            // NB Heritrix seems to store the average value in
            // KbRate instead of CurrentKbRate...
            // Inverse of doc rates.
            Long processedKBPerSec = -1L;
            if (value != null) {
                processedKBPerSec = (Long) value;
            }
            jStatus.setProcessedKBPerSec(processedKBPerSec);
            break;
        case DiscoveredCount:
            Long discoveredCount = -1L;
            if (value != null) {
                discoveredCount = (Long) value;
            }
            jStatus.setDiscoveredFilesCount(discoveredCount);
            break;
        case DocRate:
            Double docRate = new Double(-1L);
            if (value != null) {
                docRate = (Double) value;
            }
            jStatus.setProcessedDocsPerSec(docRate);
            break;
        case DownloadedCount:
            Long downloadedCount = -1L;
            if (value != null) {
                downloadedCount = (Long) value;
            }
            jStatus.setDownloadedFilesCount(downloadedCount);
            break;
        case FrontierShortReport:
            String frontierShortReport = "?";
            if (value != null) {
                frontierShortReport = (String) value;
            }
            jStatus.setFrontierShortReport(frontierShortReport);
            break;
        case KbRate:
            // NB Heritrix seems to store the average value in
            // KbRate instead of CurrentKbRate...
            // Inverse of doc rates.
            Long kbRate = -1L;
            if (value != null) {
                kbRate = (Long) value;
            }
            jStatus.setCurrentProcessedKBPerSec(kbRate);
            break;
        case Status:
            String newStatus = "?";
            if (value != null) {
                newStatus = (String) value;
            }
            jStatus.setStatus(newStatus);
            if (value != null) {
                String status = (String) value;
                if (CrawlController.PAUSING.equals(status)) {
                    cpm.setStatus(CrawlStatus.CRAWLER_PAUSING);
                } else if (CrawlController.PAUSED.equals(status)) {
                    cpm.setStatus(CrawlStatus.CRAWLER_PAUSED);
                } else {
                    cpm.setStatus(CrawlStatus.CRAWLER_ACTIVE);
                }
            }
            break;
        case ThreadCount:
            Integer currentActiveToecount = -1;
            if (value != null) {
                currentActiveToecount = (Integer) value;
            }
            jStatus.setActiveToeCount(currentActiveToecount);
            break;
        default:
            log.debug("Unhandled attribute: " + aCrawlServiceJobAttribute);
        }
    }
}

From source file:org.eclipse.smila.management.jmx.AgentMBean.java

/**
 * {@inheritDoc}/* w w w  .  j  av a2  s  .c om*/
 * 
 * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
 */
public void setAttribute(final Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    final ModelMBeanAttributeInfo info = _beanInfo.getAttribute(attribute.getName());
    if (info == null) {
        final String msg = "MBean " + _beanInfo.getClassName()
                + " doesnt contain attribute Information for method " + attribute.getName()
                + ", please check if you have defined a gettter and setter for this Attriubute!";
        _log.error(msg);
        throw new AttributeNotFoundException(msg);
    }
    final Descriptor descriptor = info.getDescriptor();
    final String setterMethod = (String) (descriptor.getFieldValue("setMethod"));
    final String setterSignatureClass = (String) (descriptor.getFieldValue("setterSignatureClass"));
    invoke(setterMethod, new Object[] { attribute.getValue() }, new String[] { setterSignatureClass });
}

From source file:org.ow2.proactive_grid_cloud_portal.rm.RMRest.java

@Override
@GET/* ww w  .  ja  v  a2 s  .  co  m*/
@GZIP
@Path("stathistory")
@Produces("application/json")
public String getStatHistory(@HeaderParam("sessionid") String sessionId, @QueryParam("range") String range)
        throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException,
        MalformedObjectNameException, NullPointerException, InterruptedException, NotConnectedException {

    RMProxyUserInterface rm = checkAccess(sessionId);

    // if range String is too large, shorten it
    // to make it recognizable by StatHistoryCaching
    if (range.length() > dataSources.length) {
        range = range.substring(0, dataSources.length);
    }
    // complete range if too short
    while (range.length() < dataSources.length) {
        range += 'a';
    }

    StatHistoryCacheEntry cache = StatHistoryCaching.getInstance().getEntry(range);
    // found unexpired cache entry matching the parameters: return it immediately
    if (cache != null) {
        return cache.getValue();
    }

    long l1 = System.currentTimeMillis();

    ObjectName on = new ObjectName(RMJMXBeans.RUNTIMEDATA_MBEAN_NAME);
    AttributeList attrs = rm.getMBeanAttributes(on, new String[] { "StatisticHistory" });
    Attribute attr = (Attribute) attrs.get(0);
    // content of the RRD4J database backing file
    byte[] rrd4j = (byte[]) attr.getValue();

    File rrd4jDb = File.createTempFile("database", "rr4dj");
    rrd4jDb.deleteOnExit();

    try (OutputStream out = new FileOutputStream(rrd4jDb)) {
        out.write(rrd4j);
    }

    // create RRD4J DB, should be identical to the one held by the RM
    RrdDb db = new RrdDb(rrd4jDb.getAbsolutePath(), true);

    long timeEnd = db.getLastUpdateTime();
    // force float separator for JSON parsing
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
    otherSymbols.setDecimalSeparator('.');
    // formatting will greatly reduce response size
    DecimalFormat formatter = new DecimalFormat("###.###", otherSymbols);

    // construct the JSON response directly in a String
    StringBuilder result = new StringBuilder();
    result.append("{");

    for (int i = 0; i < dataSources.length; i++) {
        String dataSource = dataSources[i];
        char zone = range.charAt(i);
        long timeStart;

        switch (zone) {
        default:
        case 'a': // 1 minute
            timeStart = timeEnd - 60;
            break;
        case 'm': // 10 minute
            timeStart = timeEnd - 60 * 10;
            break;
        case 'h': // 1 hours
            timeStart = timeEnd - 60 * 60;
            break;
        case 'H': // 8 hours
            timeStart = timeEnd - 60 * 60 * 8;
            break;
        case 'd': // 1 day
            timeStart = timeEnd - 60 * 60 * 24;
            break;
        case 'w': // 1 week
            timeStart = timeEnd - 60 * 60 * 24 * 7;
            break;
        case 'M': // 1 month
            timeStart = timeEnd - 60 * 60 * 24 * 28;
            break;
        case 'y': // 1 year
            timeStart = timeEnd - 60 * 60 * 24 * 365;
            break;
        }

        FetchRequest req = db.createFetchRequest(ConsolFun.AVERAGE, timeStart, timeEnd);
        req.setFilter(dataSource);
        FetchData fetchData = req.fetchData();
        result.append("\"").append(dataSource).append("\":[");

        double[] values = fetchData.getValues(dataSource);
        for (int j = 0; j < values.length; j++) {
            if (Double.compare(Double.NaN, values[j]) == 0) {
                result.append("null");
            } else {
                result.append(formatter.format(values[j]));
            }
            if (j < values.length - 1)
                result.append(',');
        }
        result.append(']');
        if (i < dataSources.length - 1)
            result.append(',');
    }
    result.append("}");

    db.close();
    rrd4jDb.delete();

    String ret = result.toString();

    StatHistoryCaching.getInstance().addEntry(range, l1, ret);

    return ret;
}

From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java

public void setAttribute(Attribute attr)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    if (attr == null)
        return;/*from www.ja  v a2  s  .c  om*/

    if (log.isDebugEnabled())
        log.debug("setAttribute " + attr.getName() + "=" + attr.getValue());
    Method setter = (Method) _setter.get(attr.getName());
    if (setter == null)
        throw new AttributeNotFoundException(attr.getName());
    try {
        Object o = _object;
        if (setter.getDeclaringClass().isInstance(this))
            o = this;
        setter.invoke(o, new Object[] { attr.getValue() });
    } catch (IllegalAccessException e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new AttributeNotFoundException(e.toString());
    } catch (InvocationTargetException e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new ReflectionException((Exception) e.getTargetException());
    }
}

From source file:com.cyberway.issue.crawler.settings.ComplexType.java

/** Set the value of a specific attribute of the ComplexType.
 *
 * This method is an extension to the Dynamic MBean specification so that
 * it is possible to set the value for a CrawlerSettings object other than
 * the settings object representing the order.
 *
 * @param settings the settings object for which this attributes value is valid
 * @param attribute The identification of the attribute to be set and the
 *                  value it is to be set to.
 * @throws AttributeNotFoundException is thrown if there is no attribute
 *         with this name.//w ww. j  ava 2s. c o m
 * @throws InvalidAttributeValueException is thrown if the attribute is of
 *         wrong type and cannot be converted to the right type.
 * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
 */
public synchronized final void setAttribute(CrawlerSettings settings, Attribute attribute)
        throws InvalidAttributeValueException, AttributeNotFoundException {

    if (settings == null) {
        settings = globalSettings();
    }

    DataContainer data = getOrCreateDataContainer(settings);
    Object value = attribute.getValue();

    ModuleAttributeInfo attrInfo = (ModuleAttributeInfo) getAttributeInfo(settings.getParent(),
            attribute.getName());

    ModuleAttributeInfo localAttrInfo = (ModuleAttributeInfo) data.getAttributeInfo(attribute.getName());

    // Check if attribute exists
    if (attrInfo == null && localAttrInfo == null) {
        throw new AttributeNotFoundException(attribute.getName());
    }

    // Check if we are overriding and if that is allowed for this attribute
    if (localAttrInfo == null) {
        if (!attrInfo.isOverrideable()) {
            throw new InvalidAttributeValueException("Attribute not overrideable: " + attribute.getName());
        }
        localAttrInfo = new ModuleAttributeInfo(attrInfo);
    }

    // Check if value is of correct type. If not, see if it is
    // a string and try to turn it into right type
    Class typeClass = getDefinition(attribute.getName()).getLegalValueType();
    if (!(typeClass.isInstance(value)) && value instanceof String) {
        try {
            value = SettingsHandler.StringToType((String) value,
                    SettingsHandler.getTypeName(typeClass.getName()));
        } catch (ClassCastException e) {
            throw new InvalidAttributeValueException(
                    "Unable to decode string '" + value + "' into type '" + typeClass.getName() + "'");
        }
    }

    // Check if the attribute value is legal
    FailedCheck error = checkValue(settings, attribute.getName(), value);
    if (error != null) {
        if (error.getLevel() == Level.SEVERE) {
            throw new InvalidAttributeValueException(error.getMessage());
        } else if (error.getLevel() == Level.WARNING) {
            if (!getSettingsHandler().fireValueErrorHandlers(error)) {
                throw new InvalidAttributeValueException(error.getMessage());
            }
        } else {
            getSettingsHandler().fireValueErrorHandlers(error);
        }
    }

    // Everything ok, set it
    localAttrInfo.setType(value);
    Object oldValue = data.put(attribute.getName(), localAttrInfo, value);

    // If the attribute is a complex type other than the old value,
    // make sure that all sub attributes are correctly set
    if (value instanceof ComplexType && value != oldValue) {
        ComplexType complex = (ComplexType) value;
        replaceComplexType(settings, complex);
    }
}

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

/**
 * function used to get attribute values of Gateway Receiver and map them to
 * GatewayReceiver inner class object/*w w w.j a  v a 2  s .c  o  m*/
 * 
 * @param mbeanName
 * @return GatewayReceiver object
 * @throws InstanceNotFoundException
 * @throws IntrospectionException
 * @throws ReflectionException
 * @throws IOException
 * @throws AttributeNotFoundException
 * @throws MBeanException
 * 
 * 
 */
private Cluster.GatewayReceiver initGatewayReceiver(ObjectName mbeanName) throws InstanceNotFoundException,
        IntrospectionException, ReflectionException, IOException, AttributeNotFoundException, MBeanException {

    Cluster.GatewayReceiver gatewayReceiver = new Cluster.GatewayReceiver();

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

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

        if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PORT)) {
            gatewayReceiver.setListeningPort(getIntegerAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_EVENTRECEIVEDDATE)) {
            gatewayReceiver.setLinkThroughput(getFloatAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVEARGEBATCHPROCESSINGTIME)) {
            gatewayReceiver
                    .setAvgBatchProcessingTime(getLongAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_RUNNING)) {
            gatewayReceiver.setStatus(getBooleanAttribute(attribute.getValue(), attribute.getName()));
        }
    }
    return gatewayReceiver;
}

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

/**
 * function used to get attribute values of Gateway Sender and map them to
 * GatewaySender inner class object/*from   w w  w . j a va 2  s  .c o m*/
 * 
 * @param mbeanName
 * @return
 * @throws InstanceNotFoundException
 * @throws IntrospectionException
 * @throws ReflectionException
 * @throws IOException
 * @throws AttributeNotFoundException
 * @throws MBeanException
 */
private Cluster.GatewaySender initGatewaySender(ObjectName mbeanName) throws InstanceNotFoundException,
        IntrospectionException, ReflectionException, IOException, AttributeNotFoundException, MBeanException {

    Cluster.GatewaySender gatewaySender = new Cluster.GatewaySender();
    AttributeList attributeList = this.mbs.getAttributes(mbeanName,
            PulseConstants.GATEWAYSENDER_MBEAN_ATTRIBUTES);

    for (int i = 0; i < attributeList.size(); i++) {
        Attribute attribute = (Attribute) attributeList.get(i);
        if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_EVENTRECEIVEDDATE)) {
            gatewaySender.setLinkThroughput(getFloatAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_BATCHSIZE)) {
            gatewaySender.setBatchSize(getIntegerAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_SENDERID)) {
            gatewaySender.setId(getStringAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_EVENTQUEUESIZE)) {
            gatewaySender.setQueueSize(getIntegerAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_RUNNING)) {
            gatewaySender.setStatus(getBooleanAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PRIMARY)) {
            gatewaySender.setPrimary(getBooleanAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PERSISTENCEENABLED)) {
            gatewaySender.setPersistenceEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PARALLEL)) {
            gatewaySender.setSenderType(getBooleanAttribute(attribute.getValue(), attribute.getName()));
        }
    }
    return gatewaySender;
}

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

/**
 * function used to get attribute values of Cluster Region and map them to cluster region vo
 * /*from w  ww .  ja v  a  2 s.c  o m*/
 * @param mbeanName Cluster Region MBean
 */
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 regionObjectName = mbeanName.getKeyProperty("name");
        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);

            String name = attribute.getName();
            switch (name) {
            case 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]);
                }
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_FULLPATH:
                region.setFullPath(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
                region.setDiskReadsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
                region.setDiskWritesRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_EMPTYNODES:
                region.setEmptyNode(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_GETSRATE:
                region.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_LRUEVICTIONRATE:
                region.setLruEvictionRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE:
                region.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_REGIONTYPE:
                region.setRegionType(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE:
                region.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_SYSTEMREGIONENTRYCOUNT:
                region.setSystemRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT:
                region.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_PERSISTENTENABLED:
                region.setPersistentEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_NAME:
                region.setName(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_GATEWAYENABLED:
                region.setWanEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_DISKUSAGE:
                region.setDiskUsage(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            }
        }

        // add for each member
        updateRegionOnMembers(regionObjectName, regionFullPath, region);

        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());

    } catch (InstanceNotFoundException | ReflectionException infe) {
        logger.warn(infe);
    }
}

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

/**
 * function used to get attribute values of Member Region and map them to Member vo
 * /*from w  w w.j ava2 s. co  m*/
 * @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);

        // Following attributes are not present in 9.0
        // "Members"
        // "EmptyNodes"
        // "SystemRegionEntryCount"
        // "MemberCount"
        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);
        }
        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);
            String name = attribute.getName();
            switch (name) {
            case PulseConstants.MBEAN_ATTRIBUTE_FULLPATH:
                region.setFullPath(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
                region.setDiskReadsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
                region.setDiskWritesRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_GETSRATE:
                region.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_LRUEVICTIONRATE:
                region.setLruEvictionRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE:
                region.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_REGIONTYPE:
                region.setRegionType(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT:
                region.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE:
                region.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_ENTRYCOUNT:
                region.setSystemRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_NAME:
                region.setName(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_PERSISTENTENABLED:
                region.setPersistentEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_GATEWAYENABLED:
                region.setWanEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            }
        }
        /*
         * GemfireXD related code try{// Added for Rolling upgrade changes. Needs to removed once
         * Rolling upgrade handled gracefully CompositeData compositeData = (CompositeData)
         * (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_LISTREGIONATTRIBUTES, null,
         * null));
         * 
         * if (compositeData != null) { if
         * (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_SCOPE)) {
         * region.setScope((String) compositeData .get(PulseConstants.COMPOSITE_DATA_KEY_SCOPE)); }
         * else if (compositeData .containsKey(PulseConstants.COMPOSITE_DATA_KEY_DISKSTORENAME)) {
         * region.setDiskStoreName((String) compositeData
         * .get(PulseConstants.COMPOSITE_DATA_KEY_DISKSTORENAME)); } else if (compositeData
         * .containsKey(PulseConstants.COMPOSITE_DATA_KEY_DISKSYNCHRONOUS)) {
         * region.setDiskSynchronous((Boolean) compositeData
         * .get(PulseConstants.COMPOSITE_DATA_KEY_DISKSYNCHRONOUS)); } } }catch (MBeanException anfe)
         * { logger.warn(anfe); }catch (javax.management.RuntimeMBeanException anfe) {
         * region.setScope(""); region.setDiskStoreName(""); region.setDiskSynchronous(false);
         * //logger.
         * warning("Some of the Pulse elements are not available currently. There might be a GemFire upgrade going on."
         * ); }
         * 
         * 
         * // 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 | ReflectionException infe) {
        logger.warn(infe);
    }
}

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

private void updateClusterStatement(ObjectName mbeanName) throws IOException {

    try {/*from w ww  .  ja  v a  2s . co  m*/

        AttributeList attributeList = this.mbs.getAttributes(mbeanName,
                PulseConstants.STATEMENT_MBEAN_ATTRIBUTES);
        // retrieve the full path of the region
        String statementDefinition = mbeanName.getKeyProperty("name");

        if (isQuoted(statementDefinition)) {
            statementDefinition = ObjectName.unquote(statementDefinition);
        }

        Cluster.Statement statement = cluster.getClusterStatements().get(statementDefinition);

        if (null == statement) {
            statement = new Cluster.Statement();
            statement.setQueryDefinition(statementDefinition);
        }

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

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

            if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMTIMESCOMPILED)) {
                statement.setNumTimesCompiled(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMEXECUTION)) {
                statement.setNumExecution(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMEXECUTIONSINPROGRESS)) {
                statement.setNumExecutionsInProgress(
                        getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMTIMESGLOBALINDEXLOOKUP)) {
                statement.setNumTimesGlobalIndexLookup(
                        getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMROWSMODIFIED)) {
                statement.setNumRowsModified(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PARSETIME)) {
                statement.setParseTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_BINDTIME)) {
                statement.setBindTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_OPTIMIZETIME)) {
                statement.setOptimizeTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_ROUTINGINFOTIME)) {
                statement.setRoutingInfoTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_GENERATETIME)) {
                statement.setGenerateTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALCOMPILATIONTIME)) {
                statement.setTotalCompilationTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_EXECUTIONTIME)) {
                statement.setExecutionTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PROJECTIONTIME)) {
                statement.setProjectionTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALEXECUTIONTIME)) {
                statement.setTotalExecutionTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_ROWSMODIFICATIONTIME)) {
                statement.setRowsModificationTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_QNNUMROWSSEEN)) {
                statement.setqNNumRowsSeen(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_QNMSGSENDTIME)) {
                statement.setqNMsgSendTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_QNMSGSERTIME)) {
                statement.setqNMsgSerTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            }
            if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_QNRESPDESERTIME)) {
                statement.setqNRespDeSerTime(getLongAttribute(attribute.getValue(), attribute.getName()));
            }
        }

        cluster.addClusterStatement(statementDefinition, statement);
        // TODO : to store data for sparklines later
        /*
         * region.getPutsPerSecTrend().add(region.getPutsRate());
         * region.getGetsPerSecTrend().add(region.getGetsRate());
         */
    } catch (InstanceNotFoundException infe) {
        LOGGER.warning(infe);
    } catch (ReflectionException re) {
        LOGGER.warning(re);
    }
}