Java Code Examples for javax.management.QueryExp#setMBeanServer()

The following examples show how to use javax.management.QueryExp#setMBeanServer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OldMBeanServerTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
    Set<ObjectInstance> instances = newSet();
    if (name == null)
        name = ObjectName.WILDCARD;
    if (query == null)
        query = trueQuery;
    MBeanServer oldMBS = QueryEval.getMBeanServer();
    try {
        query.setMBeanServer(this);
        for (ObjectName n : mbeans.keySet()) {
            if (name.apply(n)) {
                try {
                    if (query.apply(n))
                        instances.add(getObjectInstance(n));
                } catch (Exception e) {
                    // OK: Ignore this MBean in the result
                }
            }
        }
    } finally {
        query.setMBeanServer(oldMBS);
    }
    return instances;
}
 
Example 2
Source File: OldMBeanServerTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
    Set<ObjectInstance> instances = newSet();
    if (name == null)
        name = ObjectName.WILDCARD;
    if (query == null)
        query = trueQuery;
    MBeanServer oldMBS = QueryEval.getMBeanServer();
    try {
        query.setMBeanServer(this);
        for (ObjectName n : mbeans.keySet()) {
            if (name.apply(n)) {
                try {
                    if (query.apply(n))
                        instances.add(getObjectInstance(n));
                } catch (Exception e) {
                    // OK: Ignore this MBean in the result
                }
            }
        }
    } finally {
        query.setMBeanServer(oldMBS);
    }
    return instances;
}
 
Example 3
Source File: OldMBeanServerTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
    Set<ObjectInstance> instances = newSet();
    if (name == null)
        name = ObjectName.WILDCARD;
    if (query == null)
        query = trueQuery;
    MBeanServer oldMBS = QueryEval.getMBeanServer();
    try {
        query.setMBeanServer(this);
        for (ObjectName n : mbeans.keySet()) {
            if (name.apply(n)) {
                try {
                    if (query.apply(n))
                        instances.add(getObjectInstance(n));
                } catch (Exception e) {
                    // OK: Ignore this MBean in the result
                }
            }
        }
    } finally {
        query.setMBeanServer(oldMBS);
    }
    return instances;
}
 
Example 4
Source File: OldMBeanServerTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
    Set<ObjectInstance> instances = newSet();
    if (name == null)
        name = ObjectName.WILDCARD;
    if (query == null)
        query = trueQuery;
    MBeanServer oldMBS = QueryEval.getMBeanServer();
    try {
        query.setMBeanServer(this);
        for (ObjectName n : mbeans.keySet()) {
            if (name.apply(n)) {
                try {
                    if (query.apply(n))
                        instances.add(getObjectInstance(n));
                } catch (Exception e) {
                    // OK: Ignore this MBean in the result
                }
            }
        }
    } finally {
        query.setMBeanServer(oldMBS);
    }
    return instances;
}
 
Example 5
Source File: OldMBeanServerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
    Set<ObjectInstance> instances = newSet();
    if (name == null)
        name = ObjectName.WILDCARD;
    if (query == null)
        query = trueQuery;
    MBeanServer oldMBS = QueryEval.getMBeanServer();
    try {
        query.setMBeanServer(this);
        for (ObjectName n : mbeans.keySet()) {
            if (name.apply(n)) {
                try {
                    if (query.apply(n))
                        instances.add(getObjectInstance(n));
                } catch (Exception e) {
                    // OK: Ignore this MBean in the result
                }
            }
        }
    } finally {
        query.setMBeanServer(oldMBS);
    }
    return instances;
}
 
Example 6
Source File: DefaultMBeanServerInterceptor.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the specified queries to the set of ObjectInstances.
 */
private Set<ObjectInstance>
        filterListOfObjectInstances(Set<ObjectInstance> list,
                                    QueryExp query) {
    // Null query.
    //
    if (query == null) {
        return list;
    } else {
        Set<ObjectInstance> result = new HashSet<ObjectInstance>();
        // Access the filter.
        //
        for (ObjectInstance oi : list) {
            boolean res = false;
            MBeanServer oldServer = QueryEval.getMBeanServer();
            query.setMBeanServer(server);
            try {
                res = query.apply(oi.getObjectName());
            } catch (Exception e) {
                res = false;
            } finally {
                /*
                 * query.setMBeanServer is probably
                 * QueryEval.setMBeanServer so put back the old
                 * value.  Since that method uses a ThreadLocal
                 * variable, this code is only needed for the
                 * unusual case where the user creates a custom
                 * QueryExp that calls a nested query on another
                 * MBeanServer.
                 */
                query.setMBeanServer(oldServer);
            }
            if (res) {
                result.add(oi);
            }
        }
        return result;
    }
}
 
