Class WeakRefMetricsSource

java.lang.Object
org.apache.hadoop.fs.impl.WeakRefMetricsSource
All Implemented Interfaces:
MetricsSource

@Private public class WeakRefMetricsSource extends Object implements MetricsSource
A weak referenced metrics source which avoids hanging on to large objects if somehow they don't get fully closed/cleaned up. The JVM may clean up all objects which are only weakly referenced whenever it does a GC, even if there is no memory pressure. To avoid these refs being removed, always keep a strong reference around somewhere.
  • Constructor Details

    • WeakRefMetricsSource

      public WeakRefMetricsSource(String name, MetricsSource source)
      Constructor.
      Parameters:
      name - Name to know when unregistering.
      source - metrics source
  • Method Details

    • getMetrics

      public void getMetrics(MetricsCollector collector, boolean all)
      If the weak reference is non null, update the metrics.
      Specified by:
      getMetrics in interface MetricsSource
      Parameters:
      collector - to contain the resulting metrics snapshot
      all - if true, return all metrics even if unchanged.
    • getName

      public String getName()
      Name to know when unregistering.
      Returns:
      the name passed in during construction.
    • getSource

      public MetricsSource getSource()
      Get the source, will be null if the reference has been GC'd
      Returns:
      the source reference
    • toString

      public String toString()
      Overrides:
      toString in class Object