/**
* 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;
}
java类javax.management.Query的实例源码
LocalProcessController.java 文件源码
项目:gemfirexd-oss
阅读 15
收藏 0
点赞 0
评论 0
MBeanProcessController.java 文件源码
项目:gemfirexd-oss
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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;
}
MBeanProcessController.java 文件源码
项目:gemfirexd-oss
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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;
}
QueryParameterSourceJUnitTest.java 文件源码
项目:gemfirexd-oss
阅读 16
收藏 0
点赞 0
评论 0
@Test
public void testCreateQueryParameterSource() throws MalformedObjectNameException {
final ObjectName expectedObjectName = ObjectName.getInstance("GemFire:type=Member,*");
final QueryExp expectedQueryExpression = Query.eq(Query.attr("id"), Query.value("12345"));
final QueryParameterSource query = new QueryParameterSource(expectedObjectName, expectedQueryExpression);
assertNotNull(query);
assertSame(expectedObjectName, query.getObjectName());
assertSame(expectedQueryExpression, query.getQueryExpression());
}
QueryParameterSourceJUnitTest.java 文件源码
项目:gemfirexd-oss
阅读 15
收藏 0
点赞 0
评论 0
@Test
public void testSerialization() throws ClassNotFoundException, IOException, MalformedObjectNameException {
final ObjectName expectedObjectName = ObjectName.getInstance("GemFire:type=Member,*");
final QueryExp expectedQueryExpression = Query.or(
Query.eq(Query.attr("name"), Query.value("myName")),
Query.eq(Query.attr("id"), Query.value("myId"))
);
final QueryParameterSource expectedQuery = new QueryParameterSource(expectedObjectName, expectedQueryExpression);
assertNotNull(expectedQuery);
assertSame(expectedObjectName, expectedQuery.getObjectName());
assertSame(expectedQueryExpression, expectedQuery.getQueryExpression());
final byte[] queryBytes = IOUtils.serializeObject(expectedQuery);
assertNotNull(queryBytes);
assertTrue(queryBytes.length != 0);
final Object queryObj = IOUtils.deserializeObject(queryBytes);
assertTrue(queryObj instanceof QueryParameterSource);
final QueryParameterSource actualQuery = (QueryParameterSource) queryObj;
assertNotSame(expectedQuery, actualQuery);
assertNotNull(actualQuery.getObjectName());
assertEquals(expectedQuery.getObjectName().toString(), actualQuery.getObjectName().toString());
assertNotNull(actualQuery.getQueryExpression());
assertEquals(expectedQuery.getQueryExpression().toString(), actualQuery.getQueryExpression().toString());
}
LauncherLifecycleCommandsDUnitTest.java 文件源码
项目:gemfirexd-oss
阅读 26
收藏 0
点赞 0
评论 0
protected static String getMemberId(final String jmxManagerHost, final int jmxManagerPort, final String memberName)
throws Exception
{
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.connect(new JMXServiceURL(String.format(
"service:jmx:rmi://%1$s/jndi/rmi://%1$s:%2$d/jmxrmi", jmxManagerHost, jmxManagerPort)));
final MBeanServerConnection connection = connector.getMBeanServerConnection();
final ObjectName objectNamePattern = ObjectName.getInstance("GemFire:type=Member,*");
final QueryExp query = Query.eq(Query.attr("Name"), Query.value(memberName));
final Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query);
assertNotNull(objectNames);
assertEquals(1, objectNames.size());
//final ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,Name=" + memberName);
final ObjectName objectName = objectNames.iterator().next();
//System.err.printf("ObjectName for Member with Name (%1$s) is %2$s%n", memberName, objectName);
return ObjectUtils.toString(connection.getAttribute(objectName, "Id"));
}
finally {
IOUtils.close(connector);
}
}
SessionExpireTestRun.java 文件源码
项目:twill
阅读 27
收藏 0
点赞 0
评论 0
private boolean expireAppMasterZKSession(TwillController controller, long timeout, TimeUnit timeoutUnit) {
MBeanServer mbeanServer = MBeanRegistry.getInstance().getPlatformMBeanServer();
QueryExp query = Query.isInstanceOf(new StringValueExp(ConnectionMXBean.class.getName()));
Stopwatch stopwatch = new Stopwatch();
stopwatch.start();
do {
// Find the AM session and expire it
Set<ObjectName> connectionBeans = mbeanServer.queryNames(ObjectName.WILDCARD, query);
for (ObjectName objectName : connectionBeans) {
ConnectionMXBean connectionBean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName,
ConnectionMXBean.class, false);
for (String node : connectionBean.getEphemeralNodes()) {
if (node.endsWith("/instances/" + controller.getRunId().getId())) {
// This is the AM, expire the session.
LOG.info("Kill AM session {}", connectionBean.getSessionId());
connectionBean.terminateSession();
return true;
}
}
}
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
} while (stopwatch.elapsedTime(timeoutUnit) < timeout);
return false;
}
QueryMatchTest.java 文件源码
项目:jdk8u_jdk
阅读 21
收藏 0
点赞 0
评论 0
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;
}
QueryMatchTest.java 文件源码
项目:lookaside_java-1.8.0-openjdk
阅读 16
收藏 0
点赞 0
评论 0
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;
}
AbstractCommandsController.java 文件源码
项目:gemfirexd-oss
阅读 23
收藏 0
点赞 0
评论 0
/**
* Gets the MemberMXBean from the JVM Platform MBeanServer for the specified member, identified by name or ID,
* in the GemFire cluster.
* <p/>
* @param memberNameId a String indicating the name or ID of the GemFire member.
* @return a proxy to the GemFire member's MemberMXBean.
* @throws IllegalStateException if no MemberMXBean could be found for GemFire member with ID or name.
* @throws RuntimeException wrapping the MalformedObjectNameException if the ObjectName pattern is malformed.
* @see #getMBeanServer()
* @see javax.management.JMX
* @see com.gemstone.gemfire.management.MemberMXBean
* @see com.gemstone.gemfire.management.internal.ManagementConstants
*/
protected MemberMXBean getMemberMXBean(final String memberNameId) {
try {
final MBeanServer connection = getMBeanServer();
final String objectNamePattern = ManagementConstants.OBJECTNAME__PREFIX.concat("type=Member,*");
// NOTE possibly throws a MalformedObjectNameException, but this should not happen
final ObjectName objectName = ObjectName.getInstance(objectNamePattern);
final QueryExp query = Query.or(
Query.eq(Query.attr("Name"), Query.value(memberNameId)),
Query.eq(Query.attr("Id"), Query.value(memberNameId))
);
final Set<ObjectName> objectNames = connection.queryNames(objectName, query);
assertState(isMemberMXBeanFound(objectNames),
"No MemberMXBean with ObjectName (%1$s) was found in the Platform MBeanServer for member (%2$s)!",
objectName, memberNameId);
return JMX.newMXBeanProxy(connection, objectNames.iterator().next(), MemberMXBean.class);
}
catch (MalformedObjectNameException e) {
throw new RuntimeException(e);
}
}