Class AsynchronousTextWriter

java.lang.Object
org.forgerock.audit.events.handlers.writers.AsynchronousTextWriter
All Implemented Interfaces:
TextWriter

public class AsynchronousTextWriter extends Object implements TextWriter
A Text Writer which writes log records asynchronously to character-based stream.

The records are buffered in a queue and written asynchronously. If maximum CAPACITY of the queue is reached, then calls to write() method are blocked. This prevent OOM errors while allowing good write performances.

  • Constructor Details

    • AsynchronousTextWriter

      public AsynchronousTextWriter(String name, boolean autoFlush, TextWriter writer)
      Construct a new AsynchronousTextWriter wrapper.
      Parameters:
      name - the name of the thread.
      autoFlush - indicates if the underlying writer should be flushed after the queue is flushed.
      writer - a character stream used for output.
  • Method Details

    • write

      public void write(String record) throws IOException
      Write the log record asynchronously.
      Specified by:
      write in interface TextWriter
      Parameters:
      record - the log record to write.
      Throws:
      IOException - If a problem occurs.
    • flush

      public void flush()
      Description copied from interface: TextWriter
      Flushes any buffered contents of the output stream.
      Specified by:
      flush in interface TextWriter
    • getBytesWritten

      public long getBytesWritten()
      Retrieves the number of bytes written by this writer.
      Specified by:
      getBytesWritten in interface TextWriter
      Returns:
      the number of bytes written by this writer.
    • getWrappedWriter

      public TextWriter getWrappedWriter()
      Retrieves the wrapped writer.
      Returns:
      The wrapped writer used by this asynchronous writer.
    • shutdown

      public void shutdown()
      Releases any resources held by the writer.
      Specified by:
      shutdown in interface TextWriter
    • shutdown

      public void shutdown(boolean shutdownWrapped)
      Releases any resources held by the writer.
      Parameters:
      shutdownWrapped - If the wrapped writer should be closed as well.