javax.management.ObjectName.isPattern()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(112)

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

ObjectName.isPattern介绍

暂无

代码示例

代码示例来源:origin: networknt/light-4j

private ObjectName getObjectName() throws IOException {
    if (objectName.isPattern()) {
      Set<ObjectName> foundNames = mBeanServerConn.queryNames(objectName, null);
      if (foundNames.size() == 1) {
        return foundNames.iterator().next();
      }
    }
    return objectName;
  }
}

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

@Override
public ObjectName createName(String type, String domain, String name) {
  try {
    if (name.startsWith(domain)) {
      ObjectName objectName = new ObjectName(name);
      return objectName;
    }
    ObjectName objectName = new ObjectName(domain, "name", name);
    if (objectName.isPattern()) {
      objectName = new ObjectName(domain, "name", ObjectName.quote(name));
    }
    return objectName;
  } catch (MalformedObjectNameException e) {
    try {
      return new ObjectName(domain, "name", ObjectName.quote(name));
    } catch (MalformedObjectNameException e1) {
      LOGGER.warn("Unable to register {} {}", type, name, e1);
      throw new RuntimeException(e1);
    }
  }
}

代码示例来源:origin: networknt/light-4j

@Override
public ObjectName createName(String type, String domain, MetricName metricName) {
  String name = metricName.getKey();
  try {
    ObjectName objectName = new ObjectName(domain, "name", name);
    if (objectName.isPattern()) {
      objectName = new ObjectName(domain, "name", ObjectName.quote(name));
    }
    return objectName;
  } catch (MalformedObjectNameException e) {
    try {
      return new ObjectName(domain, "name", ObjectName.quote(name));
    } catch (MalformedObjectNameException e1) {
      LOGGER.warn("Unable to register {} {}", type, name, e1);
      throw new RuntimeException(e1);
    }
  }
}

代码示例来源:origin: scouter-project/scouter

