/**
  * Create a mutable metric with stats
  *
  * @param name of the metric
  * @param description of the metric
  * @param sampleName of the metric (e.g., "ops")
  * @param valueName of the metric (e.g., "time" or "latency")
  * @param extended produce extended stat (stdev, min/max etc.) if true.
  * @return a new metric object
  */
 public MetricMutableStat newStat(
     String name, String description, String sampleName, String valueName, boolean extended) {
   checkMetricName(name);
   MetricMutableStat ret = mf.newStat(name, description, sampleName, valueName, extended);
   metricsMap.put(name, ret);
   return ret;
 }
  /**
   * Decrement a metric by name.
   *
   * @param name of the metric
   * @param value of the snapshot to add
   * @param factory to lazily create the metric if not null
   */
  public void add(String name, long value, MetricMutableFactory factory) {
    MetricMutable m = metricsMap.get(name);

    if (m != null) {
      if (m instanceof MetricMutableStat) {
        ((MetricMutableStat) m).add(value);
      } else {
        throw new MetricsException("Unsupported add(value) for metric " + name);
      }
    } else if (factory != null) {
      metricsMap.put(name, factory.newStat(name));
      add(name, value, null);
    } else {
      throw new MetricsException("Metric " + name + " doesn't exist");
    }
  }
  /**
   * Decrement a metric by name.
   *
   * @param name of the metric
   * @param factory to lazily create the metric if not null
   */
  public void decr(String name, MetricMutableFactory factory) {
    MetricMutable m = metricsMap.get(name);

    if (m != null) {
      if (m instanceof MetricMutableGauge<?>) {
        ((MetricMutableGauge<?>) m).decr();
      } else {
        throw new MetricsException("Unsupported decr() for metric " + name);
      }
    } else if (factory != null) {
      metricsMap.put(name, factory.newMetric(name));
      decr(name, null);
    } else {
      throw new MetricsException("Metric " + name + " doesn't exist");
    }
  }
 /**
  * Create a mutable integer counter
  *
  * @param name of the metric
  * @param description of the metric
  * @param initValue of the metric
  * @return a new counter object
  */
 public MetricMutableCounterInt newCounter(String name, String description, int initValue) {
   checkMetricName(name);
   MetricMutableCounterInt ret = mf.newCounter(name, description, initValue);
   metricsMap.put(name, ret);
   return ret;
 }
 /**
  * Create a mutable long integer gauge
  *
  * @param name of the metric
  * @param description of the metric
  * @param initValue of the metric
  * @return a new gauge object
  */
 public MetricMutableGaugeLong newGauge(String name, String description, long initValue) {
   checkMetricName(name);
   MetricMutableGaugeLong ret = mf.newGauge(name, description, initValue);
   metricsMap.put(name, ret);
   return ret;
 }