Class RotatableWriter
- java.lang.Object
-
- org.forgerock.audit.events.handlers.writers.RotatableWriter
-
- All Implemented Interfaces:
TextWriter,RotatableObject
public class RotatableWriter extends Object implements TextWriter, RotatableObject
Supports file rotation and retention.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRotatableWriter.RolloverLifecycleHookCallback hooks to allow custom action to be taken before and after the checks for rotation and retention is performed.-
Nested classes/interfaces inherited from interface org.forgerock.audit.events.handlers.writers.TextWriter
TextWriter.Stream
-
-
Field Summary
Fields Modifier and Type Field Description static RotatableWriter.RolloverLifecycleHookNOOP_ROLLOVER_LIFECYCLE_HOOKA RolloverLifecycleHook that does nothing.
-
Constructor Summary
Constructors Constructor Description RotatableWriter(File file, FileBasedEventHandlerConfiguration configuration, boolean append)Constructs aRotatableWritergiven an initial file to manage rotation/retention, and aFileBasedEventHandlerConfiguration.RotatableWriter(File file, FileBasedEventHandlerConfiguration configuration, boolean append, RotatableWriter.RolloverLifecycleHook rolloverLifecycleHook)Constructs aRotatableWritergiven an initial file to manage rotation/retention, a aFileBasedEventHandlerConfigurationand aRotatableWriter.RolloverLifecycleHook.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the rotatable file.voidflush()Flushes any buffered contents of the output stream.booleanforceRotation()Forces a rotation of the writer.longgetBytesWritten()Retrieves the number of bytes written by this writer.OffsetDateTimegetLastRotationTime()Retrieves the last time the file was rotated.voidregisterRotationHooks(RotationHooks rotationHooks)Registers hooks into the rotation process.booleanrotateIfNeeded()Rotate the log file if any of the configured rotation policies determine that rotation is required.voidshutdown()Releases any resources held by the writer.voidwrite(String str)Writes some text to the output stream.
-
-
-
Field Detail
-
NOOP_ROLLOVER_LIFECYCLE_HOOK
public static final RotatableWriter.RolloverLifecycleHook NOOP_ROLLOVER_LIFECYCLE_HOOK
A RolloverLifecycleHook that does nothing.
-
-
Constructor Detail
-
RotatableWriter
public RotatableWriter(File file, FileBasedEventHandlerConfiguration configuration, boolean append) throws IOException
Constructs aRotatableWritergiven an initial file to manage rotation/retention, and aFileBasedEventHandlerConfiguration.- Parameters:
file- The initial file to manage rotation/retention.configuration- The configuration of the rotation and retention policies.append- Whether to append to the rotatable file or not.- Throws:
IOException- If a problem occurs.
-
RotatableWriter
public RotatableWriter(File file, FileBasedEventHandlerConfiguration configuration, boolean append, RotatableWriter.RolloverLifecycleHook rolloverLifecycleHook) throws IOException
Constructs aRotatableWritergiven an initial file to manage rotation/retention, a aFileBasedEventHandlerConfigurationand aRotatableWriter.RolloverLifecycleHook.- Parameters:
file- The initial file to manage rotation/retention.configuration- The configuration of the rotation and retention policies.append- Whether to append to the rotatable file or not.rolloverLifecycleHook- Hook to use before and after rotation/retention checks.- Throws:
IOException- If a problem occurs.
-
-
Method Detail
-
rotateIfNeeded
public boolean rotateIfNeeded() throws IOExceptionRotate the log file if any of the configured rotation policies determine that rotation is required.- Specified by:
rotateIfNeededin interfaceRotatableObject- Returns:
trueif rotation took place.- Throws:
IOException- If unable to rotate the log file.
-
getBytesWritten
public long getBytesWritten()
Description copied from interface:TextWriterRetrieves the number of bytes written by this writer.- Specified by:
getBytesWrittenin interfaceRotatableObject- Specified by:
getBytesWrittenin interfaceTextWriter- Returns:
- the number of bytes written by this writer.
-
getLastRotationTime
public OffsetDateTime getLastRotationTime()
Description copied from interface:RotatableObjectRetrieves the last time the file was rotated. If a file rotation never occurred, this value will be the time the server started.- Specified by:
getLastRotationTimein interfaceRotatableObject- Returns:
- The last time file rotation occurred.
-
close
public void close() throws IOExceptionDescription copied from interface:RotatableObjectCloses the rotatable file.- Specified by:
closein interfaceRotatableObject- Throws:
IOException- If an exception occurs while closing.
-
shutdown
public void shutdown()
Description copied from interface:TextWriterReleases any resources held by the writer.- Specified by:
shutdownin interfaceTextWriter
-
registerRotationHooks
public void registerRotationHooks(RotationHooks rotationHooks)
Description copied from interface:RotatableObjectRegisters hooks into the rotation process.- Specified by:
registerRotationHooksin interfaceRotatableObject- Parameters:
rotationHooks- TheRotationHooksinto the rotation process.
-
write
public void write(String str) throws IOException
Description copied from interface:TextWriterWrites some text to the output stream.- Specified by:
writein interfaceTextWriter- Parameters:
str- The text to write- Throws:
IOException- If a problem occurs.
-
forceRotation
public boolean forceRotation() throws IOExceptionForces a rotation of the writer.- Returns:
trueif rotation was done,falseotherwise.- Throws:
IOException- If an error occurs
-
flush
public void flush() throws IOExceptionDescription copied from interface:TextWriterFlushes any buffered contents of the output stream.- Specified by:
flushin interfaceTextWriter- Throws:
IOException- If a problem occurs.
-
-