if (objectName == null) {
  objectName = ObjectName.getInstance(mbean);
  if (objectName.isPattern()) {
    Logger.trace(mbean + "is pattern object name");
    ignoreSet.add(mbean);

代码示例来源:origin: scouter-project/scouter

if (objectName == null) {
  objectName = ObjectName.getInstance(mbean);
  if (objectName.isPattern()) {
    Logger.trace(mbean + "is pattern object name");
    ignoreSet.add(mbean);

代码示例来源:origin: rhuss/jolokia

/**
 * Whether this key embraces a MBean pattern
 *
 * @return true if the the included MBean is a pattern
 */
public boolean isMBeanPattern() {
  return mBean.isPattern();
}

代码示例来源:origin: rhuss/jolokia

/**
 * Add for a given MBean a set of read/write attributes and operations
 *
 * @param pOName MBean name (which should not be pattern)
 * @param pReadAttributes read attributes
 * @param pWriteAttributes write attributes
 * @param pOperations operations
 */
void addValues(ObjectName pOName, Set<String> pReadAttributes, Set<String> pWriteAttributes, Set<String> pOperations) {
  readAttributes.put(pOName,pReadAttributes);
  writeAttributes.put(pOName,pWriteAttributes);
  operations.put(pOName,pOperations);
  if (pOName.isPattern()) {
    addPattern(pOName);
  }
}

代码示例来源:origin: rhuss/jolokia

/**
 * Prepare an objectname patttern from a path (or "null" if no path is given)
 * @param pPathStack path
 * @return created object name (either plain or a pattern)
 */
private ObjectName objectNameFromPath(Stack<String> pPathStack) throws MalformedObjectNameException {
  if (pPathStack.empty()) {
    return null;
  }
  Stack<String> path = (Stack<String>) pPathStack.clone();
  String domain = path.pop();
  if (path.empty()) {
    return new ObjectName(domain + ":*");
  }
  String props = path.pop();
  ObjectName mbean = new ObjectName(domain + ":" + props);
  if (mbean.isPattern()) {
    throw new IllegalArgumentException("Cannot use an MBean pattern as path (given MBean: " + mbean + ")");
  }
  return mbean;
}

代码示例来源:origin: glowroot/glowroot

private Set<ObjectName> getObjectNames(String mbeanObjectName) throws Exception {
  ObjectName objectName = ObjectName.getInstance(mbeanObjectName);
  List<MBeanServer> mbeanServers = lazyPlatformMBeanServer.findAllMBeanServers();
  if (objectName.isPattern()) {
    return lazyPlatformMBeanServer.queryNames(objectName, null, mbeanServers);
  } else {
    try {
      lazyPlatformMBeanServer.getMBeanInfo(objectName, mbeanServers);
    } catch (InstanceNotFoundException e) {
      return ImmutableSet.of();
    }
    return ImmutableSet.of(objectName);
  }
}

代码示例来源:origin: rhuss/jolokia

/**
 * Name prepared according to requested formatting note. The key ordering can be influenced by the
 * processing parameter {@link ConfigKey#CANONICAL_NAMING}. If not given or set to "true",
 * then the canonical order is used, if set to "initial" the name is given to construction time
 * is used.
 *
 * @param pName name to format
 * @return formatted string
 */
public String getOrderedObjectName(ObjectName pName) {
  // For patterns we always return the canonical name
  if (pName.isPattern()) {
    return pName.getCanonicalName();
  }
  if (getParameterAsBool(ConfigKey.CANONICAL_NAMING)) {
    return pName.getCanonicalName();
  } else {
    return pName.getDomain() + ":" + pName.getKeyPropertyListString();
  }
}

代码示例来源:origin: rhuss/jolokia

/**
 * Get all MBean names for which the request fetched values. If the request
 * contained an MBean pattern then all MBean names matching this pattern and which contained
 * attributes of the given name are returned. If the MBean wasnt a pattern a single
 * value collection with the single MBean name of the request is returned.
 *
 * @return list of MBean names
 * @throws MalformedObjectNameException if the returned MBean names could not be converted to
 *                                      {@link ObjectName}s. Shouldnt occur, though.
 */
public Collection<ObjectName> getObjectNames() throws MalformedObjectNameException {
  ObjectName mBean = getRequest().getObjectName();
  if (mBean.isPattern()) {
    // The result value contains the list of fetched object names
    JSONObject values = getValue();
    Set<ObjectName> ret = new HashSet<ObjectName>();
    for (Object name : values.keySet()) {
      ret.add(new ObjectName((String) name));
    }
    return ret;
  } else {
    return Arrays.asList(mBean);
  }
}

代码示例来源:origin: rhuss/jolokia

/**
 * For a simple requests (one MBean, one attribute) we let the dispatching of the servers
 * done by the upper level. If the request is for an MBean pattern or multiple attributes
 * are required, we try multiple requests for multiple server.
 *
 * @param pRequest request to decide on whether to handle all request at once
 * @return true if this is a multi attribute request, has an MBean pattern to look for or is a request for
 *         all attributes.
 */
@Override
public boolean handleAllServersAtOnce(JmxReadRequest pRequest) {
  return pRequest.getObjectName().isPattern() || pRequest.isMultiAttributeMode() || !pRequest.hasAttribute();
}

代码示例来源:origin: rhuss/jolokia

private void init(JmxObjectNameRequest pJmxReq) {
  if (pJmxReq.getObjectNameAsString() == null) {
    throw new IllegalArgumentException("MBean name must not be null");
  }
  if (pJmxReq.getObjectName().isPattern()) {
    throw new IllegalArgumentException("MBean name must not be a pattern");
  }
  if (pJmxReq.getTargetConfig() != null) {
    target = pJmxReq.getTargetConfig().getUrl();
  }
  mBean = pJmxReq.getObjectName();
}

代码示例来源:origin: glowroot/glowroot

return ImmutableList.of();
if (!objectName.isPattern()) {
  return collectGaugeValues(objectName, gaugeConfig.mbeanAttributes(), mbeanObjectName,
      mbeanServers);

代码示例来源:origin: rhuss/jolokia

/**
 * Get the value for a certain MBean and a given attribute. This method is especially
 * useful if the request leading to this response was done for multiple MBeans (i.e.
 * a read for an MBean pattern) and multiple attributes. However, this method can be
 * used for a request for single MBeans and single attributes as well, but then the given
 * parameters must match the parameters given in the request.
 *
 * @param pObjectName name of the Mbean or <code>null</code> if the request was only for a single
 *        Mbeans in which case this single MBean is taken from the request
 * @param pAttribute the attribute or <code>null</code> if the request was for a single
 *        attribute in which case the attribute name is taken from the request
 * @param <V> the object type of the return value ({@link String},{@link Map} or {@link List})
 * @return the value
 * @throws IllegalArgumentException if there was no value for the given parameters or if <code>null</code>
 *         was given for given for one or both arguments and the request was for multiple MBeans
 *         or attributes.
 */
public <V> V getValue(ObjectName pObjectName,String pAttribute) {
  ObjectName requestMBean = getRequest().getObjectName();
  if (requestMBean.isPattern()) {
    JSONObject mAttributes = getAttributesForObjectNameWithPatternRequest(pObjectName);
    if (!mAttributes.containsKey(pAttribute)) {
      throw new IllegalArgumentException("No attribute " + pAttribute + " for ObjectName " + pObjectName + " returned for" +
          " the given request");
    }
    return (V) mAttributes.get(pAttribute);
  } else {
    return (V) getValue(pAttribute);
  }
}

代码示例来源:origin: rhuss/jolokia

@Override
/** {@inheritDoc} */
public Object doHandleRequest(MBeanServerExecutor pServerManager, JmxReadRequest pRequest)
    throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException {
  ObjectName oName = pRequest.getObjectName();
  ValueFaultHandler faultHandler = pRequest.getValueFaultHandler();
  if (oName.isPattern()) {
    return fetchAttributesForMBeanPattern(pServerManager, pRequest);
  } else {
    return fetchAttributes(pServerManager,oName,pRequest.getAttributeNames(),faultHandler);
  }
}

代码示例来源:origin: rhuss/jolokia

/**
 * Get all attributes obtained. This method can be only used, if the requested MBean
 * was not a pattern (i.e. the request was for a single MBean).
 *
 * @return a list of attributes for this request. If the request was performed for
 *         only a single attribute, the attribute name of the request is returend as
 *         a single valued list. For more than one attribute, the attribute names
 *         a returned from the returned list.
 */
public Collection<String> getAttributes() {
  J4pReadRequest request = getRequest();
  ObjectName requestBean = request.getObjectName();
  if (requestBean.isPattern()) {
    throw new IllegalArgumentException(
        "Attributes can be fetched only for non-pattern request (current: " +
            requestBean.getCanonicalName() + ")");
  }
  // The attribute names are the same as from the request
  if (request.hasSingleAttribute()) {
    // Contains only a single attribute:
    return request.getAttributes();
  } else {
    JSONObject attributes = getValue();
    return attributes.keySet();
  }
}

代码示例来源:origin: glowroot/glowroot

public Set<ObjectName> queryNames(@Nullable ObjectName name, @Nullable QueryExp query,
    List<MBeanServer> mbeanServers) throws Exception {
  ensureInit();
  if (needsManualPatternMatching && name != null && name.isPattern()) {
    return queryNamesAcrossAll(null, new ObjectNamePatternQueryExp(name), mbeanServers);
  } else {
    return queryNamesAcrossAll(name, query, mbeanServers);
  }
}

代码示例来源:origin: rhuss/jolokia

/**
 * Get the name of all attributes fetched for a certain MBean name. If the request was
 * performed for a single MBean, then the given name must match that of the MBean name
 * provided in the request. If <code>null</code> is given as argument, then this method
 * will return all attributes for the single MBean given in the request
 *
 * @param pObjectName MBean for which to get the attribute names,
 * @return a collection of attribute names
 */
public Collection<String> getAttributes(ObjectName pObjectName) {
  ObjectName requestMBean = getRequest().getObjectName();
  if (requestMBean.isPattern()) {
    // We need to got down one level in the returned values
    JSONObject attributes = getAttributesForObjectNameWithPatternRequest(pObjectName);
    return attributes.keySet();
  } else {
    if (pObjectName != null && !pObjectName.equals(requestMBean)) {
      throw new IllegalArgumentException("Given ObjectName " + pObjectName + " doesn't match with" +
          " the single ObjectName " + requestMBean + " given in the request");
    }
    return getAttributes();
  }
}

代码示例来源:origin: rhuss/jolokia

/** {@inheritDoc} */
@Override
public Object doHandleRequest(MBeanServerExecutor pServerManager, JmxListRequest pRequest)
    throws IOException, NotChangedException {
  // Throw an exception if list has not changed
  checkForModifiedSince(pServerManager, pRequest);
  Stack<String> originalPathStack = EscapeUtil.reversePath(pRequest.getPathParts());
  int maxDepth = pRequest.getParameterAsInt(ConfigKey.MAX_DEPTH);
  boolean useCanonicalName = pRequest.getParameterAsBool(ConfigKey.CANONICAL_NAMING);
  ObjectName oName = null;
  try {
    Stack<String> pathStack = (Stack<String>) originalPathStack.clone();
    oName = objectNameFromPath(pathStack);
    ListMBeanEachAction action = new ListMBeanEachAction(maxDepth,pathStack,useCanonicalName);
    if (oName == null || oName.isPattern()) {
      pServerManager.each(oName, action);
    } else {
      pServerManager.call(oName,action);
    }
    return action.getResult();
  } catch (MalformedObjectNameException e) {
    throw new IllegalArgumentException("Invalid path within the MBean part given. (Path: " + pRequest.getPath() + ")",e);
  } catch (InstanceNotFoundException e) {
    throw new IllegalArgumentException("No MBean '" + oName + "' found",e);
  } catch (JMException e) {
    throw new IllegalStateException("Internal error while retrieving list: " + e, e);
  }
}

相关文章