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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.forgerock.audit.events.handlers.writers.TextWriter
TextWriter.Stream
-
-
Constructor Summary
Constructors Constructor Description AsynchronousTextWriter(String name, boolean autoFlush, TextWriter writer)
Construct a new AsynchronousTextWriter wrapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
flush()
Flushes any buffered contents of the output stream.long
getBytesWritten()
Retrieves the number of bytes written by this writer.TextWriter
getWrappedWriter()
Retrieves the wrapped writer.void
shutdown()
Releases any resources held by the writer.void
shutdown(boolean shutdownWrapped)
Releases any resources held by the writer.void
write(String record)
Write the log record asynchronously.
-
-
-
Constructor Detail
-
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 Detail
-
write
public void write(String record) throws IOException
Write the log record asynchronously.- Specified by:
write
in interfaceTextWriter
- 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 interfaceTextWriter
-
getBytesWritten
public long getBytesWritten()
Retrieves the number of bytes written by this writer.- Specified by:
getBytesWritten
in interfaceTextWriter
- 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 interfaceTextWriter
-
shutdown
public void shutdown(boolean shutdownWrapped)
Releases any resources held by the writer.- Parameters:
shutdownWrapped
- If the wrapped writer should be closed as well.
-
-