Class AsyncReader


public class AsyncReader extends ProxyReader
A proxy that reads data asynchronously using a separate thread.
  • Field Details

  • Constructor Details

    • AsyncReader

      public AsyncReader(DataReader reader)
  • Method Details

    • getMaxBufferSizeInBytes

      public long getMaxBufferSizeInBytes()
      Returns the estimated size in bytes of buffered records at which the background thread pauses reading (defaults to 512 KB).
    • setMaxBufferSizeInBytes

      public AsyncReader setMaxBufferSizeInBytes(long maxBufferSize)
      Sets the estimated size in bytes of buffered records at which the background thread pauses reading (defaults to 512 KB, minimum MINIMUM_BUFFER_SIZE).
    • getBufferSizeInBytes

      public long getBufferSizeInBytes()
      Returns the estimated size in bytes of the records buffered but not yet read.
    • getPeakBufferSizeInBytes

      public long getPeakBufferSizeInBytes()
      Returns the largest value getBufferSizeInBytes() has reached.
    • getPriority

      public int getPriority()
      Returns the priority given to the background reading thread when this reader is opened (defaults to Thread.NORM_PRIORITY).
    • setPriority

      public AsyncReader setPriority(int priority)
      Sets the priority given to the background reading thread when this reader is opened, from Thread.MIN_PRIORITY to Thread.MAX_PRIORITY (defaults to Thread.NORM_PRIORITY).
    • getException

      public DataException getException()
      Returns the first exception thrown by the background thread or null if there was none.
    • open

      public void open() throws DataException
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class ProxyReader
      Throws:
      DataException
    • close

      public void close() throws DataException
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class ProxyReader
      Throws:
      DataException
    • push

      public void push(Record record)
      Description copied from class: DataReader
      Adds a record to this DataReaders buffer. Records in the buffer will be returned by DataReader.read() before attempting to read from the underlying implementation.
      Overrides:
      push in class DataReader
      See Also:
    • pop

      protected Record pop()
      Description copied from class: DataReader
      Removes and returns the next record in this DataReaders buffer or null if it is empty.
      Overrides:
      pop in class DataReader
      See Also:
    • available

      public int available() throws DataException
      Description copied from class: DataReader
      Returns the number of records that can probably be read without blocking.
      Overrides:
      available in class ProxyReader
      Throws:
      DataException
    • fillCache

      protected void fillCache()
      Runs on the background thread, reading the nested reader into the buffer (pausing while it is full) until the input ends, this reader is closed or a read fails.
    • rethrowAsyncException

      public void rethrowAsyncException()
      Rethrows the exception thrown by the internal thread or returns silently if no exception was thrown.
    • 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 ProxyReader
      Throws:
      Throwable
    • exception

      public final DataException exception(String message, Throwable exception)
      Description copied from class: DataObject
      Converts an exception to a DataException, prefixing the original message with the specified text and adding this endpoint's properties (name-value pairs).

      The returned exception can then be thrown in the normal way.

      If the supplied exception is an instanceof DataException, it will be returned, otherwise it will be nested inside a DataException. In either case the result message will contain the new prefix along with this endpoint properties.

      Overrides:
      exception in class DataObject
    • exception

      public final DataException exception(Throwable exception)
      Description copied from class: DataObject
      Converts an exception to a DataException and adds this endpoint's properties (name-value pairs).

      The returned exception can then be thrown in the normal way.

      If the supplied exception is an instanceof DataException, it will be returned, otherwise it will be nested inside a DataException. In either case the result message will contain this endpoint properties.

      Overrides:
      exception in class DataObject
    • exception

      public final DataException exception(String message)
      Description copied from class: DataObject
      Creates an exception with the specified message and containing this endpoint's properties (name-value pairs).

      The returned exception can then be thrown in the normal way.

      Overrides:
      exception in class DataObject
    • addExceptionProperties

      public final 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 ProxyReader
    • addExceptionPropertiesImpl

      protected DataException addExceptionPropertiesImpl(DataException exception)
      Adds this reader's own state, but not the nested reader's (it runs on another thread), to the exception; subclasses override this instead of the final addExceptionProperties(DataException).