Example 7
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the specified queries to the set of ObjectInstances.
 */
private Set<ObjectInstance>
        filterListOfObjectInstances(Set<ObjectInstance> list,
                                    QueryExp query) {
    // Null query.
    //
    if (query == null) {
        return list;
    } else {
        Set<ObjectInstance> result = new HashSet<ObjectInstance>();
        // Access the filter.
        //
        for (ObjectInstance oi : list) {
            boolean res = false;
            MBeanServer oldServer = QueryEval.getMBeanServer();
            query.setMBeanServer(server);
            try {
                res = query.apply(oi.getObjectName());
            } catch (Exception e) {
                res = false;
            } finally {
                /*
                 * query.setMBeanServer is probably
                 * QueryEval.setMBeanServer so put back the old
                 * value.  Since that method uses a ThreadLocal
                 * variable, this code is only needed for the
                 * unusual case where the user creates a custom
                 * QueryExp that calls a nested query on another
                 * MBeanServer.
                 */
                query.setMBeanServer(oldServer);
            }
            if (res) {
                result.add(oi);
            }
        }
        return result;
    }
}
 
Example 8
Source File: DefaultMBeanServerInterceptor.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the specified queries to the set of ObjectInstances.
 */
private Set<ObjectInstance>
        filterListOfObjectInstances(Set<ObjectInstance> list,
                                    QueryExp query) {
    // Null query.
    //
    if (query == null) {
        return list;
    } else {
        Set<ObjectInstance> result = new HashSet<ObjectInstance>();
        // Access the filter.
        //
        for (ObjectInstance oi : list) {
            boolean res = false;
            MBeanServer oldServer = QueryEval.getMBeanServer();
            query.setMBeanServer(server);
            try {
                res = query.apply(oi.getObjectName());
            } catch (Exception e) {
                res = false;
            } finally {
                /*
                 * query.setMBeanServer is probably
                 * QueryEval.setMBeanServer so put back the old
                 * value.  Since that method uses a ThreadLocal
                 * variable, this code is only needed for the
                 * unusual case where the user creates a custom
                 * QueryExp that calls a nested query on another
                 * MBeanServer.
                 */
                query.setMBeanServer(oldServer);
            }
            if (res) {
                result.add(oi);
            }
        }
        return result;
    }
}
 
Example 9
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the specified queries to the set of ObjectInstances.
 */
private Set<ObjectInstance>
        filterListOfObjectInstances(Set<ObjectInstance> list,
                                    QueryExp query) {
    // Null query.
    //
    if (query == null) {
        return list;
    } else {
        Set<ObjectInstance> result = new HashSet<ObjectInstance>();
        // Access the filter.
        //
        for (ObjectInstance oi : list) {
            boolean res = false;
            MBeanServer oldServer = QueryEval.getMBeanServer();
            query.setMBeanServer(server);
            try {
                res = query.apply(oi.getObjectName());
            } catch (Exception e) {
                res = false;
            } finally {
                /*
                 * query.setMBeanServer is probably
                 * QueryEval.setMBeanServer so put back the old
                 * value.  Since that method uses a ThreadLocal
                 * variable, this code is only needed for the
                 * unusual case where the user creates a custom
                 * QueryExp that calls a nested query on another
                 * MBeanServer.
                 */
                query.setMBeanServer(oldServer);
            }
            if (res) {
                result.add(oi);
            }
        }
        return result;
    }
}
 
Example 10
Source File: DefaultMBeanServerInterceptor.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Applies the specified queries to the set of ObjectInstances.
 */
