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 voidflush()Flushes any buffered contents of the output stream.longgetBytesWritten()Retrieves the number of bytes written by this writer.TextWritergetWrappedWriter()Retrieves the wrapped writer.voidshutdown()Releases any resources held by the writer.voidshutdown(boolean shutdownWrapped)Releases any resources held by the writer.voidwrite(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:
writein interfaceTextWriter- Parameters:
record- the log record to write.- Throws:
IOException- If a problem occurs.
-
flush
public void flush()
Description copied from interface:TextWriterFlushes any buffered contents of the output stream.- Specified by:
flushin interfaceTextWriter
-
getBytesWritten
public long getBytesWritten()
Retrieves the number of bytes written by this writer.- Specified by:
getBytesWrittenin 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:
shutdownin 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.
-
-