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

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

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

Query.attr介绍

暂无

代码示例

代码示例来源: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: 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: 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: 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: org.objectweb.jonas/jonas-ejb-2.1

QueryExp match = Query.match(Query.attr("jndiName"),
               Query.value(jndiName));
Set objectNames = mbeanServer.queryNames(J2eeObjectName.getJDBCDataSources(J2eeObjectName.ALL, null),

代码示例来源: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.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: 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: io.snappydata/gemfire-hydra-tests

final QueryExp constraint = Query.eq(Query.attr("Name"), Query.value(getUniqueName()));

代码示例来源: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: io.snappydata/gemfire-hydra-tests

final QueryExp constraint = Query.eq(Query.attr("ProcessId"),Query.value(ProcessUtils.identifyPid()));

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

相关文章