private Set<ObjectInstance>
        filterListOfObjectInstances(Set<ObjectInstance> list,
                                    QueryExp query) {
    // Null query.
    //
    if (query == null) {
        return list;
    } else {
        Set<ObjectInstance> result = new HashSet<ObjectInstance>();
        // Access the filter.
        //
        for (ObjectInstance oi : list) {
            boolean res = false;
            MBeanServer oldServer = QueryEval.getMBeanServer();
            query.setMBeanServer(server);
            try {
                res = query.apply(oi.getObjectName());
            } catch (Exception e) {
                res = false;
            } finally {
                /*
                 * query.setMBeanServer is probably
                 * QueryEval.setMBeanServer so put back the old
                 * value.  Since that method uses a ThreadLocal
                 * variable, this code is only needed for the
                 * unusual case where the user creates a custom
                 * QueryExp that calls a nested query on another
                 * MBeanServer.
                 */
                query.setMBeanServer(oldServer);
            }
            if (res) {
                result.add(oi);
            }
        }
        return result;
    }
}
 
Example 11
Source File: QueryMatchTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static int query(MBeanServer mbs,
                         String pattern,
                         String[][] data) throws Exception {

    int error = 0;

    System.out.println("\nAttribute Value Pattern = " + pattern + "\n");
    for (int i = 0; i < data.length; i++) {
        ObjectName on = new ObjectName("domain:type=Simple,pattern=" +
                                       ObjectName.quote(pattern) +
                                       ",name=" + i);
        Simple s = new Simple(data[i][0]);
        mbs.registerMBean(s, on);
        QueryExp q =
            Query.match(Query.attr("StringNumber"), Query.value(pattern));
        q.setMBeanServer(mbs);
        boolean r = q.apply(on);
        System.out.print("Attribute Value = " +
            mbs.getAttribute(on, "StringNumber"));
        if (r && "OK".equals(data[i][1])) {
            System.out.println(" OK");
        } else if (!r && "KO".equals(data[i][1])) {
            System.out.println(" KO");
        } else {
            System.out.println(" Error");
            error++;
        }
    }

    return error;
}
 
Example 12
Source File: QueryMatchTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static int query(MBeanServer mbs,
                         String pattern,
                         String[][] data) throws Exception {

    int error = 0;

    System.out.println("\nAttribute Value Pattern = " + pattern + "\n");
    for (int i = 0; i < data.length; i++) {
        ObjectName on = new ObjectName("domain:type=Simple,pattern=" +
                                       ObjectName.quote(pattern) +
                                       ",name=" + i);
        Simple s = new Simple(data[i][0]);
        mbs.registerMBean(s, on);
        QueryExp q =
            Query.match(Query.attr("StringNumber"), Query.value(pattern));
        q.setMBeanServer(mbs);
        boolean r = q.apply(on);
        System.out.print("Attribute Value = " +
            mbs.getAttribute(on, "StringNumber"));
        if (r && "OK".equals(data[i][1])) {
            System.out.println(" OK");
        } else if (!r && "KO".equals(data[i][1])) {
            System.out.println(" KO");
        } else {
            System.out.println(" Error");
            error++;
        }
    }

    return error;
}
 
Example 13
Source File: DefaultMBeanServerInterceptor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the specified queries to the set of ObjectInstances.
 */
private Set<ObjectInstance>
        filterListOfObjectInstances(Set<ObjectInstance> list,
                                    QueryExp query) {
    // Null query.
    //
    if (query == null) {
        return list;
    } else {
        Set<ObjectInstance> result = new HashSet<ObjectInstance>();
        // Access the filter.
        //
        for (ObjectInstance oi : list) {
            boolean res = false;
            MBeanServer oldServer = QueryEval.getMBeanServer();
            query.setMBeanServer(server);
            try {
                res = query.apply(oi.getObjectName());
            } catch (Exception e) {
                res = false;
            } finally {
                /*
                 * query.setMBeanServer is probably
                 * QueryEval.setMBeanServer so put back the old
                 * value.  Since that method uses a ThreadLocal
                 * variable, this code is only needed for the
                 * unusual case where the user creates a custom
                 * QueryExp that calls a nested query on another
                 * MBeanServer.
                 */
                query.setMBeanServer(oldServer);
            }
            if (res) {
                result.add(oi);
            }
        }
        return result;
    }
}
 
