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
ConstructorsConstructorDescriptionAsynchronousTextWriter(String name, boolean autoFlush, TextWriter writer) Construct a new AsynchronousTextWriter wrapper. -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()Flushes any buffered contents of the output stream.longRetrieves the number of bytes written by this writer.Retrieves the wrapped writer.voidshutdown()Releases any resources held by the writer.voidshutdown(boolean shutdownWrapped) Releases any resources held by the writer.voidWrite 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:
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
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.
-