org.ka2ddo.yaac.core
Class FileLogger<T>

java.lang.Object
  extended by java.util.TimerTask
      extended by org.ka2ddo.yaac.core.FileLogger<T>
All Implemented Interfaces:
java.lang.Runnable, ShutdownHandler
Direct Known Subclasses:
AX25Logger, GPSLogger

public abstract class FileLogger<T>
extends java.util.TimerTask
implements ShutdownHandler

This class implements a generic time-batched logging facility for an arbitrary record type T in a date-rolled sequential logging file.


Constructor Summary
protected FileLogger(java.lang.String prefix, java.lang.String datePattern, java.lang.String suffix, int flushEveryNSeconds)
          Create a FileLogger using the specified file prefix, date pattern, suffix, and flush interval, storing the log files in YAAC's default log directory.
protected FileLogger(java.lang.String prefix, java.lang.String datePattern, java.lang.String suffix, int flushEveryNSeconds, java.lang.String logDirPath)
          Create a FileLogger using the specified file prefix, date pattern, suffix, and flush interval, storing the log files in the explicitly specified log directory.
 
Method Summary
abstract  void dumpRecordQueueToFile(java.io.File logFileFile, java.util.ArrayList<T> recordQueue)
          Subclasses should implement this method to open the specified sequential file for append, then write each of the records in the recordQueue in order to the file, then close the file.
 void flush()
          Dump the current contents of the backlog queue to the current log file.
 void log(T record)
          Append one record to the log file, using asynchronous background writing.
 void log(T record, java.util.Date date)
          Append one record to the log file, using asynchronous background writing.
 void log(T record, long date)
          Append one record to the log file, using asynchronous background writing.
 void run()
           
 void setDatePattern(java.lang.String datePattern)
           
static void setDefaultLogDir(java.lang.String defaultLogDirPath)
           
 void setFilePrefix(java.lang.String prefix)
          Change the constant prefix that should be used before the date part of the log file name.
 void setFileSuffix(java.lang.String suffix)
          Change the constant suffix that should be used after the date part of the log file name.
 void setFlushInterval(int flushEveryNSeconds)
          Set how frequently the logger should dump its backlog queue to disk and close the file for checkpointing.
 void setLogDirectory(java.lang.String logDirPath)
          Set the directory in which log files should be created.
 void shutdown()
          Do whatever cleanup this object needs for program shutdown.
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileLogger

protected FileLogger(java.lang.String prefix,
                     java.lang.String datePattern,
                     java.lang.String suffix,
                     int flushEveryNSeconds)
Create a FileLogger using the specified file prefix, date pattern, suffix, and flush interval, storing the log files in YAAC's default log directory.

Parameters:
prefix - String file name prefix (before the date)
datePattern - format string for file name embedded date, using SimpleDateFormat directives
suffix - String file name suffix (after the date)
flushEveryNSeconds - the interval between log flushes in seconds
See Also:
setDefaultLogDir(String)

FileLogger

protected FileLogger(java.lang.String prefix,
                     java.lang.String datePattern,
                     java.lang.String suffix,
                     int flushEveryNSeconds,
                     java.lang.String logDirPath)
Create a FileLogger using the specified file prefix, date pattern, suffix, and flush interval, storing the log files in the explicitly specified log directory.

Parameters:
prefix - String file name prefix (before the date)
datePattern - format string for file name embedded date, using SimpleDateFormat directives
suffix - String file name suffix (after the date)
flushEveryNSeconds - the interval between log flushes in seconds
logDirPath - String path name of directory to contain the log files
Method Detail

setLogDirectory

public void setLogDirectory(java.lang.String logDirPath)
Set the directory in which log files should be created. If the directory does not exist, this method will attempt to create it.

Parameters:
logDirPath - String pathname of log-containing directory

setDefaultLogDir

public static void setDefaultLogDir(java.lang.String defaultLogDirPath)

setFlushInterval

public void setFlushInterval(int flushEveryNSeconds)
Set how frequently the logger should dump its backlog queue to disk and close the file for checkpointing.

Parameters:
flushEveryNSeconds - the interval in seconds between file closes

setDatePattern

public void setDatePattern(java.lang.String datePattern)

setFilePrefix

public void setFilePrefix(java.lang.String prefix)
Change the constant prefix that should be used before the date part of the log file name.

Parameters:
prefix - String name prefix

setFileSuffix

public void setFileSuffix(java.lang.String suffix)
Change the constant suffix that should be used after the date part of the log file name.

Parameters:
suffix - String name suffix

log

public void log(T record)
Append one record to the log file, using asynchronous background writing.

Parameters:
record - data record to log of the specified generic type

log

public void log(T record,
                java.util.Date date)
Append one record to the log file, using asynchronous background writing.

Parameters:
record - data record to log of the specified generic type
date - Date when record was created, received, etc.

log

public void log(T record,
                long date)
Append one record to the log file, using asynchronous background writing.

Parameters:
record - data record to log of the specified generic type
date - long timestamp in milliseconds since midnight Jan 19 1970 UTC when record was created, received, etc.

flush

public void flush()
Dump the current contents of the backlog queue to the current log file.


dumpRecordQueueToFile

public abstract void dumpRecordQueueToFile(java.io.File logFileFile,
                                           java.util.ArrayList<T> recordQueue)
                                    throws java.io.IOException
Subclasses should implement this method to open the specified sequential file for append, then write each of the records in the recordQueue in order to the file, then close the file.

Parameters:
logFileFile - File identifying the log file to open and write
recordQueue - the ArrayList of ordered records to write
Throws:
java.io.IOException - if record saving fails for any reason

run

public final void run()
Specified by:
run in interface java.lang.Runnable
Specified by:
run in class java.util.TimerTask

shutdown

public void shutdown()
Do whatever cleanup this object needs for program shutdown.

Specified by:
shutdown in interface ShutdownHandler