Example 14
Source File: QueryMatchTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static int query(MBeanServer mbs,
                         String pattern,
                         String[][] data) throws Exception {

    int error = 0;

    System.out.println("\nAttribute Value Pattern = " + pattern + "\n");
    for (int i = 0; i < data.length; i++) {
        ObjectName on = new ObjectName("domain:type=Simple,pattern=" +
                                       ObjectName.quote(pattern) +
                                       ",name=" + i);
        Simple s = new Simple(data[i][0]);
        mbs.registerMBean(s, on);
        QueryExp q =
            Query.match(Query.attr("StringNumber"), Query.value(pattern));
        q.setMBeanServer(mbs);
        boolean r = q.apply(on);
        System.out.print("Attribute Value = " +
            mbs.getAttribute(on, "StringNumber"));
        if (r && "OK".equals(data[i][1])) {
            System.out.println(" OK");
        } else if (!r && "KO".equals(data[i][1])) {
            System.out.println(" KO");
        } else {
            System.out.println(" Error");
            error++;
        }
    }

    return error;
}
 
Example 15
Source File: QueryMatchTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static int query(MBeanServer mbs,
                         String pattern,
                         String[][] data) throws Exception {

    int error = 0;

    System.out.println("\nAttribute Value Pattern = " + pattern + "\n");
    for (int i = 0; i < data.length; i++) {
        ObjectName on = new ObjectName("domain:type=Simple,pattern=" +
                                       ObjectName.quote(pattern) +
                                       ",name=" + i);
        Simple s = new Simple(data[i][0]);
        mbs.registerMBean(s, on);
        QueryExp q =
            Query.match(Query.attr("StringNumber"), Query.value(pattern));
        q.setMBeanServer(mbs);
        boolean r = q.apply(on);
        System.out.print("Attribute Value = " +
            mbs.getAttribute(on, "StringNumber"));
        if (r && "OK".equals(data[i][1])) {
            System.out.println(" OK");
        } else if (!r && "KO".equals(data[i][1])) {
            System.out.println(" KO");
        } else {
            System.out.println(" Error");
            error++;
        }
    }

    return error;
}
 
Example 16
Source File: DefaultMBeanServerInterceptor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the specified queries to the set of ObjectInstances.
 */
private Set<ObjectInstance>
        filterListOfObjectInstances(Set<ObjectInstance> list,
                                    QueryExp query) {
    // Null query.
    //
    if (query == null) {
        return list;
    } else {
        Set<ObjectInstance> result = new HashSet<ObjectInstance>();
        // Access the filter.
        //
        for (ObjectInstance oi : list) {
            boolean res = false;
            MBeanServer oldServer = QueryEval.getMBeanServer();
            query.setMBeanServer(server);
            try {
                res = query.apply(oi.getObjectName());
            } catch (Exception e) {
                res = false;
            } finally {
                /*
                 * query.setMBeanServer is probably
                 * QueryEval.setMBeanServer so put back the old
                 * value.  Since that method uses a ThreadLocal
                 * variable, this code is only needed for the
                 * unusual case where the user creates a custom
                 * QueryExp that calls a nested query on another
                 * MBeanServer.
                 */
                query.setMBeanServer(oldServer);
            }
            if (res) {
                result.add(oi);
            }
        }
        return result;
    }
}
 
Example 17
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the specified queries to the set of ObjectInstances.
 */
private Set<ObjectInstance>
        filterListOfObjectInstances(Set<ObjectInstance> list,
                                    QueryExp query) {
    // Null query.
    //
    if (query == null) {
        return list;
    } else {
        Set<ObjectInstance> result = new HashSet<ObjectInstance>();
        // Access the filter.
        //
        for (ObjectInstance oi : list) {
            boolean res = false;
            MBeanServer oldServer = QueryEval.getMBeanServer();
            query.setMBeanServer(server);
            try {
                res = query.apply(oi.getObjectName());
            } catch (Exception e) {
                res = false;
            } finally {
                /*
                 * query.setMBeanServer is probably
                 * QueryEval.setMBeanServer so put back the old
                 * value.  Since that method uses a ThreadLocal
                 * variable, this code is only needed for the
                 * unusual case where the user creates a custom
                 * QueryExp that calls a nested query on another
                 * MBeanServer.
                 */
                query.setMBeanServer(oldServer);
            }
            if (res) {
                result.add(oi);
            }
        }
        return result;
    }
}
 
