hadoop MetricsSystem 源码

  • 2022-10-20
  • 浏览 (221)

haddop MetricsSystem 代码

文件路径:/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/MetricsSystem.java

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.hadoop.metrics2;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;

/**
 * The metrics system interface.
 * 
 * The following components are used for metrics.
 * <ul>
 * <li>{@link MetricsSource} generate and update metrics information.</li>
 * <li>{@link MetricsSink} consume the metrics information</li>
 * </ul>
 * 
 * {@link MetricsSource} and {@link MetricsSink} register with the metrics
 * system. Implementations of {@link MetricsSystem} polls the
 * {@link MetricsSource}s periodically and pass the {@link MetricsRecord}s to
 * {@link MetricsSink}.
 */
@InterfaceAudience.Public
@InterfaceStability.Evolving
public abstract class MetricsSystem implements MetricsSystemMXBean {

  @InterfaceAudience.Private
  public abstract MetricsSystem init(String prefix);

  /**
   * Register a metrics source
   * @param <T>   the actual type of the source object
   * @param source object to register
   * @param name  of the source. Must be unique or null (then extracted from
   *              the annotations of the source object.)
   * @param desc  the description of the source (or null. See above.)
   * @return the source object
   * @exception MetricsException Metrics Exception.
   */
  public abstract <T> T register(String name, String desc, T source);

  /**
   * Unregister a metrics source
   * @param name of the source. This is the name you use to call register()
   */
  public abstract void unregisterSource(String name);

  /**
   * Register a metrics source (deriving name and description from the object)
   * @param <T>   the actual type of the source object
   * @param source  object to register
   * @return  the source object
   * @exception MetricsException Metrics Exception.
   */
  public <T> T register(T source) {
    return register(null, null, source);
  }

  /**
   * @param name  of the metrics source
   * @return the metrics source (potentially wrapped) object
   */
  @InterfaceAudience.Private
  public abstract MetricsSource getSource(String name);

  /**
   * Register a metrics sink
   * @param <T>   the type of the sink
   * @param sink  to register
   * @param name  of the sink. Must be unique.
   * @param desc  the description of the sink
   * @return the sink
   * @exception MetricsException Metrics Exception.
   */
  public abstract <T extends MetricsSink>
  T register(String name, String desc, T sink);

  /**
   * Register a callback interface for JMX events
   * @param callback  the callback object implementing the MBean interface.
   */
  public abstract void register(Callback callback);

  /**
   * Requests an immediate publish of all metrics from sources to sinks.
   * 
   * This is a "soft" request: the expectation is that a best effort will be
   * done to synchronously snapshot the metrics from all the sources and put
   * them in all the sinks (including flushing the sinks) before returning to
   * the caller. If this can't be accomplished in reasonable time it's OK to
   * return to the caller before everything is done. 
   */
  public abstract void publishMetricsNow();

  /**
   * Shutdown the metrics system completely (usually during server shutdown.)
   * The MetricsSystemMXBean will be unregistered.
   * @return true if shutdown completed
   */
  public abstract boolean shutdown();

  /**
   * The metrics system callback interface (needed for proxies.)
   */
  public interface Callback {
    /**
     * Called before start()
     */
    void preStart();

    /**
     * Called after start()
     */
    void postStart();

    /**
     * Called before stop()
     */
    void preStop();

    /**
     * Called after stop()
     */
    void postStop();
  }

  /**
   * Convenient abstract class for implementing callback interface
   */
  public static abstract class AbstractCallback implements Callback {
    @Override public void preStart() {}
    @Override public void postStart() {}
    @Override public void preStop() {}
    @Override public void postStop() {}
  }
}

相关信息

hadoop 源码目录

相关文章

hadoop AbstractMetric 源码

hadoop MetricStringBuilder 源码

hadoop MetricType 源码

hadoop MetricsCollector 源码

hadoop MetricsException 源码

hadoop MetricsFilter 源码

hadoop MetricsInfo 源码

hadoop MetricsJsonBuilder 源码

hadoop MetricsPlugin 源码

hadoop MetricsRecord 源码

0  赞