javax.management.Query.value()方法的使用及代码示例

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

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

Query.value介绍

暂无

代码示例

代码示例来源: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: 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

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

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

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

代码示例来源: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: 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: 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: 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: spring-projects/sts4

protected Set<ObjectName> getNonBootSpringLiveMBeans() {
  if (this.nonBootLiveMBeanNames == null) {
    try {
      this.nonBootLiveMBeanNames = withTimeout(() -> withJmxConnector(jmxConnector -> {
        MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
        QueryExp queryExp = Query.isInstanceOf(Query.value("org.springframework.context.support.LiveBeansView"));
        return connection.queryNames(null, queryExp);
      }));
    } catch (Exception e) {
      e.printStackTrace();
      this.nonBootLiveMBeanNames = Collections.emptySet();
    }
  }
  return this.nonBootLiveMBeanNames;
}

代码示例来源: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/jackrabbit-oak

private Set<ObjectInstance> getMetricMbeans() throws MalformedObjectNameException {
  QueryExp q = Query.isInstanceOf(Query.value(JmxReporter.MetricMBean.class.getName()));
  return server.queryMBeans(new ObjectName("org.apache.jackrabbit.oak:*"), q);
}

代码示例来源:origin: org.apache.geode/gemfire-core

/**
 * 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;
}

代码示例来源:origin: org.apache.geode/gemfire-core

/**
 * 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;
}

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

/**
 * 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;
}

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

/**
 * 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;
}

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

/**
  * Queries for all MBeans from the MBean Server and only looks at the relevant MBean and gets its metric numbers.
  *
  */
 private void updateMetrics() {
  try {
   QueryExp exp = Query.match(Query.attr("SensorName"), Query.value("*" + CLUSTER_NAME + "*"));
   Set<ObjectInstance> mbeans =
     new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
   for (ObjectInstance instance : mbeans) {
    ObjectName beanName = instance.getObjectName();
    if (beanName.toString().equals("ClusterStatus:cluster=" + CLUSTER_NAME)) {
     MBeanInfo info = _server.getMBeanInfo(beanName);
     MBeanAttributeInfo[] infos = info.getAttributes();
     for (MBeanAttributeInfo infoItem : infos) {
      Object val = _server.getAttribute(beanName, infoItem.getName());
      _beanValueMap.put(infoItem.getName(), val);
     }
    }
   }
  } catch (Exception e) {
   // update failed
  }
 }
}

代码示例来源:origin: org.apache.geode/gemfire-core

protected MemberMXBean getMemberMXBean(final String serviceName, final String member) throws IOException {
 assertState(isConnectedAndReady(), "Gfsh must be connected in order to get proxy to a GemFire Member MBean.");
 MemberMXBean memberBean = null;
 try {
  String objectNamePattern = ManagementConstants.OBJECTNAME__PREFIX;
  objectNamePattern += (StringUtils.isBlank(serviceName) ? StringUtils.EMPTY_STRING
   : "service=" + serviceName + 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 = getGfsh().getOperationInvoker().queryNames(objectName, query);
  if (!memberObjectNames.isEmpty()) {
   memberBean = getGfsh().getOperationInvoker().getMBeanProxy(memberObjectNames.iterator().next(), MemberMXBean.class);
  }
 }
 catch (MalformedObjectNameException e) {
  getGfsh().logSevere(e.getMessage(), e);
 }
 return memberBean;
}

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

protected MemberMXBean getMemberMXBean(final String serviceName, final String member) throws IOException {
 assertState(isConnectedAndReady(), "Gfsh must be connected in order to get proxy to a GemFire Member MBean.");
 MemberMXBean memberBean = null;
 try {
  String objectNamePattern = ManagementConstants.OBJECTNAME__PREFIX;
  objectNamePattern += (StringUtils.isBlank(serviceName) ? StringUtils.EMPTY_STRING
   : "service=" + serviceName + 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 = getGfsh().getOperationInvoker().queryNames(objectName, query);
  if (!memberObjectNames.isEmpty()) {
   memberBean = getGfsh().getOperationInvoker().getMBeanProxy(memberObjectNames.iterator().next(), MemberMXBean.class);
  }
 }
 catch (MalformedObjectNameException e) {
  getGfsh().logSevere(e.getMessage(), e);
 }
 return memberBean;
}

相关文章