Class ThrottledReader

All Implemented Interfaces:
Metered, Throttled

public class ThrottledReader extends MeteredReader implements Throttled
A proxy that limits the rate (bytes/second) at which data is read.
  • Constructor Details

    • ThrottledReader

      public ThrottledReader(DataReader reader, int bytesPerSecond)
      Creates a reader that limits reading to bytesPerSecond on average, counting each record's estimated size in bytes.
    • ThrottledReader

      public ThrottledReader(DataReader reader, int unitsPerSecond, RecordMeter.MeterUnit units)
      Creates a reader that limits reading to unitsPerSecond on average, counting bytes or records depending on units.
  • Method Details

    • getThrottle

      public Throttle getThrottle()
      Specified by:
      getThrottle in interface Throttled
    • getMeasure

      public RecordMeter.MeterUnit getMeasure()
      Returns whether the limit counts records or their estimated size in bytes (defaults to BYTES).
    • setMeasure

      public ThrottledReader setMeasure(RecordMeter.MeterUnit measure)
      Sets whether the limit counts records or their estimated size in bytes (defaults to BYTES).
    • readImpl

      protected Record readImpl() throws Throwable
      Description copied from class: DataReader
      Overridden by subclasses to read the next record from this DataReader. The default implementation of DataReader.read() now insures that this method will not be called again after it returns a null.

      If no record is available, null will be returned.

      Contract for subclasses (see also docs/authoring/DataReader.md):

      Overrides:
      readImpl in class MeteredReader
      Throws:
      Throwable
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class MeteredReader