Class AsynchronousTextWriter
java.lang.Object
org.forgerock.audit.events.handlers.writers.AsynchronousTextWriter
- All Implemented Interfaces:
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
ConstructorDescriptionAsynchronousTextWriter
(String name, boolean autoFlush, TextWriter writer) Construct a new AsynchronousTextWriter wrapper. -
Method Summary
Modifier and TypeMethodDescriptionvoid
flush()
Flushes any buffered contents of the output stream.long
Retrieves the number of bytes written by this writer.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 the log record asynchronously.
-
Constructor Details
-
AsynchronousTextWriter
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
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
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.
-