Class LogWriter

  • All Implemented Interfaces:
    ILogWriter

    public class LogWriter
    extends java.lang.Object
    implements ILogWriter
    LogWriter writes the binary logs into a file using FileChannel together with check sums of each log calculated using CRC32.
    • Constructor Summary

      Constructors 
      Constructor Description
      LogWriter​(java.io.File logFile, boolean forceEachWrite)  
      LogWriter​(java.lang.String logFilePath, boolean forceEachWrite)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      release resources occupied by this object, like file streams.
      void force()
      force the OS/FileSystem to flush its cache to make sure logs are persisted.
      java.lang.String toString()  
      void write​(java.nio.ByteBuffer logBuffer)
      Write given logs to a persistent medium.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • LogWriter

        public LogWriter​(java.lang.String logFilePath,
                         boolean forceEachWrite)
                  throws java.io.FileNotFoundException
        Parameters:
        logFilePath -
        forceEachWrite -
        Throws:
        java.io.FileNotFoundException
      • LogWriter

        public LogWriter​(java.io.File logFile,
                         boolean forceEachWrite)
                  throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
    • Method Detail

      • write

        public void write​(java.nio.ByteBuffer logBuffer)
                   throws java.io.IOException
        Description copied from interface: ILogWriter
        Write given logs to a persistent medium. NOTICE: the logs may be cached in the OS/FileSystem, if the OS/FileSystem you are using do not guarantee strong persistency and you want the logs to be persisted immediately, please call force() after calling this method. Notice: do not flip the buffer before calling this method
        Specified by:
        write in interface ILogWriter
        Parameters:
        logBuffer - WAL logs that have been converted to bytes
        Throws:
        java.io.IOException
      • force

        public void force()
                   throws java.io.IOException
        Description copied from interface: ILogWriter
        force the OS/FileSystem to flush its cache to make sure logs are persisted.
        Specified by:
        force in interface ILogWriter
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: ILogWriter
        release resources occupied by this object, like file streams.
        Specified by:
        close in interface ILogWriter
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object