javax.management.Query类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(13.5k)|赞(0)|评价(0)|浏览(86)

本文整理了Java中javax.management.Query类的一些代码示例,展示了Query类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query类的具体详情如下:
包路径:javax.management.Query
类名称:Query

Query介绍

暂无

代码示例

代码示例来源:origin: apache/geode

/**
 * 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) {
 QueryExp optionalAttributes = buildOptionalQueryExp(attributes, values);
 QueryExp constraint;
 if (optionalAttributes != null) {
  constraint =
    Query.and(optionalAttributes, Query.eq(Query.attr(pidAttribute), Query.value(pid)));
 } else {
  constraint = Query.eq(Query.attr(pidAttribute), Query.value(pid));
 }
 return constraint;
}

代码示例来源:origin: apache/geode

public static MemberMXBean getMemberMXBean(final String serviceName, final String member)
  throws IOException {
 assertState(Gfsh.isCurrentInstanceConnectedAndReady(),
   "Gfsh must be connected in order to get proxy to a GemFire Member MBean.");
 MemberMXBean memberBean = null;
 try {
  String objectNamePattern = ManagementConstants.OBJECTNAME__PREFIX;
  objectNamePattern += (org.apache.geode.internal.lang.StringUtils.isBlank(serviceName)
    ? org.apache.geode.internal.lang.StringUtils.EMPTY
    : "service=" + serviceName + org.apache.geode.internal.lang.StringUtils.COMMA_DELIMITER);
  objectNamePattern += "type=Member,*";
  // NOTE throws a MalformedObjectNameException, however, this should not happen since the
  // ObjectName is constructed
  // here in a conforming pattern
  final ObjectName objectName = ObjectName.getInstance(objectNamePattern);
  final QueryExp query = Query.or(Query.eq(Query.attr("Name"), Query.value(member)),
    Query.eq(Query.attr("Id"), Query.value(member)));
  final Set<ObjectName> memberObjectNames =
    Gfsh.getCurrentInstance().getOperationInvoker().queryNames(objectName, query);
  if (!memberObjectNames.isEmpty()) {
   memberBean = Gfsh.getCurrentInstance().getOperationInvoker()
     .getMBeanProxy(memberObjectNames.iterator().next(), MemberMXBean.class);
  }
 } catch (MalformedObjectNameException e) {
  Gfsh.getCurrentInstance().logSevere(e.getMessage(), e);
 }
 return memberBean;
}

代码示例来源:origin: apache/geode

private ObjectName getObjectName(Class<?> proxyClass, String beanQueryName)
  throws MalformedObjectNameException, IOException {
 ObjectName name = null;
 QueryExp query = null;
 if (proxyClass != null) {
  query = Query.isInstanceOf(Query.value(proxyClass.getName()));
 }
 if (beanQueryName != null) {
  name = ObjectName.getInstance(beanQueryName);
 }
 Set<ObjectInstance> beans = con.queryMBeans(name, query);
 assertEquals("failed to find only one instance of type " + proxyClass.getName() + " with name "
   + beanQueryName, 1, beans.size());
 return ((ObjectInstance) beans.toArray()[0]).getObjectName();
}

代码示例来源:origin: vakinge/oneplatform

private static  int getServerPort(){
    int port = 0;
    try {
      MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
      Set<ObjectName> objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"),
          Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));

      port = Integer.valueOf(objectNames.iterator().next().getKeyProperty("port"));
    }catch (Exception e){
      if(StringUtils.isNotBlank(System.getProperty("jetty.port"))){
        port = Integer.parseInt(System.getProperty("jetty.port"));
      }
    }
    return port;
  }
}

代码示例来源:origin: apache/geode

@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());
}

代码示例来源:origin: locationtech/geowave

private static String getHTTPEndPoint() throws Exception {
 final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
 final QueryExp subQuery1 = Query.match(Query.attr("protocol"), Query.value("HTTP/1.1"));
 final QueryExp subQuery2 = Query.anySubString(Query.attr("protocol"), Query.value("Http11"));
 final QueryExp query = Query.or(subQuery1, subQuery2);
 final Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"), query);

代码示例来源:origin: org.objectweb.jonas/jonas-ejb-2.1

QueryExp match = Query.match(Query.attr("jndiName"), Query.value(jndiName));
QueryExp query = Query.and(match, new DataSourcePropertiesQueryExp());
Set objectNames = mbeanServer.queryNames(J2eeObjectName.getResourceAdapters(J2eeObjectName.ALL, null), query);

代码示例来源:origin: com.github.cjmx/cjmx-ext

private static ValueExp asValueExp(final Object value) {
  if (value instanceof Boolean)
    return Query.value((Boolean)value);
  else if (value instanceof Double)
    return Query.value((Double)value);
  else if (value instanceof Float)
    return Query.value((Float)value);
  else if (value instanceof Integer)
    return Query.value((Integer)value);
  else if (value instanceof Long)
    return Query.value((Long)value);
  else if (value instanceof Number)
    return Query.value((Number)value);
  else if (value instanceof String)
    return Query.value((String)value);
  else
    return Query.value(value.toString());
}

代码示例来源:origin: org.terracotta/terracotta-ee

public static final QueryExp matchAllTerracottaMBeans(UUID id, String[] tunneledDomains) {
 try {
  QueryExp query = Query.or(new ObjectName(MBeanDomain.PUBLIC + ":*,node=" + id),
               new ObjectName(MBeanDomain.INTERNAL + ":*,node=" + id));
  if (tunneledDomains != null) {
   for (String tunneledDomain : tunneledDomains) {
    query = Query.or(query, new ObjectName(tunneledDomain + ":*,node=" + id));
   }
  }
  return query;
 } catch (MalformedObjectNameException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: palantir/atlasdb

/**
   *
   * @param <T>
   * @param mbeanClazz
   * @return proxy interfaces to all beans registered to the server implementing the class mbeanClazz.
   */
  public static <T> Iterable<T> getInstanceBeanProxies(final Class<T> mbeanClazz){
    return Iterables.transform(
        ManagementFactory.getPlatformMBeanServer().queryNames(ObjectName.WILDCARD, Query.isInstanceOf(new StringValueExp(mbeanClazz.getName())))
        , obj -> JMXUtils.newMBeanProxy(ManagementFactory.getPlatformMBeanServer(), obj, mbeanClazz));
  }
}