Example 18
Source File: DefaultMBeanServerInterceptor.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the specified queries to the set of ObjectInstances.
 */
private Set<ObjectInstance>
        filterListOfObjectInstances(Set<ObjectInstance> list,
                                    QueryExp query) {
    // Null query.
    //
    if (query == null) {
        return list;
    } else {
        Set<ObjectInstance> result = new HashSet<ObjectInstance>();
        // Access the filter.
        //
        for (ObjectInstance oi : list) {
            boolean res = false;
            MBeanServer oldServer = QueryEval.getMBeanServer();
            query.setMBeanServer(server);
            try {
                res = query.apply(oi.getObjectName());
            } catch (Exception e) {
                res = false;
            } finally {
                /*
                 * query.setMBeanServer is probably
                 * QueryEval.setMBeanServer so put back the old
                 * value.  Since that method uses a ThreadLocal
                 * variable, this code is only needed for the
                 * unusual case where the user creates a custom
                 * QueryExp that calls a nested query on another
                 * MBeanServer.
                 */
                query.setMBeanServer(oldServer);
            }
            if (res) {
                result.add(oi);
            }
        }
        return result;
    }
}
 
Example 19
Source File: QuerySubstringTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static int query(MBeanServer mbs,
                         int type,
                         String substring,
                         String[][] data) throws Exception {

    int error = 0;

    String querySubString = null;
    switch (type) {
        case 1:
            querySubString = "InitialSubString";
            break;
        case 2:
            querySubString = "AnySubString";
            break;
        case 3:
            querySubString = "FinalSubString";
            break;
    }

    System.out.println("\n" + querySubString + " = " + substring + "\n");

    for (int i = 0; i < data.length; i++) {
        ObjectName on = new ObjectName("test:type=Simple,query=" +
                                       querySubString + ",name=" + i);
        Simple s = new Simple(data[i][0]);
        mbs.registerMBean(s, on);
        QueryExp q = null;
        switch (type) {
            case 1:
                q = Query.initialSubString(Query.attr("String"),
                                           Query.value(substring));
                break;
            case 2:
                q = Query.anySubString(Query.attr("String"),
                                       Query.value(substring));
                break;
            case 3:
                q = Query.finalSubString(Query.attr("String"),
                                         Query.value(substring));
                break;
        }
        q.setMBeanServer(mbs);
        boolean r = q.apply(on);
        System.out.print("Attribute Value = " +
            mbs.getAttribute(on, "String"));
        if (r && "OK".equals(data[i][type])) {
            System.out.println(" OK");
        } else if (!r && "KO".equals(data[i][type])) {
            System.out.println(" KO");
        } else {
            System.out.println(" Error");
            error++;
        }
    }

    return error;
}
 
Example 20
Source File: QuerySubstringTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static int query(MBeanServer mbs,
                         int type,
                         String substring,
                         String[][] data) throws Exception {

    int error = 0;

    String querySubString = null;
    switch (type) {
        case 1:
            querySubString = "InitialSubString";
            break;
        case 2:
            querySubString = "AnySubString";
            break;
        case 3:
            querySubString = "FinalSubString";
            break;
    }

    System.out.println("\n" + querySubString + " = " + substring + "\n");

    for (int i = 0; i < data.length; i++) {
        ObjectName on = new ObjectName("test:type=Simple,query=" +
                                       querySubString + ",name=" + i);
        Simple s = new Simple(data[i][0]);
        mbs.registerMBean(s, on);
        QueryExp q = null;
        switch (type) {
            case 1:
                q = Query.initialSubString(Query.attr("String"),
                                           Query.value(substring));
                break;
            case 2:
                q = Query.anySubString(Query.attr("String"),
                                       Query.value(substring));
                break;
            case 3:
                q = Query.finalSubString(Query.attr("String"),
                                         Query.value(substring));
                break;
        }
        q.setMBeanServer(mbs);
        boolean r = q.apply(on);
        System.out.print("Attribute Value = " +
            mbs.getAttribute(on, "String"));
        if (r && "OK".equals(data[i][type])) {
            System.out.println(" OK");
        } else if (!r && "KO".equals(data[i][type])) {
            System.out.println(" KO");
        } else {
            System.out.println(" Error");
            error++;
        }
    }

    return error;
}