Class LogFile

java.lang.Object
org.objectweb.howl.log.LogFile

class LogFile extends Object
An individual file within a set of log files managed by a Logger.

The Logger will create an instance of LogFile for each physical file that is configured for the Logger.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) long
    total number of data written.
    (package private) FileChannel
    FileChannel associated with this LogFile.
    (package private) File
     
    (package private) String
     
    (package private) int
    BSN of first block in the file.
    (package private) long
    log key for the first record in the next file.
    (package private) FileLock
    FileLock acquired when file is opened.
    (package private) boolean
    indicates the file was created during the call to open()
    (package private) long
    FileChannel.position() of last read or write.
    (package private) int
    number of times this file position was reset to zero.
    (package private) long
    currentTimeMillis when LogFileManager switched to this LogFile.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LogFile(File file)
    construct an instance of LogFile for a given file name
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) LogFile
    Close the channel associated with this LogFile.
    (package private) void
    force(boolean forceMetadata)
    Helper provides access to the FileChannel.force() method for the FileChannel associated with this LogFile.
    (package private) String
    return statistics for this LogFile as an XML string.
    (package private) LogFile
    open(String fileMode)
    open the file and get the associated nio FileChannel for the file.
    (package private) void
    Helper provides access to the FileChannel.write() method for the FileChannel associated with this LogFile.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • file

      File file
    • fileMode

      String fileMode
      See Also:
    • channel

      FileChannel channel
      FileChannel associated with this LogFile.

      The FileChannel is private to guarantee that all calls to the channel methods come through this LogFile object to allow for statistics collection.

    • rewindCounter

      int rewindCounter
      number of times this file position was reset to zero.
    • bytesWritten

      long bytesWritten
      total number of data written.
    • highMark

      long highMark
      log key for the first record in the next file.

      when a file switch occurs, the LogFileManager stores the mark for the file header record of the next log file into this LogFile object. Effectively, any mark with a value less than the header record for the next log file resides in this or some previous log file.

      Later, when this LogFile object is about to be reused, the value for the active mark is compared with the highMark value. If the active mark is less than highMark, then a LogFileOverflowException is thrown to prevent re-use of a log file that contains active data.

      While this LogFile is the current LogFile of the set, (ie, the LogFile that is currently being written to) the highMark will be set to first record of the subsequent block. For example, while block 1 is being written, highMark will be set to the first record of block 2.

      During replay operations, the end of the active journal can be detected by comparing the BSN of a desired block with the current highMark. If the requested BSN is less than highMark, then the requested block resides within active journal space. If the requested BSN is >= the highMark, then the BSN is invalid.

      Any attempt to add records to the log will cause an exception until Logger.mark() is called to clear prior records from the log.

    • firstBSN

      int firstBSN
      BSN of first block in the file.

      Initialized by LogFileManager and updated as log files are reused.

      Used by LogFileManager.read() to calculate offset into a file to read a specific block.

    • tod

      long tod
      currentTimeMillis when LogFileManager switched to this LogFile.
    • position

      long position
      FileChannel.position() of last read or write.

      May be used to report the file position when IOException occurs.

    • newFile

      boolean newFile
      indicates the file was created during the call to open()
      See Also:
    • lock

      FileLock lock
      FileLock acquired when file is opened.
  • Constructor Details

    • LogFile

      LogFile(File file)
      construct an instance of LogFile for a given file name
      Parameters:
      file - filename
  • Method Details

    • open

      open the file and get the associated nio FileChannel for the file.

      If the file does not exist, then the newFile member is set true.

      Parameters:
      fileMode - value passed to RandomAccessFile constructor.
      Throws:
      FileNotFoundException - if the parent directory structure does not exist.
      LogConfigurationException
      See Also:
    • close

      LogFile close() throws IOException
      Close the channel associated with this LogFile.

      Also releases the lock that is held on the file.

      Returns:
      this LogFile
      Throws:
      IOException
    • write

      void write(LogBuffer lb) throws IOException
      Helper provides access to the FileChannel.write() method for the FileChannel associated with this LogFile.
      Parameters:
      lb - Reference to a LogBuffer object that is to be written.
      Throws:
      IOException
    • force

      void force(boolean forceMetadata) throws IOException
      Helper provides access to the FileChannel.force() method for the FileChannel associated with this LogFile.

      Hides actual FileChannel and allows capture of statistics.

      In theory the force could be eliminated if the file is open with mode "rwd" or "rws" because the access method is supposed to guarantee that the writes do not return until the data is on the media. Unfortunately, testing with Windows XP platforms suggests that system write cache may confuse the Java runtime and the program will actually return before data is on media. Consequently, this method *always* does a force() regardless of the file open mode.

      Parameters:
      forceMetadata - as defined by FileChannel.force()
      Throws:
      IOException
      See Also:
    • getStats

      String getStats()
      return statistics for this LogFile as an XML string.
      Returns:
      XML string containing LogFile statistics.