代码示例来源:origin: apache/geode

@Override
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
 if (query != null)
  return mbs.queryNames(name, Query.and(query, notAccessControlMBean));
 else
  return mbs.queryNames(name, notAccessControlMBean);
}

代码示例来源:origin: org.restcomm/restcomm-connect.commons

@Override
  public HttpConnectorList findConnectors() throws MalformedObjectNameException, NullPointerException, UnknownHostException, AttributeNotFoundException,
      InstanceNotFoundException, MBeanException, ReflectionException {
    LOG.info("Searching Tomcat HTTP connectors.");
    HttpConnectorList httpConnectorList = null;
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    Set<ObjectName> tomcatObjs = mbs.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));

    ArrayList<HttpConnector> endPoints = new ArrayList<HttpConnector>();
    if (tomcatObjs != null && tomcatObjs.size() > 0) {
      for (ObjectName obj : tomcatObjs) {
        String scheme = mbs.getAttribute(obj, "scheme").toString().replaceAll("\"", "");
        String port = obj.getKeyProperty("port").replaceAll("\"", "");
        String address = obj.getKeyProperty("address").replaceAll("\"", "");
        if (LOG.isInfoEnabled()) {
          LOG.info("Tomcat Http Connector: " + scheme + "://" + address + ":" + port);
        }
        HttpConnector httpConnector = new HttpConnector(scheme, address, Integer.parseInt(port), scheme.equalsIgnoreCase("https"));
        endPoints.add(httpConnector);
      }
    }
    if (endPoints.isEmpty()) {
      LOG.warn("Coundn't discover any Http Interfaces");
    }
    httpConnectorList = new HttpConnectorList(endPoints);
    return httpConnectorList;
  }
}

代码示例来源:origin: io.snappydata/gemfire-hydra-tests

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);
 }
}

代码示例来源:origin: apache/helix

Query.match(Query.attr("SensorName"), Query.value("*" + _clusterNamePrefix + "*"));
final Set<ObjectInstance> mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer()
  .queryMBeans(new ObjectName("ClusterStatus:*"), exp1));
final QueryExp exp2 = Query.and(
  Query.not(Query.match(Query.attr("SensorName"), Query.value("MessageQueueStatus.*"))),
  exp1);

代码示例来源:origin: stackoverflow.com

Class[] objs = Arrays.stream(joinPoint.getArgs()).map(item -> item.getClass()).toArray(Class[]::new);
System.out.println("[AspectJ] args interfaces :"+objs);

Class clazz = Class.forName(joinPoint.getSignature().getDeclaringTypeName());
System.out.println("[AspectJ] signature class :"+clazz);

Method method = clazz.getDeclaredMethod(joinPoint.getSignature().getName(), objs) ;
System.out.println("[AspectJ] signature method :"+method);

Query m = method.getDeclaredAnnotation(Query.class) ;
System.out.println("[AspectJ] signature annotation value:"+ (m!=null?m.value():m) );

代码示例来源:origin: org.terracotta/terracotta-l1

public static final QueryExp matchAllTerracottaMBeans(UUID id, String[] tunneledDomains) {
 try {
  QueryExp query = Query.or(new ObjectName(MBeanDomain.PUBLIC + ":*,node=" + id),
               new ObjectName(MBeanDomain.INTERNAL + ":*,node=" + id));
  if (tunneledDomains != null) {
   for (String tunneledDomain : tunneledDomains) {
    query = Query.or(query, new ObjectName(tunneledDomain + ":*,node=" + id));
   }
  }
  return query;
 } catch (MalformedObjectNameException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: com.palantir.atlasdb/atlasdb-commons

/**
   *
   * @param <T>
   * @param mbeanClazz
   * @return proxy interfaces to all beans registered to the server implementing the class mbeanClazz.
   */
  public static <T> Iterable<T> getInstanceBeanProxies(final Class<T> mbeanClazz){
    return Iterables.transform(
        ManagementFactory.getPlatformMBeanServer().queryNames(ObjectName.WILDCARD, Query.isInstanceOf(new StringValueExp(mbeanClazz.getName())))
        , obj -> JMXUtils.newMBeanProxy(ManagementFactory.getPlatformMBeanServer(), obj, mbeanClazz));
  }
}

代码示例来源:origin: apache/geode

@Override
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
 // We need to filter out the AccessControlMXBean so that the clients wouldn't see it
 if (query != null)
  return mbs.queryMBeans(name, Query.and(query, notAccessControlMBean));
 else
  return mbs.queryMBeans(name, notAccessControlMBean);
}

代码示例来源:origin: apache/geode

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])));
  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])));
  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])));

代码示例来源:origin: apache/geode

@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());
}

相关文章