Java Code Examples for javax.management.Query#and()
The following examples show how to use
javax.management.Query#and() .
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: LocalProcessController.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Builds the QueryExp used to identify the target MBean. * * @param pidAttribute the name of the MBean attribute with the process id to compare against * @param attributes the names of additional MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return the main QueryExp for matching the target MBean */ private QueryExp buildQueryExp(final String pidAttribute, final String[] attributes, final Object[] values) { final QueryExp optionalAttributes = buildOptionalQueryExp(attributes, values); QueryExp constraint; if (optionalAttributes != null) { constraint = Query.and(optionalAttributes, Query.eq( Query.attr(pidAttribute), Query.value(this.pid))); } else { constraint = Query.eq( Query.attr(pidAttribute), Query.value(this.pid)); } return constraint; }
Example 2
Source File: LocalProcessController.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Builds an optional QueryExp to aid in matching the correct MBean using * additional attributes with the specified values. Returns null if no * attributes and values were specified during construction. * * @param attributes the names of additional MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return optional QueryExp to aid in matching the correct MBean */ private QueryExp buildOptionalQueryExp(final String[] attributes, final Object[] values) { QueryExp queryExp = null; for (int i = 0; i < attributes.length; i++) { if (values[i] instanceof Boolean) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value(((Boolean) values[i]))); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value(((Boolean) values[i])))); } } else if (values[i] instanceof Number) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value((Number)values[i])); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value((Number)values[i]))); } } else if (values[i] instanceof String) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value((String)values[i])); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value((String)values[i]))); } } } return queryExp; }
Example 3
Source File: MBeanProcessController.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Builds the QueryExp used to identify the target MBean. * * @param pidAttribute the name of the MBean attribute with the process id to compare against * @param attributes the names of additional MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return the main QueryExp for matching the target MBean */ private QueryExp buildQueryExp(final String pidAttribute, final String[] attributes, final Object[] values) { final QueryExp optionalAttributes = buildOptionalQueryExp(attributes, values); QueryExp constraint; if (optionalAttributes != null) { constraint = Query.and(optionalAttributes, Query.eq( Query.attr(pidAttribute), Query.value(this.pid))); } else { constraint = Query.eq( Query.attr(pidAttribute), Query.value(this.pid)); } return constraint; }
Example 4
Source File: MBeanProcessController.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Builds an optional QueryExp to aid in matching the correct MBean using * additional attributes with the specified values. Returns null if no * attributes and values were specified during construction. * * @param attributes the names of additional MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return optional QueryExp to aid in matching the correct MBean */ private QueryExp buildOptionalQueryExp(final String[] attributes, final Object[] values) { QueryExp queryExp = null; for (int i = 0; i < attributes.length; i++) { if (values[i] instanceof Boolean) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value(((Boolean) values[i]))); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value(((Boolean) values[i])))); } } else if (values[i] instanceof Number) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value((Number)values[i])); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value((Number)values[i]))); } } else if (values[i] instanceof String) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value((String)values[i])); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value((String)values[i]))); } } } return queryExp; }
Example 5
Source File: LocalProcessController.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Builds the QueryExp used to identify the target MBean. * * @param pidAttribute the name of the MBean attribute with the process id to compare against * @param attributes the names of additional MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return the main QueryExp for matching the target MBean */ private QueryExp buildQueryExp(final String pidAttribute, final String[] attributes, final Object[] values) { final QueryExp optionalAttributes = buildOptionalQueryExp(attributes, values); QueryExp constraint; if (optionalAttributes != null) { constraint = Query.and(optionalAttributes, Query.eq( Query.attr(pidAttribute), Query.value(this.pid))); } else { constraint = Query.eq( Query.attr(pidAttribute), Query.value(this.pid)); } return constraint; }
Example 6
Source File: LocalProcessController.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Builds an optional QueryExp to aid in matching the correct MBean using * additional attributes with the specified values. Returns null if no * attributes and values were specified during construction. * * @param attributes the names of additional MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return optional QueryExp to aid in matching the correct MBean */ private QueryExp buildOptionalQueryExp(final String[] attributes, final Object[] values) { QueryExp queryExp = null; for (int i = 0; i < attributes.length; i++) { if (values[i] instanceof Boolean) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value(((Boolean) values[i]))); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value(((Boolean) values[i])))); } } else if (values[i] instanceof Number) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value((Number)values[i])); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value((Number)values[i]))); } } else if (values[i] instanceof String) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value((String)values[i])); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value((String)values[i]))); } } } return queryExp; }
Example 7
Source File: MBeanProcessController.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Builds the QueryExp used to identify the target MBean. * * @param pidAttribute the name of the MBean attribute with the process id to compare against * @param attributes the names of additional MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return the main QueryExp for matching the target MBean */ private QueryExp buildQueryExp(final String pidAttribute, final String[] attributes, final Object[] values) { final QueryExp optionalAttributes = buildOptionalQueryExp(attributes, values); QueryExp constraint; if (optionalAttributes != null) { constraint = Query.and(optionalAttributes, Query.eq( Query.attr(pidAttribute), Query.value(this.pid))); } else { constraint = Query.eq( Query.attr(pidAttribute), Query.value(this.pid)); } return constraint; }
Example 8
Source File: MBeanProcessController.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Builds an optional QueryExp to aid in matching the correct MBean using * additional attributes with the specified values. Returns null if no * attributes and values were specified during construction. * * @param attributes the names of additional MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return optional QueryExp to aid in matching the correct MBean */ private QueryExp buildOptionalQueryExp(final String[] attributes, final Object[] values) { QueryExp queryExp = null; for (int i = 0; i < attributes.length; i++) { if (values[i] instanceof Boolean) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value(((Boolean) values[i]))); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value(((Boolean) values[i])))); } } else if (values[i] instanceof Number) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value((Number)values[i])); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value((Number)values[i]))); } } else if (values[i] instanceof String) { if (queryExp == null) { queryExp = Query.eq( Query.attr(attributes[i]), Query.value((String)values[i])); } else { queryExp = Query.and(queryExp, Query.eq(Query.attr(attributes[i]), Query.value((String)values[i]))); } } } return queryExp; }
Example 9
Source File: LocalProcessControllerJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public void testProcessMBean() throws Exception { final String testName = "testProcessMBean"; final int pid = ProcessUtils.identifyPid(); final Process process = new Process(pid, true); final ObjectName objectName = ObjectName.getInstance( getClass().getSimpleName() + ":testName=" + testName); final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); final ObjectInstance instance = server.registerMBean(process, objectName); assertNotNull(instance); try { // validate basics of the ProcessMBean Set<ObjectName> mbeanNames = server.queryNames(objectName, null); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); assertEquals(1, mbeanNames.size()); final ObjectName name = mbeanNames.iterator().next(); final MBeanInfo info = server.getMBeanInfo(name); final MBeanOperationInfo[] operInfo = info.getOperations(); assertEquals(1, operInfo.length); assertEquals("stop", operInfo[0].getName()); final MBeanAttributeInfo[] attrInfo = info.getAttributes(); assertEquals(2, attrInfo.length); // The order of these attributes is indeterminate // assertEquals("Pid", attrInfo[0].getName()); // assertEquals("Process", attrInfo[1].getName()); assertNotNull(server.getAttribute(name, "Pid")); assertNotNull(server.getAttribute(name, "Process")); assertEquals(pid, server.getAttribute(name, "Pid")); assertEquals(true, server.getAttribute(name, "Process")); // validate query using only Pid attribute QueryExp constraint = Query.eq( Query.attr("Pid"), Query.value(pid)); mbeanNames = server.queryNames(objectName, constraint); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); // validate query with wrong Pid finds nothing constraint = Query.eq( Query.attr("Pid"), Query.value(pid+1)); mbeanNames = server.queryNames(objectName, constraint); assertTrue("Found matching mbeans", mbeanNames.isEmpty()); // validate query using both attributes constraint = Query.and( Query.eq(Query.attr("Process"),Query.value(true)), Query.eq(Query.attr("Pid"),Query.value(pid))); mbeanNames = server.queryNames(objectName, constraint); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); // validate query with wrong attribute finds nothing constraint = Query.and( Query.eq(Query.attr("Process"),Query.value(false)), Query.eq(Query.attr("Pid"),Query.value(pid))); mbeanNames = server.queryNames(objectName, constraint); assertTrue("Found matching mbeans", mbeanNames.isEmpty()); } finally { try { server.unregisterMBean(objectName); } catch (Throwable t) { t.printStackTrace(); } } }
Example 10
Source File: LocalProcessControllerJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public void testProcessMBean() throws Exception { final String testName = "testProcessMBean"; final int pid = ProcessUtils.identifyPid(); final Process process = new Process(pid, true); final ObjectName objectName = ObjectName.getInstance( getClass().getSimpleName() + ":testName=" + testName); final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); final ObjectInstance instance = server.registerMBean(process, objectName); assertNotNull(instance); try { // validate basics of the ProcessMBean Set<ObjectName> mbeanNames = server.queryNames(objectName, null); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); assertEquals(1, mbeanNames.size()); final ObjectName name = mbeanNames.iterator().next(); final MBeanInfo info = server.getMBeanInfo(name); final MBeanOperationInfo[] operInfo = info.getOperations(); assertEquals(1, operInfo.length); assertEquals("stop", operInfo[0].getName()); final MBeanAttributeInfo[] attrInfo = info.getAttributes(); assertEquals(2, attrInfo.length); // The order of these attributes is indeterminate // assertEquals("Pid", attrInfo[0].getName()); // assertEquals("Process", attrInfo[1].getName()); assertNotNull(server.getAttribute(name, "Pid")); assertNotNull(server.getAttribute(name, "Process")); assertEquals(pid, server.getAttribute(name, "Pid")); assertEquals(true, server.getAttribute(name, "Process")); // validate query using only Pid attribute QueryExp constraint = Query.eq( Query.attr("Pid"), Query.value(pid)); mbeanNames = server.queryNames(objectName, constraint); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); // validate query with wrong Pid finds nothing constraint = Query.eq( Query.attr("Pid"), Query.value(pid+1)); mbeanNames = server.queryNames(objectName, constraint); assertTrue("Found matching mbeans", mbeanNames.isEmpty()); // validate query using both attributes constraint = Query.and( Query.eq(Query.attr("Process"),Query.value(true)), Query.eq(Query.attr("Pid"),Query.value(pid))); mbeanNames = server.queryNames(objectName, constraint); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); // validate query with wrong attribute finds nothing constraint = Query.and( Query.eq(Query.attr("Process"),Query.value(false)), Query.eq(Query.attr("Pid"),Query.value(pid))); mbeanNames = server.queryNames(objectName, constraint); assertTrue("Found matching mbeans", mbeanNames.isEmpty()); } finally { try { server.unregisterMBean(objectName); } catch (Throwable t) { t.printStackTrace(); } } }