org.opends.server.loggers
Class MultifileTextWriter

java.lang.Object
  extended by org.opends.server.loggers.MultifileTextWriter
All Implemented Interfaces:
ConfigurationChangeListener<SizeLimitLogRotationPolicyCfg>, ServerShutdownListener, TextWriter

public class MultifileTextWriter
extends java.lang.Object
implements ServerShutdownListener, TextWriter, ConfigurationChangeListener<SizeLimitLogRotationPolicyCfg>

A MultiFileTextWriter is a specialized TextWriter which supports publishing log records to a set of files. MultiFileWriters write to one file in the set at a time, switching files as is dictated by a specified rotation and retention policies. When a switch is required, the writer closes the current file and opens a new one named in accordance with a specified FileNamingPolicy.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.opends.server.loggers.TextWriter
TextWriter.STDERR, TextWriter.STDOUT, TextWriter.STREAM
 
Constructor Summary
MultifileTextWriter(java.lang.String name, long interval, FileNamingPolicy namingPolicy, FilePermission filePermissions, LogPublisherErrorHandler errorHandler, java.lang.String encoding, boolean autoFlush, boolean append, int bufferSize)
          Creates a new instance of MultiFileTextWriter with the supplied policies.
 
Method Summary
 void addRetentionPolicy(RetentionPolicy policy)
          Add a retention policy to enforce on the files written by this writer.
 void addRotationPolicy(RotationPolicy policy)
          Add a rotation policy to enforce on the files written by this writer.
 ConfigChangeResult applyConfigurationChange(SizeLimitLogRotationPolicyCfg config)
          Applies the configuration changes to this change listener.
 void flush()
          Flushes any buffered contents of the output stream.
 long getBytesWritten()
          Retrieves the number of bytes written to the current log file.
 long getLastCleanCount()
          Retrieves the number of files cleaned in the last cleanup run.
 java.util.Calendar getLastCleanTime()
          Retrieves the last time one or more log files are cleaned in this instance of the Directory Server.
 java.util.Calendar getLastRotationTime()
          Retrieves the last time a log file was rotated in this instance of Directory Server.
 FileNamingPolicy getNamingPolicy()
          Retrieves the current naming policy used to generate log file names.
 java.lang.String getShutdownListenerName()
          Retrieves the human-readable name for this shutdown listener.
 long getTotalFilesCleaned()
          Retrieves the total number of files cleaned in this instance of the Directory Server.
 long getTotalFilesRotated()
          Retrieves the total number file rotations occurred in this instance of the Directory Server.
 boolean isConfigurationChangeAcceptable(SizeLimitLogRotationPolicyCfg config, java.util.List<Message> unacceptableReasons)
          Indicates whether the proposed change to the configuration is acceptable to this change listener.
 void processServerShutdown(Message reason)
          Indicates that the Directory Server has received a request to stop running and that this shutdown listener should take any action necessary to prepare for it.
 void removeAllRetentionPolicies()
          Removes all retention policies being enforced by this writer.
 void removeAllRotationPolicies()
          Removes all the rotation policies currently enforced by this writer.
 void rotate()
          Tries to rotate the log files.
 void setAppend(boolean append)
          Set the append setting for this writter.
 void setAutoFlush(boolean autoFlush)
          Set the auto flush setting for this writer.
 void setBufferSize(int bufferSize)
          Set the buffer size for this writter.
 void setFilePermissions(FilePermission filePermissions)
          Set the file permission to set for newly created log files.
 void setInterval(long interval)
          Set the internval in which the rotator thread checks to see if the log file should be rotated.
 void setNamingPolicy(FileNamingPolicy namingPolicy)
          Set the naming policy to use when generating new log files.
 void setPostRotationActions(java.util.ArrayList<ActionType> actions)
          This method sets the actions that need to be executed after rotation.
 void shutdown()
          Shutdown the text writer.
 void writeRecord(java.lang.String record)
          Write a log record string to the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultifileTextWriter

public MultifileTextWriter(java.lang.String name,
                           long interval,
                           FileNamingPolicy namingPolicy,
                           FilePermission filePermissions,
                           LogPublisherErrorHandler errorHandler,
                           java.lang.String encoding,
                           boolean autoFlush,
                           boolean append,
                           int bufferSize)
                    throws java.io.IOException,
                           DirectoryException
Creates a new instance of MultiFileTextWriter with the supplied policies.

Parameters:
name - the name of the log rotation thread.
interval - the interval to check whether the logs need to be rotated.
namingPolicy - the file naming policy to use to name rotated log. files.
filePermissions - the file permissions to set on the log files.
errorHandler - the log publisher error handler to notify when an error occurs.
encoding - the encoding to use to write the log files.
autoFlush - whether to flush the writer on every println.
append - whether to append to an existing log file.
bufferSize - the bufferSize to use for the writer.
Throws:
java.io.IOException - if an error occurs while creating the log file.
DirectoryException - if an error occurs while preping the new log file.
Method Detail

addRotationPolicy

public void addRotationPolicy(RotationPolicy policy)
Add a rotation policy to enforce on the files written by this writer.

Parameters:
policy - The rotation policy to add.

