All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.collectd.mx.CollectdMBean Maven / Gradle / Ivy

Go to download

The jcollectd package implements the collectd protocol in Java, making it possible for Java applications to push data into collectd over the wire.

The newest version!
/*
 * jcollectd
 * Copyright (C) 2009 Hyperic, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; only version 2 of the License is applicable.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

package org.collectd.mx;

import java.util.Map;

import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.ReflectionException;

/**
 * Wrap a Map<String,Number> as a DynamicMBean.
 */
public class CollectdMBean implements DynamicMBean {

    private Map _metrics;

    public CollectdMBean(Map metrics) {
        _metrics = metrics;
    }

    public Object getAttribute(String key)
        throws AttributeNotFoundException,
               MBeanException, ReflectionException {

        Number val = _metrics.get(key);
        if (val == null){
            throw new AttributeNotFoundException(key);
        }
        return val;
    }

    public AttributeList getAttributes(String[] attrs) {
        AttributeList result = new AttributeList();
        for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy