Class RotatableWriter
java.lang.Object
org.forgerock.audit.events.handlers.writers.RotatableWriter
- All Implemented Interfaces:
TextWriter
,RotatableObject
Supports file rotation and retention.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Callback 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
Modifier and TypeFieldDescriptionstatic final RotatableWriter.RolloverLifecycleHook
A RolloverLifecycleHook that does nothing. -
Constructor Summary
ConstructorDescriptionRotatableWriter
(File file, FileBasedEventHandlerConfiguration configuration, boolean append) Constructs aRotatableWriter
given an initial file to manage rotation/retention, and aFileBasedEventHandlerConfiguration
.RotatableWriter
(File file, FileBasedEventHandlerConfiguration configuration, boolean append, RotatableWriter.RolloverLifecycleHook rolloverLifecycleHook) Constructs aRotatableWriter
given an initial file to manage rotation/retention, a aFileBasedEventHandlerConfiguration
and aRotatableWriter.RolloverLifecycleHook
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the rotatable file.void
flush()
Flushes any buffered contents of the output stream.boolean
Forces a rotation of the writer.long
Retrieves the number of bytes written by this writer.Retrieves the last time the file was rotated.void
registerRotationHooks
(RotationHooks rotationHooks) Registers hooks into the rotation process.boolean
Rotate the log file if any of the configured rotation policies determine that rotation is required.void
shutdown()
Releases any resources held by the writer.void
Writes some text to the output stream.
-
Field Details
-
NOOP_ROLLOVER_LIFECYCLE_HOOK
A RolloverLifecycleHook that does nothing.
-
-
Constructor Details
-
RotatableWriter
public RotatableWriter(File file, FileBasedEventHandlerConfiguration configuration, boolean append) throws IOException Constructs aRotatableWriter
given 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 aRotatableWriter
given an initial file to manage rotation/retention, a aFileBasedEventHandlerConfiguration
and 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 Details
-
rotateIfNeeded
Rotate the log file if any of the configured rotation policies determine that rotation is required.- Specified by:
rotateIfNeeded
in interfaceRotatableObject
- Returns:
true
if rotation took place.- Throws:
IOException
- If unable to rotate the log file.
-
getBytesWritten
public long getBytesWritten()Description copied from interface:TextWriter
Retrieves the number of bytes written by this writer.- Specified by:
getBytesWritten
in interfaceRotatableObject
- Specified by:
getBytesWritten
in interfaceTextWriter
- Returns:
- the number of bytes written by this writer.
-
getLastRotationTime
Description copied from interface:RotatableObject
Retrieves the last time the file was rotated. If a file rotation never occurred, this value will be the time the server started.- Specified by:
getLastRotationTime
in interfaceRotatableObject
- Returns:
- The last time file rotation occurred.
-
close
Description copied from interface:RotatableObject
Closes the rotatable file.- Specified by:
close
in interfaceRotatableObject
- Throws:
IOException
- If an exception occurs while closing.
-
shutdown
public void shutdown()Description copied from interface:TextWriter
Releases any resources held by the writer.- Specified by:
shutdown
in interfaceTextWriter
-
registerRotationHooks
Description copied from interface:RotatableObject
Registers hooks into the rotation process.- Specified by:
registerRotationHooks
in interfaceRotatableObject
- Parameters:
rotationHooks
- TheRotationHooks
into the rotation process.
-
write
Description copied from interface:TextWriter
Writes some text to the output stream.- Specified by:
write
in interfaceTextWriter
- Parameters:
str
- The text to write- Throws:
IOException
- If a problem occurs.
-
forceRotation
Forces a rotation of the writer.- Returns:
true
if rotation was done,false
otherwise.- Throws:
IOException
- If an error occurs
-
flush
Description copied from interface:TextWriter
Flushes any buffered contents of the output stream.- Specified by:
flush
in interfaceTextWriter
- Throws:
IOException
- If a problem occurs.
-