Package javax.management

Examples of javax.management.AttributeList


        return result;
    }

    @Override
    public AttributeList getAttributes(final String[] attributes) {
        final AttributeList result = new AttributeList();
        if ( attributes != null ) {
            HealthCheckExecutionResult hcResult = null;
            for(final String key : attributes) {
                final Object defaultValue = this.defaultAttributes.get(key);
                if ( defaultValue != null ) {
                    result.add(new Attribute(key, defaultValue));
                } else {
                    // we assume that a valid attribute name is used
                    // which is requesting a hc result
                    if ( hcResult == null ) {
                        hcResult = this.getHealthCheckResult();
                    }

                    if ( HC_OK_ATTRIBUTE_NAME.equals(key) ) {
                        result.add(new Attribute(key, hcResult.getHealthCheckResult().isOk()));
                    } else if ( HC_LOG_ATTRIBUTE_NAME.equals(key) ) {
                        try {
                            result.add(new Attribute(key, logData(hcResult.getHealthCheckResult())));
                        } catch ( final OpenDataException ignore ) {
                            // we ignore this and simply don't add the attribute
                        }
                    } else if ( HC_STATUS_ATTRIBUTE_NAME.equals(key) ) {
                        result.add(new Attribute(key, hcResult.getHealthCheckResult().getStatus().toString()));
                    } else if ( HC_ELAPSED_TIMED_ATTRIBUTE_NAME.equals(key) ) {
                        result.add(new Attribute(key, hcResult.getElapsedTimeInMs()));
                    } else if ( HC_FINISHED_AT_ATTRIBUTE_NAME.equals(key) ) {
                        result.add(new Attribute(key, hcResult.getFinishedAt()));
                    } else if ( HC_TIMED_OUT_ATTRIBUTE_NAME.equals(key) ) {
                        result.add(new Attribute(key, hcResult.hasTimedOut()));
                    }
                }
            }
        }
View Full Code Here


        throw new MBeanException(new UnsupportedOperationException(getClass().getSimpleName() + " does not support setting attributes."));
    }

    @Override
    public AttributeList setAttributes(final AttributeList attributes) {
        return new AttributeList();
    }
View Full Code Here

            throw new ReflectionException(e);
        }
    }

    public AttributeList getAttributes(String[] attributes) {
        AttributeList results = new AttributeList(attributes.length);
        for (int i = 0; i < attributes.length; i++) {
            String name = attributes[i];
            try {
                Object value = getAttribute(name);
                results.add(new Attribute(name, value));
            } catch (JMException e) {
                log.warn("Exception while getting attribute " + name, e);
            }
        }
        return results;
View Full Code Here

        }
        return results;
    }

    public AttributeList setAttributes(AttributeList attributes) {
        AttributeList results = new AttributeList(attributes.size());
        for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
            Attribute attribute = (Attribute) iterator.next();
            try {
                setAttribute(attribute);
                results.add(attribute);
            } catch (JMException e) {
                log.warn("Exception while setting attribute " + attribute.getName(), e);
            }
        }
        return results;
View Full Code Here

     *
     * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
     */
    public AttributeList getAttributes(String[] attributes) {
        if ( statistics == null ) {
            return new AttributeList();
        }
        AttributeList al = new AttributeList();
        Iterator<Entry<String, TimeSeries>> statIter = statistics.iterator();
        while (statIter.hasNext()) {
            Entry<String, TimeSeries> entry = statIter.next();
            long[] valuePerSecond = entry.getValue().getValuePerSecond();
            al.add(new Attribute("PerSecond_" + entry.getKey(),
                    valuePerSecond[valuePerSecond.length - 1]));
            al.add(new Attribute(
                    "LastMinutePerSecond_" + entry.getKey(),
                    valuePerSecond));
            long[] valuePerMinute = entry.getValue().getValuePerMinute();
            al.add(new Attribute("PerMinute" + entry.getKey(),
                    valuePerMinute[valuePerMinute.length - 1]));
            al.add(new Attribute("LastHourPerMinute_" + entry.getKey(),
                    valuePerMinute));
            long[] valuePerHour = entry.getValue().getValuePerHour();
            al.add(new Attribute("PerHour_" + entry.getKey(),
                    valuePerHour[valuePerHour.length - 1]));
            al.add(new Attribute("LastWeekPerHour_" + entry.getKey(),
                    valuePerHour));
            long[] valuePerWeek = entry.getValue().getValuePerWeek();
            al.add(new Attribute("PerWeek_" + entry.getKey(),
                    valuePerWeek[valuePerWeek.length - 1]));
            al.add(new Attribute("LastYearPerWeek_" + entry.getKey(),
                    valuePerWeek));
        }
        return al;
    }
