Class AsyncWriter


public class AsyncWriter extends ProxyWriter
A proxy that writes data asynchronously using a separate thread.
  • Constructor Details

    • AsyncWriter

      public AsyncWriter(DataWriter nestedDataWriter, int maxQueuedRecords)
      Creates an AsyncWriter object, with the given DataWriter and maximum number of records that can be queued.
    • AsyncWriter

      public AsyncWriter(DataWriter nestedDataWriter)
      Creates an AsyncWriter object, with the given DataWriter and default capacity of 500 records that can be queued.
  • Method Details

    • getBufferSizeInBytes

      public long getBufferSizeInBytes()
      Returns the estimated size in bytes of the records queued but not yet passed to the nested writer.
    • getPeakBufferSizeInBytes

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

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

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

      public DataException getException()
      Returns the background thread's failure that has not yet been rethrown to the caller or null if there is none.
    • open

      public void open() throws DataException
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class ProxyWriter
      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 ProxyWriter
      Throws:
      DataException
    • available

      public int available() throws DataException
      Description copied from class: DataWriter
      Returns the number of records that can probably be written without blocking.
      Overrides:
      available in class ProxyWriter
      Throws:
      DataException
    • write

      public void write(Record record) throws DataException
      Description copied from class: DataWriter
      Writes the specified record to this DataWriter and increases the record-count by 1. Any exception raised while writing will be converted to a DataException using DataObject.exception(Throwable).

      Subclasses generally do not need to override this method, instead they should implement DataWriter.writeImpl(Record).

      Overrides:
      write in class DataWriter
      Throws:
      DataException
    • writeImpl

      protected void writeImpl(Record record) throws Throwable
      Description copied from class: DataWriter
      Overridden by subclasses to write the specified record to this DataWriter.

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

      Overrides:
      writeImpl in class ProxyWriter
      Throws:
      Throwable
    • rethrowAsyncException

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

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