hadoop IOStatisticsContextImpl 源码

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

haddop IOStatisticsContextImpl 代码

文件路径:/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/statistics/impl/IOStatisticsContextImpl.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.fs.statistics.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hadoop.fs.statistics.IOStatistics;
import org.apache.hadoop.fs.statistics.IOStatisticsAggregator;
import org.apache.hadoop.fs.statistics.IOStatisticsContext;
import org.apache.hadoop.fs.statistics.IOStatisticsSnapshot;

/**
 * Implementing the IOStatisticsContext.
 *
 * A Context defined for IOStatistics collection per thread which captures
 * each worker thread's work in FS streams and stores it in the form of
 * IOStatisticsSnapshot.
 *
 * For the current thread the IOStatisticsSnapshot can be used as a way to
 * move the IOStatistics data between applications using the Serializable
 * nature of the class.
 */
public final class IOStatisticsContextImpl implements IOStatisticsContext {
  private static final Logger LOG =
      LoggerFactory.getLogger(IOStatisticsContextImpl.class);

  /**
   * Thread ID.
   */
  private final long threadId;

  /**
   * Unique ID.
   */
  private final long id;

  /**
   * IOStatistics to aggregate.
   */
  private final IOStatisticsSnapshot ioStatistics = new IOStatisticsSnapshot();

  /**
   * Constructor.
   * @param threadId thread ID
   * @param id instance ID.
   */
  public IOStatisticsContextImpl(final long threadId, final long id) {
    this.threadId = threadId;
    this.id = id;
  }

  @Override
  public String toString() {
    return "IOStatisticsContextImpl{" +
        "id=" + id +
        ", threadId=" + threadId +
        ", ioStatistics=" + ioStatistics +
        '}';
  }

  /**
   * Get the IOStatisticsAggregator of the context.
   * @return the instance of IOStatisticsAggregator for this context.
   */
  @Override
  public IOStatisticsAggregator getAggregator() {
    return ioStatistics;
  }

  /**
   * Returns a snapshot of the current thread's IOStatistics.
   *
   * @return IOStatisticsSnapshot of the context.
   */
  @Override
  public IOStatisticsSnapshot snapshot() {
    LOG.debug("Taking snapshot of IOStatisticsContext id {}", id);
    return new IOStatisticsSnapshot(ioStatistics);
  }

  /**
   * Reset the thread +.
   */
  @Override
  public void reset() {
    LOG.debug("clearing IOStatisticsContext id {}", id);
    ioStatistics.clear();
  }

  @Override
  public IOStatistics getIOStatistics() {
    return ioStatistics;
  }

  /**
   * ID of this context.
   * @return ID.
   */
  @Override
  public long getID() {
    return id;
  }

  /**
   * Get the thread ID.
   * @return thread ID.
   */
  public long getThreadID() {
    return threadId;
  }
}

相关信息

hadoop 源码目录

相关文章

hadoop AbstractIOStatisticsImpl 源码

hadoop DynamicIOStatistics 源码

hadoop DynamicIOStatisticsBuilder 源码

hadoop EmptyIOStatistics 源码

hadoop EmptyIOStatisticsContextImpl 源码

hadoop EmptyIOStatisticsStore 源码

hadoop EvaluatingStatisticsMap 源码

hadoop IOStatisticsBinding 源码

hadoop IOStatisticsContextIntegration 源码

hadoop IOStatisticsStore 源码

0  赞