Interface LogWriter

  • All Superinterfaces:
    java.lang.AutoCloseable
    All Known Implementing Classes:
    DirectWriter

    interface LogWriter
    extends java.lang.AutoCloseable
    Interface for writing data to a bookkeeper entry log.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void close()
      Close any held resources.
      void flush()
      Flush all buffered writes to disk.
      int logId()
      Return the ID of the log being written.
      long position()
      The current offset within the log at which the next call to #writeDelimited will start writing.
      void position​(long offset)
      Set the offset within the log at which the next call to #writeDelimited will start writing.
      int serializedSize​(io.netty.buffer.ByteBuf buf)  
      void writeAt​(long offset, io.netty.buffer.ByteBuf buf)
      Write the contents of a buffer at a predefined position in the log.
      int writeDelimited​(io.netty.buffer.ByteBuf buf)
      Write a delimited buffer the log.
    • Method Detail

      • logId

        int logId()
        Return the ID of the log being written.
      • writeAt

        void writeAt​(long offset,
                     io.netty.buffer.ByteBuf buf)
              throws java.io.IOException
        Write the contents of a buffer at a predefined position in the log. Both the position and the size of the buffer must be page aligned (i.e. to 4096).
        Throws:
        java.io.IOException
      • writeDelimited

        int writeDelimited​(io.netty.buffer.ByteBuf buf)
                    throws java.io.IOException
        Write a delimited buffer the log. The size of the buffer is first written and then the buffer itself. Note that the returned offset is for the buffer itself, not the size. So, if a buffer is written at the start of the file, the returned offset will be 4, not 0. The returned offset is an int. Consequently, entries can only be written in the first Integer.MAX_VALUE bytes of the file. This is due to how offsets are stored in the index.
        Returns:
        the offset of the buffer within the file.
        Throws:
        java.io.IOException
      • serializedSize

        int serializedSize​(io.netty.buffer.ByteBuf buf)
        Returns:
        the number of bytes consumed by the buffer when written with #writeDelimited
      • position

        long position()
               throws java.io.IOException
        The current offset within the log at which the next call to #writeDelimited will start writing.
        Throws:
        java.io.IOException
      • position

        void position​(long offset)
               throws java.io.IOException
        Set the offset within the log at which the next call to #writeDelimited will start writing.
        Throws:
        java.io.IOException
      • flush

        void flush()
            throws java.io.IOException
        Flush all buffered writes to disk. This call must ensure that the bytes are actually on disk before returning.
        Throws:
        java.io.IOException
      • close

        void close()
            throws java.io.IOException
        Close any held resources.
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.io.IOException