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

com.jn.langx.management.BaseService Maven / Gradle / Ivy

Go to download

Java lang extensions for java6+, a supplement to , replacement of a Guava, commons-lang. Core utilities, Collection utilities, IO utilities, Cache, Configuration library ...

There is a newer version: 4.8.2
Show newest version
package com.jn.langx.management;

import com.jn.langx.util.struct.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.Attribute;
import javax.management.ObjectName;
import java.util.Collection;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;

public abstract class BaseService implements MBeanService {
    private static final Logger logger;
    protected Hashtable defaultOptions;
    protected String domain;
    protected JMXConnection conn;

    public BaseService() {
        this.defaultOptions = new Hashtable();
        this.init();
    }

    protected abstract void init();

    protected ObjectName createObjectName(final Hashtable table) {
        final Hashtable options = new Hashtable();
        options.putAll(this.defaultOptions);
        if (table != null) {
            options.putAll(table);
        }
        ObjectName oname = null;
        try {
            oname = new ObjectName(this.domain, options);
        } catch (Exception ex) {
        }
        BaseService.logger.debug("create an ObjectName : " + oname);
        return oname;
    }

    @Override
    public List> getMBeanAttrs(final Hashtable options, final Collection attributeNames) {
        final ObjectName oname = this.createObjectName(null);
        List attrList = null;
        if (attributeNames != null && !attributeNames.isEmpty()) {
            attrList = this.conn.getAttributes(oname, (String[]) attributeNames.toArray(new String[0])).asList();
        }
        if (attrList == null) {
            BaseService.logger.warn("The attributeNames is not specified");
            return null;
        }
        final List> mbean = new LinkedList>();
        for (final Attribute attr : attrList) {
            final String attrName = attr.getName();
            final Object attrValue = attr.getValue();
            mbean.add(new Entry(attrName, attrValue));
        }
        return mbean;
    }

    static {
        logger = LoggerFactory.getLogger(BaseService.class);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy