Class IOStatisticsContextIntegration

java.lang.Object
org.apache.hadoop.fs.statistics.impl.IOStatisticsContextIntegration

public final class IOStatisticsContextIntegration extends Object
A Utility class for IOStatisticsContext, which helps in creating and getting the current active context. Static methods in this class allows to get the current context to start aggregating the IOStatistics. Static initializer is used to work out if the feature to collect thread-level IOStatistics is enabled or not and the corresponding implementation class is called for it. Weak Reference thread map to be used to keep track of different context's to avoid long-lived memory leakages as these references would be cleaned up at GC.
  • Field Details

    • INSTANCE_ID

      public static final AtomicLong INSTANCE_ID
      ID for next instance to create.
  • Method Details

    • isIOStatisticsThreadLevelEnabled

      public static boolean isIOStatisticsThreadLevelEnabled()
      Static probe to check if the thread-level IO statistics enabled.
      Returns:
      if the thread-level IO statistics enabled.
    • getCurrentIOStatisticsContext

      public static IOStatisticsContext getCurrentIOStatisticsContext()
      Get the current thread's IOStatisticsContext instance. If no instance is present for this thread ID, create one using the factory.
      Returns:
      instance of IOStatisticsContext.
    • setThreadIOStatisticsContext

      public static void setThreadIOStatisticsContext(IOStatisticsContext statisticsContext)
      Set the IOStatisticsContext for the current thread.
      Parameters:
      statisticsContext - IOStatistics context instance for the current thread. If null, the context is reset.
    • getThreadSpecificIOStatisticsContext

      @VisibleForTesting public static IOStatisticsContext getThreadSpecificIOStatisticsContext(long testThreadId)
      Get thread ID specific IOStatistics values if statistics are enabled and the thread ID is in the map.
      Parameters:
      testThreadId - thread ID.
      Returns:
      IOStatisticsContext if found in the map.
    • enableIOStatisticsContext

      @VisibleForTesting public static void enableIOStatisticsContext()
      A method to enable IOStatisticsContext to override if set otherwise in the configurations for tests.