javax.management.QueryExp Java Examples

The following examples show how to use javax.management.QueryExp. 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: ArrayNotificationBuffer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Set<ObjectName> queryNames(final ObjectName name,
                                   final QueryExp query) {
    PrivilegedAction<Set<ObjectName>> act =
        new PrivilegedAction<Set<ObjectName>>() {
            public Set<ObjectName> run() {
                return mBeanServer.queryNames(name, query);
            }
        };
    try {
        return AccessController.doPrivileged(act);
    } catch (RuntimeException e) {
        logger.fine("queryNames", "Failed to query names: " + e);
        logger.debug("queryNames", e);
        throw e;
    }
}
 
Example #2
Source File: RMIConnector.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)
        throws IOException {
    if (logger.debugOn()) logger.debug("queryMBeans",
            "name=" + name + ", query=" + query);

    final MarshalledObject<QueryExp> sQuery =
            new MarshalledObject<QueryExp>(query);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.queryMBeans(name, sQuery, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.queryMBeans(name, sQuery, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #3
Source File: ArrayNotificationBuffer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private Set<ObjectName> queryNames(final ObjectName name,
                                   final QueryExp query) {
    PrivilegedAction<Set<ObjectName>> act =
        new PrivilegedAction<Set<ObjectName>>() {
            public Set<ObjectName> run() {
                return mBeanServer.queryNames(name, query);
            }
        };
    try {
        return AccessController.doPrivileged(act);
    } catch (RuntimeException e) {
        logger.fine("queryNames", "Failed to query names: " + e);
        logger.debug("queryNames", e);
        throw e;
    }
}
 
Example #4
Source File: RMIConnector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectName> queryNames(ObjectName name,
        QueryExp query)
        throws IOException {
    if (logger.debugOn()) logger.debug("queryNames",
            "name=" + name + ", query=" + query);

    final MarshalledObject<QueryExp> sQuery =
            new MarshalledObject<QueryExp>(query);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.queryNames(name, sQuery, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.queryNames(name, sQuery, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #5
Source File: RMIConnector.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectName> queryNames(ObjectName name,
        QueryExp query)
        throws IOException {
    if (logger.debugOn()) logger.debug("queryNames",
            "name=" + name + ", query=" + query);

    final MarshalledObject<QueryExp> sQuery =
            new MarshalledObject<QueryExp>(query);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.queryNames(name, sQuery, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.queryNames(name, sQuery, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #6
Source File: RMIConnector.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectName> queryNames(ObjectName name,
        QueryExp query)
        throws IOException {
    if (logger.debugOn()) logger.debug("queryNames",
            "name=" + name + ", query=" + query);

    final MarshalledObject<QueryExp> sQuery =
            new MarshalledObject<QueryExp>(query);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.queryNames(name, sQuery, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.queryNames(name, sQuery, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #7
Source File: ArrayNotificationBuffer.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private Set<ObjectName> queryNames(final ObjectName name,
                                   final QueryExp query) {
    PrivilegedAction<Set<ObjectName>> act =
        new PrivilegedAction<Set<ObjectName>>() {
            public Set<ObjectName> run() {
                return mBeanServer.queryNames(name, query);
            }
        };
    try {
        return AccessController.doPrivileged(act);
    } catch (RuntimeException e) {
        logger.fine("queryNames", "Failed to query names: " + e);
        logger.debug("queryNames", e);
        throw e;
    }
}
 
Example #8
Source File: RMIConnector.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectName> queryNames(ObjectName name,
        QueryExp query)
        throws IOException {
    if (logger.debugOn()) logger.debug("queryNames",
            "name=" + name + ", query=" + query);

    final MarshalledObject<QueryExp> sQuery =
            new MarshalledObject<QueryExp>(query);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.queryNames(name, sQuery, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.queryNames(name, sQuery, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #9
Source File: Util.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the specified object is deployed in JBoss Application Server
 *
 * @return if specified object is deployed
 */
public static boolean isObjectDeployed(JBDeploymentManager dm, final ObjectName searchPattern) {
    try {
        dm.invokeRemoteAction(new JBRemoteAction<Boolean>() {

            @Override
            public Boolean action(MBeanServerConnection connection, JBoss5ProfileServiceProxy profileService) throws Exception {
                // FIXME is this reflection really needed
                Method method = connection.getClass().getMethod("queryMBeans", new Class[] {ObjectName.class, QueryExp.class});
                method = fixJava4071957(method);
                Set managedObj = (Set) method.invoke(connection, new Object[] {searchPattern, null});

                return managedObj.size() > 0;
            }

        });
    } catch (ExecutionException ex) {
        LOGGER.log(Level.INFO, null, ex);
    }

    return false;
}
 
Example #10
Source File: RMIConnector.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public Set<ObjectName> queryNames(ObjectName name,
        QueryExp query)
        throws IOException {
    if (logger.debugOn()) logger.debug("queryNames",
            "name=" + name + ", query=" + query);

    final MarshalledObject<QueryExp> sQuery =
            new MarshalledObject<QueryExp>(query);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.queryNames(name, sQuery, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.queryNames(name, sQuery, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #11
Source File: ArrayNotificationBuffer.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private Set<ObjectName> queryNames(final ObjectName name,
                                   final QueryExp query) {
    PrivilegedAction<Set<ObjectName>> act =
        new PrivilegedAction<Set<ObjectName>>() {
            public Set<ObjectName> run() {
                return mBeanServer.queryNames(name, query);
            }
        };
    try {
        return AccessController.doPrivileged(act);
    } catch (RuntimeException e) {
        logger.fine("queryNames", "Failed to query names: " + e);
        logger.debug("queryNames", e);
        throw e;
    }
}
 
Example #12
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 #13
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 #14
Source File: RMIConnector.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public Set<ObjectName> queryNames(ObjectName name,
        QueryExp query)
        throws IOException {
    if (logger.debugOn()) logger.debug("queryNames",
            "name=" + name + ", query=" + query);

    final MarshalledObject<QueryExp> sQuery =
            new MarshalledObject<QueryExp>(query);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.queryNames(name, sQuery, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.queryNames(name, sQuery, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #15
Source File: RMIConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectName> queryNames(ObjectName name,
        QueryExp query)
        throws IOException {
    if (logger.debugOn()) logger.debug("queryNames",
            "name=" + name + ", query=" + query);

    final MarshalledObject<QueryExp> sQuery =
            new MarshalledObject<QueryExp>(query);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.queryNames(name, sQuery, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.queryNames(name, sQuery, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #16
Source File: ArrayNotificationBuffer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private Set<ObjectName> queryNames(final ObjectName name,
                                   final QueryExp query) {
    PrivilegedAction<Set<ObjectName>> act =
        new PrivilegedAction<Set<ObjectName>>() {
            public Set<ObjectName> run() {
                return mBeanServer.queryNames(name, query);
            }
        };
    try {
        return AccessController.doPrivileged(act);
    } catch (RuntimeException e) {
        logger.fine("queryNames", "Failed to query names: " + e);
        logger.debug("queryNames", e);
        throw e;
    }
}
 
Example #17
Source File: RMIConnector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public Set<ObjectName> queryNames(ObjectName name,
        QueryExp query)
        throws IOException {
    if (logger.debugOn()) logger.debug("queryNames",
            "name=" + name + ", query=" + query);

    final MarshalledObject<QueryExp> sQuery =
            new MarshalledObject<QueryExp>(query);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.queryNames(name, sQuery, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.queryNames(name, sQuery, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #18
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 #19
Source File: DefaultMBeanServerInterceptor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Set<ObjectInstance> queryMBeansImpl(ObjectName name,
                                            QueryExp query) {
    // Query the MBeans on the repository
    //
    Set<NamedObject> list = repository.query(name, query);

    return (objectInstancesFromFilteredNamedObjects(list, query));
}
 
Example #20
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 #21
Source File: DefaultMBeanServerInterceptor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        // Check if the caller has the right to invoke 'queryMBeans'
        //
        checkMBeanPermission((String) null, null, null, "queryMBeans");

        // Perform query without "query".
        //
        Set<ObjectInstance> list = queryMBeansImpl(name, null);

        // Check if the caller has the right to invoke 'queryMBeans'
        // on each specific classname/objectname in the list.
        //
        Set<ObjectInstance> allowedList =
            new HashSet<ObjectInstance>(list.size());
        for (ObjectInstance oi : list) {
            try {
                checkMBeanPermission(oi.getClassName(), null,
                                     oi.getObjectName(), "queryMBeans");
                allowedList.add(oi);
            } catch (SecurityException e) {
                // OK: Do not add this ObjectInstance to the list
            }
        }

        // Apply query to allowed MBeans only.
        //
        return filterListOfObjectInstances(allowedList, query);
    } else {
        // Perform query.
        //
        return queryMBeansImpl(name, query);
    }
}
 
Example #22
Source File: DefaultMBeanServerInterceptor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Set<ObjectName> queryNamesImpl(ObjectName name, QueryExp query) {
    // Query the MBeans on the repository
    //
    Set<NamedObject> list = repository.query(name, query);

    return (objectNamesFromFilteredNamedObjects(list, query));
}
 
Example #23
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 #24
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 #25
Source File: OldMBeanServerTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
    Set<ObjectInstance> instances = queryMBeans(name, query);
    Set<ObjectName> names = newSet();
    for (ObjectInstance instance : instances)
        names.add(instance.getObjectName());
    return names;
}
 
Example #26
Source File: DefaultMBeanServerInterceptor.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private Set<ObjectInstance> queryMBeansImpl(ObjectName name,
                                            QueryExp query) {
    // Query the MBeans on the repository
    //
    Set<NamedObject> list = repository.query(name, query);

    return (objectInstancesFromFilteredNamedObjects(list, query));
}
 
Example #27
Source File: DefaultMBeanServerInterceptor.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private Set<ObjectName> queryNamesImpl(ObjectName name, QueryExp query) {
    // Query the MBeans on the repository
    //
    Set<NamedObject> list = repository.query(name, query);

    return (objectNamesFromFilteredNamedObjects(list, query));
}
 
Example #28
Source File: SupportedQueryTypesTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private int doQueryNames(QueryExp query, Set<ObjectName> referenceSet) {
    int errorCount = 0;
    System.out.println(" <*> Perform queryNames call ");

    try {
        // Call queryNames on the remote MBeanServer
        Set<ObjectName> remoteSet =  mbsc.queryNames(null, query);

        // Compare the 2 Set<ObjectName>
        errorCount += checkSet(remoteSet, referenceSet);

        // Cleaning
        remoteSet.clear();

    } catch (Exception e) {
        Utils.printThrowable(e, true);
        errorCount++;
    }

    if ( errorCount == 0 ) {
        System.out.println("\t(OK)");
    } else {
        System.out.println("\t(ERROR) Query failed");
    }

    return errorCount;
}
 
Example #29
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 #30
Source File: QueryMatchTest.java    From dragonwell8_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;
}