Java Code Examples for javax.management.ObjectName#unquote()

The following examples show how to use javax.management.ObjectName#unquote() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpGaugeSet.java    From metrics with Apache License 2.0 6 votes vote down vote up
private void populateGauges() {
    // collect http metrics
    ObjectName[] connectorNames = JMXUtils.getObjectNames(globalReqProcessor);

    for (ObjectName connectorName : connectorNames) {
        String name = ObjectName.unquote(connectorName.getKeyProperty("name"));
        connectorMetrics.put(name, new Long[HttpMetrics.values().length]);
    }

    for (Map.Entry<String, Long[]> entry: connectorMetrics.entrySet()) {
        for (HttpMetrics metric : HttpMetrics.values()) {
            gauges.put(MetricName.build(metricNames[metric.ordinal()]).tagged("connector", entry.getKey()),
                    new HttpStatGauge<Long>(entry.getValue(), metric.ordinal()));
        }
    }

}
 
Example 2
Source File: NamingResourcesMBean.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Remove any resource link reference with the specified name.
 *
 * @param resourceLinkName Name of the resource link reference to remove
 */
public void removeResourceLink(String resourceLinkName) {

    resourceLinkName = ObjectName.unquote(resourceLinkName);
    NamingResources nresources = (NamingResources) this.resource;
    if (nresources == null) {
        return;
    }
    ContextResourceLink resourceLink = 
                        nresources.findResourceLink(resourceLinkName);
    if (resourceLink == null) {
        throw new IllegalArgumentException
            ("Invalid resource Link name '" + resourceLinkName + "'");
    }
    nresources.removeResourceLink(resourceLinkName);
}
 
Example 3
Source File: NamingResourcesMBean.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Remove any resource link reference with the specified name.
 *
 * @param resourceLinkName Name of the resource link reference to remove
 */
public void removeResourceLink(String resourceLinkName) {

    resourceLinkName = ObjectName.unquote(resourceLinkName);
    NamingResources nresources = (NamingResources) this.resource;
    if (nresources == null) {
        return;
    }
    ContextResourceLink resourceLink = 
                        nresources.findResourceLink(resourceLinkName);
    if (resourceLink == null) {
        throw new IllegalArgumentException
            ("Invalid resource Link name '" + resourceLinkName + "'");
    }
    nresources.removeResourceLink(resourceLinkName);
}
 
Example 4
Source File: NamingResourcesMBean.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Remove any resource link reference with the specified name.
 *
 * @param resourceLinkName Name of the resource link reference to remove
 */
public void removeResourceLink(String resourceLinkName) {
    resourceLinkName = ObjectName.unquote(resourceLinkName);
    NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
    if (nresources == null) {
        return;
    }
    ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName);
    if (resourceLink == null) {
        throw new IllegalArgumentException(
                "Invalid resource Link name '" + resourceLinkName + "'");
    }
    nresources.removeResourceLink(resourceLinkName);
}
 