addRetentionPolicy

public void addRetentionPolicy(RetentionPolicy policy)
Add a retention policy to enforce on the files written by this writer.

Parameters:
policy - The retention policy to add.

removeAllRotationPolicies

public void removeAllRotationPolicies()
Removes all the rotation policies currently enforced by this writer.


removeAllRetentionPolicies

public void removeAllRetentionPolicies()
Removes all retention policies being enforced by this writer.


setAutoFlush

public void setAutoFlush(boolean autoFlush)
Set the auto flush setting for this writer.

Parameters:
autoFlush - If the writer should flush the buffer after every line.

setAppend

public void setAppend(boolean append)
Set the append setting for this writter.

Parameters:
append - If the writer should append to an existing file.

setBufferSize

public void setBufferSize(int bufferSize)
Set the buffer size for this writter.

Parameters:
bufferSize - The size of the underlying output stream buffer.

setFilePermissions

public void setFilePermissions(FilePermission filePermissions)
Set the file permission to set for newly created log files.

Parameters:
filePermissions - The file permission to set for new log files.

getNamingPolicy

public FileNamingPolicy getNamingPolicy()
Retrieves the current naming policy used to generate log file names.

Returns:
The current naming policy in use.

setNamingPolicy

public void setNamingPolicy(FileNamingPolicy namingPolicy)
Set the naming policy to use when generating new log files.

Parameters:
namingPolicy - the naming policy to use to name log files.

setInterval

public void setInterval(long interval)
Set the internval in which the rotator thread checks to see if the log file should be rotated.

Parameters:
interval - The interval to check if the log file needs to be rotated.

isConfigurationChangeAcceptable

public boolean isConfigurationChangeAcceptable(SizeLimitLogRotationPolicyCfg config,
                                               java.util.List<Message> unacceptableReasons)
Indicates whether the proposed change to the configuration is acceptable to this change listener.

Specified by:
isConfigurationChangeAcceptable in interface ConfigurationChangeListener<SizeLimitLogRotationPolicyCfg>
Parameters:
config - The new configuration containing the changes.
unacceptableReasons - A list that can be used to hold messages about why the provided configuration is not acceptable.
Returns:
Returns true if the proposed change is acceptable, or false if it is not.

applyConfigurationChange

public ConfigChangeResult applyConfigurationChange(SizeLimitLogRotationPolicyCfg config)
Applies the configuration changes to this change listener.

Specified by:
applyConfigurationChange in interface ConfigurationChangeListener<SizeLimitLogRotationPolicyCfg>
Parameters:
config - The new configuration containing the changes.
Returns:
Returns information about the result of changing the configuration.

getShutdownListenerName

public java.lang.String getShutdownListenerName()
Retrieves the human-readable name for this shutdown listener.

Specified by:
getShutdownListenerName in interface ServerShutdownListener
Returns:
The human-readable name for this shutdown listener.

processServerShutdown

public void processServerShutdown(Message reason)
Indicates that the Directory Server has received a request to stop running and that this shutdown listener should take any action necessary to prepare for it.

Specified by:
processServerShutdown in interface ServerShutdownListener
Parameters:
reason - The human-readable reason for the shutdown.

shutdown

public void shutdown()
Shutdown the text writer.

Specified by:
shutdown in interface TextWriter

writeRecord

public void writeRecord(java.lang.String record)
Write a log record string to the file.

Specified by:
writeRecord in interface TextWriter
Parameters:
record - the log record to write.

flush

public void flush()
Flushes any buffered contents of the output stream.

Specified by:
flush in interface TextWriter

rotate

public void rotate()
Tries to rotate the log files. If the new log file already exists, it tries to rename the file. On failure, all subsequent log write requests will throw exceptions.


setPostRotationActions

public void setPostRotationActions(java.util.ArrayList<ActionType> actions)
This method sets the actions that need to be executed after rotation.

Parameters:
actions - An array of actions that need to be executed on rotation.

getBytesWritten

public long getBytesWritten()
Retrieves the number of bytes written to the current log file.

Specified by:
getBytesWritten in interface TextWriter
Returns:
The number of bytes written to the current log file.

getLastCleanTime

public java.util.Calendar getLastCleanTime()
Retrieves the last time one or more log files are cleaned in this instance of the Directory Server. If log files have never been cleaned, this value will be the time the server started.

Returns:
The last time log files are cleaned.

getLastCleanCount

public long getLastCleanCount()
Retrieves the number of files cleaned in the last cleanup run.

Returns:
The number of files cleaned int he last cleanup run.

getLastRotationTime

public java.util.Calendar getLastRotationTime()
Retrieves the last time a log file was rotated in this instance of Directory Server. If a log rotation never occurred, this value will be the time the server started.

Returns:
The last time log rotation occurred.

getTotalFilesRotated

public long getTotalFilesRotated()
Retrieves the total number file rotations occurred in this instance of the Directory Server.

Returns:
The total number of file rotations.

getTotalFilesCleaned

public long getTotalFilesCleaned()
Retrieves the total number of files cleaned in this instance of the Directory Server.

Returns:
The total number of files cleaned.