Class DynamicWrappedStatistics

java.lang.Object
org.apache.hadoop.io.wrappedio.impl.DynamicWrappedStatistics

public final class DynamicWrappedStatistics extends Object
The wrapped IOStatistics methods in WrappedStatistics, dynamically loaded. This is suitable for copy-and-paste into other libraries which have some version of the Parquet DynMethods classes already present.
  • Field Details

    • WRAPPED_STATISTICS_CLASSNAME

      public static final String WRAPPED_STATISTICS_CLASSNAME
      Classname of the wrapped statistics class: "org.apache.hadoop.io.wrappedio.WrappedStatistics".
      See Also:
    • IS_IOSTATISTICS_SOURCE

      public static final String IS_IOSTATISTICS_SOURCE
      Method name: "isIOStatisticsSource".
      See Also:
    • IS_IOSTATISTICS

      public static final String IS_IOSTATISTICS
      Method name: "isIOStatistics".
      See Also:
    • IS_IOSTATISTICS_SNAPSHOT

      public static final String IS_IOSTATISTICS_SNAPSHOT
      Method name: "isIOStatisticsSnapshot".
      See Also:
    • IOSTATISTICS_CONTEXT_AGGREGATE

      public static final String IOSTATISTICS_CONTEXT_AGGREGATE
      IOStatisticsContext method: "iostatisticsContext_aggregate".
      See Also:
    • IOSTATISTICS_CONTEXT_ENABLED

      public static final String IOSTATISTICS_CONTEXT_ENABLED
      IOStatisticsContext method: "iostatisticsContext_enabled".
      See Also:
    • IOSTATISTICS_CONTEXT_GET_CURRENT

      public static final String IOSTATISTICS_CONTEXT_GET_CURRENT
      IOStatisticsContext method: "iostatisticsContext_getCurrent".
      See Also:
    • IOSTATISTICS_CONTEXT_SET_THREAD_CONTEXT

      public static final String IOSTATISTICS_CONTEXT_SET_THREAD_CONTEXT
      IOStatisticsContext method: "iostatisticsContext_setThreadIOStatisticsContext".
      See Also:
    • IOSTATISTICS_CONTEXT_RESET

      public static final String IOSTATISTICS_CONTEXT_RESET
      IOStatisticsContext method: "iostatisticsContext_reset".
      See Also:
    • IOSTATISTICS_CONTEXT_SNAPSHOT

      public static final String IOSTATISTICS_CONTEXT_SNAPSHOT
      IOStatisticsContext method: "iostatisticsContext_snapshot".
      See Also:
    • IOSTATISTICS_SNAPSHOT_AGGREGATE

      public static final String IOSTATISTICS_SNAPSHOT_AGGREGATE
      Method name: "iostatisticsSnapshot_aggregate".
      See Also:
    • IOSTATISTICS_SNAPSHOT_CREATE

      public static final String IOSTATISTICS_SNAPSHOT_CREATE
      Method name: "iostatisticsSnapshot_create".
      See Also:
    • IOSTATISTICS_SNAPSHOT_FROM_JSON_STRING

      public static final String IOSTATISTICS_SNAPSHOT_FROM_JSON_STRING
      Method name: "iostatisticsSnapshot_fromJsonString".
      See Also:
    • IOSTATISTICS_SNAPSHOT_LOAD

      public static final String IOSTATISTICS_SNAPSHOT_LOAD
      Method name: "iostatisticsSnapshot_load".
      See Also:
    • IOSTATISTICS_SNAPSHOT_RETRIEVE

      public static final String IOSTATISTICS_SNAPSHOT_RETRIEVE
      Method name: "iostatisticsSnapshot_retrieve".
      See Also:
    • IOSTATISTICS_SNAPSHOT_SAVE

      public static final String IOSTATISTICS_SNAPSHOT_SAVE
      Method name: "iostatisticsSnapshot_save".
      See Also:
    • IOSTATISTICS_SNAPSHOT_TO_JSON_STRING

      public static final String IOSTATISTICS_SNAPSHOT_TO_JSON_STRING
      Method name: "iostatisticsSnapshot_toJsonString".
      See Also:
    • IOSTATISTICS_TO_PRETTY_STRING

      public static final String IOSTATISTICS_TO_PRETTY_STRING
      Method name: "iostatistics_toPrettyString".
      See Also:
    • IOSTATISTICS_COUNTERS

      public static final String IOSTATISTICS_COUNTERS
      Method name: "iostatistics_counters".
      See Also:
    • IOSTATISTICS_GAUGES

      public static final String IOSTATISTICS_GAUGES
      Method name: "iostatistics_gauges".
      See Also:
    • IOSTATISTICS_MINIMUMS

      public static final String IOSTATISTICS_MINIMUMS
      Method name: "iostatistics_minimums".
      See Also:
    • IOSTATISTICS_MAXIMUMS

      public static final String IOSTATISTICS_MAXIMUMS
      Method name: "iostatistics_maximums".
      See Also:
    • IOSTATISTICS_MEANS

      public static final String IOSTATISTICS_MEANS
      Method name: "iostatistics_means".
      See Also:
  • Constructor Details

    • DynamicWrappedStatistics

      public DynamicWrappedStatistics()
    • DynamicWrappedStatistics

      public DynamicWrappedStatistics(String classname)
  • Method Details

    • loaded

      public boolean loaded()
      Is the wrapped statistics class loaded?
      Returns:
      true if the wrappedIO class was found and loaded.
    • ioStatisticsAvailable

      public boolean ioStatisticsAvailable()
      Are the core IOStatistics methods and classes available.
      Returns:
      true if the relevant methods are loaded.
    • ioStatisticsContextAvailable

      public boolean ioStatisticsContextAvailable()
      Are the IOStatisticsContext methods and classes available?
      Returns:
      true if the relevant methods are loaded.
    • isIOStatisticsSource

      public boolean isIOStatisticsSource(Object object)
      Probe for an object being an instance of IOStatisticsSource.
      Parameters:
      object - object to probe
      Returns:
      true if the object is the right type, false if the classes were not found or the object is null/of a different type
    • isIOStatistics

      public boolean isIOStatistics(Object object)
      Probe for an object being an instance of IOStatisticsSource.
      Parameters:
      object - object to probe
      Returns:
      true if the object is the right type, false if the classes were not found or the object is null/of a different type
    • isIOStatisticsSnapshot

      public boolean isIOStatisticsSnapshot(Serializable object)
      Probe for an object being an instance of IOStatisticsSnapshot.
      Parameters:
      object - object to probe
      Returns:
      true if the object is the right type, false if the classes were not found or the object is null/of a different type
    • iostatisticsContext_enabled

      public boolean iostatisticsContext_enabled()
      Probe to check if the thread-level IO statistics enabled. If the relevant classes and methods were not found, returns false
      Returns:
      true if the IOStatisticsContext API was found and is enabled.
    • iostatisticsContext_getCurrent

      public Object iostatisticsContext_getCurrent() throws UnsupportedOperationException
      Get the context's IOStatisticsContext which implements IOStatisticsSource. This is either a thread-local value or a global empty context.
      Returns:
      instance of IOStatisticsContext.
      Throws:
      UnsupportedOperationException - if the IOStatisticsContext API was not found
    • iostatisticsContext_setThreadIOStatisticsContext

      public void iostatisticsContext_setThreadIOStatisticsContext(@Nullable Object statisticsContext) throws UnsupportedOperationException
      Set the IOStatisticsContext for the current thread.
      Parameters:
      statisticsContext - IOStatistics context instance for the current thread. If null, the context is reset.
      Throws:
      UnsupportedOperationException - if the IOStatisticsContext API was not found
    • iostatisticsContext_reset

      public void iostatisticsContext_reset() throws UnsupportedOperationException
      Reset the context's IOStatistics. IOStatisticsContext#reset()
      Throws:
      UnsupportedOperationException - if the IOStatisticsContext API was not found
    • iostatisticsContext_snapshot

      public Serializable iostatisticsContext_snapshot() throws UnsupportedOperationException
      Take a snapshot of the context IOStatistics. IOStatisticsContext#snapshot()
      Returns:
      an instance of IOStatisticsSnapshot.
      Throws:
      UnsupportedOperationException - if the IOStatisticsContext API was not found
    • iostatisticsContext_aggregate

      public boolean iostatisticsContext_aggregate(Object source)
      Aggregate into the IOStatistics context the statistics passed in via IOStatistics/source parameter.

      Returns false if the source is null or does not contain any statistics.

      Parameters:
      source - implementation of IOStatisticsSource or IOStatistics
      Returns:
      true if the the source object was aggregated.
    • iostatisticsSnapshot_aggregate

      public boolean iostatisticsSnapshot_aggregate(Serializable snapshot, @Nullable Object statistics) throws UnsupportedOperationException
      Aggregate an existing IOStatisticsSnapshot with the supplied statistics.
      Parameters:
      snapshot - snapshot to update
      statistics - IOStatistics to add
      Returns:
      true if the snapshot was updated.
      Throws:
      IllegalArgumentException - if the statistics argument is not null but not an instance of IOStatistics, or if snapshot is invalid.
      UnsupportedOperationException - if the IOStatistics classes were not found
    • iostatisticsSnapshot_create

      public Serializable iostatisticsSnapshot_create() throws UnsupportedOperationException
      Create a new IOStatisticsSnapshot instance.
      Returns:
      an empty IOStatisticsSnapshot.
      Throws:
      UnsupportedOperationException - if the IOStatistics classes were not found
    • iostatisticsSnapshot_create

      public Serializable iostatisticsSnapshot_create(@Nullable Object source) throws UnsupportedOperationException, ClassCastException
      Create a new IOStatisticsSnapshot instance.
      Parameters:
      source - optional source statistics
      Returns:
      an IOStatisticsSnapshot.
      Throws:
      ClassCastException - if the source is not valid.
      UnsupportedOperationException - if the IOStatistics classes were not found
    • iostatisticsSnapshot_toJsonString

      public String iostatisticsSnapshot_toJsonString(@Nullable Serializable snapshot) throws UncheckedIOException, UnsupportedOperationException
      Save IOStatisticsSnapshot to a JSON string.
      Parameters:
      snapshot - statistics; may be null or of an incompatible type
      Returns:
      JSON string value or null if source is not an IOStatisticsSnapshot
      Throws:
      UncheckedIOException - Any IO/jackson exception.
      UnsupportedOperationException - if the IOStatistics classes were not found
    • iostatisticsSnapshot_fromJsonString

      public Serializable iostatisticsSnapshot_fromJsonString(String json) throws UncheckedIOException, UnsupportedOperationException
      Load IOStatisticsSnapshot from a JSON string.
      Parameters:
      json - JSON string value.
      Returns:
      deserialized snapshot.
      Throws:
      UncheckedIOException - Any IO/jackson exception.
      UnsupportedOperationException - if the IOStatistics classes were not found
    • iostatisticsSnapshot_load

      public Serializable iostatisticsSnapshot_load(FileSystem fs, Path path) throws UncheckedIOException, UnsupportedOperationException
      Load IOStatisticsSnapshot from a Hadoop filesystem.
      Parameters:
      fs - filesystem
      path - path
      Returns:
      the loaded snapshot
      Throws:
      UncheckedIOException - Any IO exception.
      UnsupportedOperationException - if the IOStatistics classes were not found
    • iostatisticsSnapshot_retrieve

      public Serializable iostatisticsSnapshot_retrieve(@Nullable Object source) throws UnsupportedOperationException
      Extract the IOStatistics from an object in a serializable form.
      Parameters:
      source - source object, may be null/not a statistics source/instance
      Returns:
      IOStatisticsSnapshot or null if the object is null/doesn't have statistics
      Throws:
      UnsupportedOperationException - if the IOStatistics classes were not found
    • iostatisticsSnapshot_save

      public void iostatisticsSnapshot_save(@Nullable Serializable snapshot, FileSystem fs, Path path, boolean overwrite) throws UncheckedIOException, UnsupportedOperationException
      Save IOStatisticsSnapshot to a Hadoop filesystem as a JSON file.
      Parameters:
      snapshot - statistics
      fs - filesystem
      path - path
      overwrite - should any existing file be overwritten?
      Throws:
      UncheckedIOException - Any IO exception.
      UnsupportedOperationException - if the IOStatistics classes were not found
    • iostatistics_counters

      public Map<String,Long> iostatistics_counters(Serializable source)
      Get the counters of an IOStatisticsSnapshot.
      Parameters:
      source - source of statistics.
      Returns:
      the map of counters.
    • iostatistics_gauges

      public Map<String,Long> iostatistics_gauges(Serializable source)
      Get the gauges of an IOStatisticsSnapshot.
      Parameters:
      source - source of statistics.
      Returns:
      the map of gauges.
    • iostatistics_minimums

      public Map<String,Long> iostatistics_minimums(Serializable source)
      Get the minimums of an IOStatisticsSnapshot.
      Parameters:
      source - source of statistics.
      Returns:
      the map of minimums.
    • iostatistics_maximums

      public Map<String,Long> iostatistics_maximums(Serializable source)
      Get the maximums of an IOStatisticsSnapshot.
      Parameters:
      source - source of statistics.
      Returns:
      the map of maximums.
    • iostatistics_means

      public Map<String,Map.Entry<Long,Long>> iostatistics_means(Serializable source)
      Get the means of an IOStatisticsSnapshot. Each value in the map is the (sample, sum) tuple of the values; the mean is then calculated by dividing sum/sample wherever sample is non-zero.
      Parameters:
      source - source of statistics.
      Returns:
      a map of mean key to (sample, sum) tuples.
    • iostatistics_toPrettyString

      public String iostatistics_toPrettyString(Object statistics)
      Convert IOStatistics to a string form, with all the metrics sorted and empty value stripped.
      Parameters:
      statistics - A statistics instance.
      Returns:
      string value or the empty string if null
      Throws:
      UnsupportedOperationException - if the IOStatistics classes were not found
    • toString

      public String toString()
      Overrides:
      toString in class Object