Class BufferedChannel

    • Field Detail

      • writeCapacity

        protected final int writeCapacity
        The capacity of the write buffer.
      • writeBufferStartPosition

        protected java.util.concurrent.atomic.AtomicLong writeBufferStartPosition
        The position of the file channel's write pointer.
      • writeBuffer

        protected final io.netty.buffer.ByteBuf writeBuffer
        The buffer used to write operations.
      • position

        protected volatile long position
        The absolute position of the next write operation.
      • unpersistedBytesBound

        protected final long unpersistedBytesBound
      • unpersistedBytes

        protected final java.util.concurrent.atomic.AtomicLong unpersistedBytes
    • Constructor Detail

      • BufferedChannel

        public BufferedChannel​(io.netty.buffer.ByteBufAllocator allocator,
                               java.nio.channels.FileChannel fc,
                               int capacity)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • BufferedChannel

        public BufferedChannel​(io.netty.buffer.ByteBufAllocator allocator,
                               java.nio.channels.FileChannel fc,
                               int capacity,
                               long unpersistedBytesBound)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • BufferedChannel

        public BufferedChannel​(io.netty.buffer.ByteBufAllocator allocator,
                               java.nio.channels.FileChannel fc,
                               int writeCapacity,
                               int readCapacity,
                               long unpersistedBytesBound)
                        throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • write

        public void write​(io.netty.buffer.ByteBuf src)
                   throws java.io.IOException
        Write all the data in src to the FileChannel. Note that this function can buffer or re-order writes based on the implementation. These writes will be flushed to the disk only when flush() is invoked.
        Parameters:
        src - The source ByteBuffer which contains the data to be written.
        Throws:
        java.io.IOException - if a write operation fails.
      • position

        public long position()
        Get the position where the next write operation will begin writing from.
        Returns:
      • getFileChannelPosition

        public long getFileChannelPosition()
        Get the position of the file channel's write pointer.
        Returns:
      • flushAndForceWrite

        public void flushAndForceWrite​(boolean forceMetadata)
                                throws java.io.IOException
        calls both flush and forceWrite methods.
        Parameters:
        forceMetadata - - If true then this method is required to force changes to both the file's content and metadata to be written to storage; otherwise, it need only force content changes to be written
        Throws:
        java.io.IOException
      • flushAndForceWriteIfRegularFlush

        public void flushAndForceWriteIfRegularFlush​(boolean forceMetadata)
                                              throws java.io.IOException
        calls both flush and forceWrite methods if regular flush is enabled.
        Parameters:
        forceMetadata - - If true then this method is required to force changes to both the file's content and metadata to be written to storage; otherwise, it need only force content changes to be written
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Write any data in the buffer to the file and advance the writeBufferPosition. Callers are expected to synchronize appropriately
        Throws:
        java.io.IOException - if the write fails.
      • forceWrite

        public long forceWrite​(boolean forceMetadata)
                        throws java.io.IOException
        force a sync operation so that data is persisted to the disk.
        Parameters:
        forceMetadata -
        Returns:
        Throws:
        java.io.IOException
      • read

        public int read​(io.netty.buffer.ByteBuf dest,
                        long pos,
                        int length)
                 throws java.io.IOException
        Overrides:
        read in class BufferedReadChannel
        Throws:
        java.io.IOException
      • getNumOfBytesInWriteBuffer

        public int getNumOfBytesInWriteBuffer()
      • getUnpersistedBytes

        long getUnpersistedBytes()