Example 5
Source File: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Remove an existing Connector.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeConnector(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    Service service = getService(oname);
    String port = oname.getKeyProperty("port");
    String address = oname.getKeyProperty("address");
    if (address != null) {
        address = ObjectName.unquote(address);
    }

    Connector conns[] = service.findConnectors();

    for (int i = 0; i < conns.length; i++) {
        String connAddress = null;
        Object objConnAddress = conns[i].getProperty("address");
        if (objConnAddress != null) {
            connAddress = ((InetAddress) objConnAddress).getHostAddress();
        }
        String connPort = ""+conns[i].getPort();

        if (address == null) {
            // Don't combine this with outer if or we could get an NPE in
            // 'else if' below
            if (connAddress == null && port.equals(connPort)) {
                service.removeConnector(conns[i]);
                conns[i].destroy();
                break;
            }
        } else if (address.equals(connAddress) && port.equals(connPort)) {
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
    }
}
 
Example 6
Source File: ClusterStatistics.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void updateClusterStatement(ObjectName mbeanName) throws IOException {

    try {
      AttributeList attributeList = this.mbs.getAttributes(mbeanName, GfxdConstants.STATEMENT_MBEAN_ATTRIBUTES);
      String statementDefinition = mbeanName.getKeyProperty("name");
      if (isQuoted(statementDefinition)) {
        statementDefinition = ObjectName.unquote(statementDefinition);
      }
      
      Statement statement = statementMap.get(statementDefinition);

      if (null == statement) {
        statement = new Statement();
        statement.setQueryDefinition(statementDefinition);
      }

      for (int i = 0; i < attributeList.size(); i++) {
       Attribute attribute = (Attribute) attributeList.get(i);
        updateAttribute(statement,attribute);
      }

      addClusterStatement(statementDefinition, statement);
    } catch (InstanceNotFoundException infe) {
      logger.warning(infe);
    } catch (ReflectionException re) {
      logger.warning(re);
    }
  }
 
Example 7
Source File: ClusterStatistics.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void updateClusterStatement(ObjectName mbeanName) throws IOException {

    try {
      AttributeList attributeList = this.mbs.getAttributes(mbeanName, GfxdConstants.STATEMENT_MBEAN_ATTRIBUTES);
      String statementDefinition = mbeanName.getKeyProperty("name");
      if (isQuoted(statementDefinition)) {
        statementDefinition = ObjectName.unquote(statementDefinition);
      }
      
      Statement statement = statementMap.get(statementDefinition);

      if (null == statement) {
        statement = new Statement();
        statement.setQueryDefinition(statementDefinition);
      }

      for (int i = 0; i < attributeList.size(); i++) {
       Attribute attribute = (Attribute) attributeList.get(i);
        updateAttribute(statement,attribute);
      }

      addClusterStatement(statementDefinition, statement);
    } catch (InstanceNotFoundException infe) {
      logger.warning(infe);
    } catch (ReflectionException re) {
      logger.warning(re);
    }
  }
 
Example 8
Source File: HttpGaugeSet.java    From metrics with Apache License 2.0 4 votes vote down vote up
@Override
protected void getValueInternal() {
    // collect http metrics
    ObjectName[] connectorNames = JMXUtils.getObjectNames(globalReqProcessor);

    for (ObjectName connectorName : connectorNames) {
        String name = ObjectName.unquote(connectorName.getKeyProperty("name"));
        Long[] metrics = connectorMetrics.get(name);
        if (null == metrics) {
            continue;
        }

        try {
            metrics[HttpMetrics.REQUEST_COUNT.ordinal()] =
                    Long.valueOf((Integer)mbeanServer.getAttribute(connectorName, "requestCount"));
            metrics[HttpMetrics.PROCESSING_TIME.ordinal()] =
                    (Long)mbeanServer.getAttribute(connectorName, "processingTime");
            metrics[HttpMetrics.ERROR_COUNT.ordinal()] =
                    Long.valueOf((Integer)mbeanServer.getAttribute(connectorName, "errorCount"));
            metrics[HttpMetrics.MAX_TIME.ordinal()] =
                    (Long)mbeanServer.getAttribute(connectorName, "maxTime");
            metrics[HttpMetrics.BYTES_RECEIVED.ordinal()] =
                    (Long)mbeanServer.getAttribute(connectorName, "bytesReceived");
            metrics[HttpMetrics.BYTES_SENT.ordinal()] =
                    (Long)mbeanServer.getAttribute(connectorName, "bytesSent");
        } catch (Exception e) {
            logger.error("Exception occur when getting connector global stats: ", e);
        }

        // get request failure count
        try {
            Object attribute = mbeanServer.getAttribute(connectorName, "requestFailureCount");
            if (attribute != null) {
                Integer[] data = (Integer[]) attribute;
                for (int i = 0; i < data.length; i++) {
                    failureStats.get(name)[i] = data[i];
                }
            }
        } catch (Exception ex) {
            // it is ok if running on Apache Tomcat, which has no such attribute indeed.
        }
    }
}