Java Management query Connection By - Java javax.management

Java examples for javax.management:ObjectName

Description

Java Management query Connection By

Demo Code


//package com.java2s;
import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import javax.management.ObjectName;

import java.util.Hashtable;
import java.util.Set;

public class Main {
    public static Set<ObjectInstance> queryConnectionBy(
            MBeanServerConnection connection, ObjectName objectName)
            throws Exception {
        return connection.queryMBeans(objectName, null);
    }/*from  w w  w.  ja v a  2 s. c  om*/

    public static Set<ObjectInstance> queryConnectionBy(
            MBeanServerConnection connection, String domain, String name,
            String type, String scope) throws Exception {
        return queryConnectionBy(connection,
                getObjectName(domain, name, type, scope));
    }

    public static ObjectName getObjectName(String domain, String name,
            String type, String scope) throws Exception {
        Hashtable<String, String> map = new Hashtable<String, String>();
        if (name != null)
            map.put("name", name);
        if (type != null)
            map.put("type", type);
        if (scope != null)
            map.put("scope", scope);
        return ObjectName.getInstance(domain, map);
    }
}

Related Tutorials