View Full Code Here

            }
            try {
                this.attributeList = mbeanServer.getAttributes(objectName, names);
            } catch (InstanceNotFoundException e) {
                // ignore
                this.attributeList = new AttributeList();
            } catch (ReflectionException e) {
                // ignore
                this.attributeList = new AttributeList();
            }
        }
        return this.attributeList;
    }
View Full Code Here

            result.put(Constants.PROP_DESCRIPTION, this.info.getDescription());
        }
        result.put(Constants.PROP_CLASSNAME, this.info.getClassName());
        result.put(Constants.PROP_OBJECTNAME, this.objectName.getCanonicalName());

        final AttributeList values = this.getAttributes();
        final Iterator iter = values.iterator();
        while ( iter.hasNext() ) {
            final Attribute a = (Attribute)iter.next();
            final Object value = a.getValue();
            if ( value != null ) {
                result.put(a.getName(), value);
View Full Code Here

                            parent = ((MapResource)parentRsrc).getAttributeResource();
                        }
                        parentAttributesResource = (AttributesResource) parent.getParent();
                        parentMBeanResource = (MBeanResource) parentAttributesResource.getParent();
                    }
                    final AttributeList result = parentMBeanResource.getAttributes();

                    final String attrPath = info.pathInfo.substring("mbean:attributes/".length());
                    final int pos = attrPath.indexOf('/');
                    final String attrName;
                    final String subPath;
                    if ( pos == -1 ) {
                        attrName = attrPath;
                        subPath = null;
                    } else {
                        attrName = attrPath.substring(0, pos);
                        subPath = attrPath.substring(pos + 1);
                    }
                    for(final MBeanAttributeInfo mai : info.mbeanInfo.getAttributes()) {
                        if ( mai.getName().equals(attrName) ) {
                            final Iterator iter = result.iterator();
                            Object value = null;
                            while ( iter.hasNext() && value == null ) {
                                final Attribute a = (Attribute) iter.next();
                                if ( a.getName().equals(attrName) ) {
                                    value = a.getValue();
View Full Code Here

                        parentResource = (AttributesResource)parent;
                    } else {
                        parentResource = (AttributesResource) this.getResource(parent.getResourceResolver(), parent.getPath());
                    }
                    final MBeanResource parentMBeanResource = (MBeanResource)parentResource.getParent();
                    final AttributeList result = parentMBeanResource.getAttributes();

                    final MBeanAttributeInfo[] infos = info.mbeanInfo.getAttributes();
                    final Map<String, MBeanAttributeInfo> infoMap = new HashMap<String, MBeanAttributeInfo>();
                    for(final MBeanAttributeInfo i : infos) {
                        infoMap.put(i.getName(), i);
                    }
                    final Iterator iter = result.iterator();
                    return new Iterator<Resource>() {

                        public void remove() {
                            throw new UnsupportedOperationException("remove");
                        }
View Full Code Here

        objName = new ObjectName("org.apache.flume.source"
          + ":type=" + source.getName());

        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        String strAtts[] = {"Type", "EventReceivedCount", "EventAcceptedCount"};
        AttributeList attrList = mbeanServer.getAttributes(objName, strAtts);

        Assert.assertNotNull(attrList.get(0));
        Assert.assertEquals("Expected Value: Type", "Type",
                ((Attribute) attrList.get(0)).getName());
        Assert.assertEquals("Expected Value: SOURCE", "SOURCE",
                ((Attribute) attrList.get(0)).getValue());

        Assert.assertNotNull(attrList.get(1));
        Assert.assertEquals("Expected Value: EventReceivedCount", "EventReceivedCount",
                ((Attribute) attrList.get(1)).getName());
        Assert.assertEquals("Expected Value: 5", "5",
                ((Attribute) attrList.get(1)).getValue().toString());

        Assert.assertNotNull(attrList.get(2));
        Assert.assertEquals("Expected Value: EventAcceptedCount", "EventAcceptedCount",
                ((Attribute) attrList.get(2)).getName());
        Assert.assertEquals("Expected Value: 5", "5",
                ((Attribute) attrList.get(2)).getValue().toString());

    } catch (Exception ex) {
      System.out.println("Unable to retreive the monitored counter: "
          + objName + ex.getMessage());
    }
View Full Code Here

TOP

Related Classes of javax.management.AttributeList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.