Class LimitingRebufferer

  • All Implemented Interfaces:
    java.lang.AutoCloseable, ReaderFileProxy, Rebufferer, Rebufferer.BufferHolder

    public class LimitingRebufferer
    extends java.lang.Object
    implements Rebufferer, Rebufferer.BufferHolder
    Rebufferer wrapper that applies rate limiting. Instantiated once per RandomAccessReader, thread-unsafe. The instances reuse themselves as the BufferHolder to avoid having to return a new object for each rebuffer call.
    • Constructor Detail

      • LimitingRebufferer

        public LimitingRebufferer​(Rebufferer wrapped,
                                  com.google.common.util.concurrent.RateLimiter limiter,
                                  int limitQuant)
    • Method Detail

      • rebuffer

        public Rebufferer.BufferHolder rebuffer​(long position)
        Description copied from interface: Rebufferer
        Rebuffer (move on or seek to) a given position, and return a buffer that can be used there. The only guarantee about the size of the returned data is that unless rebuffering at the end of the file, the buffer will not be empty and will contain the requested position, i.e. offset <= position < offset + bh.buffer().limit(), but the buffer will not be positioned there.
        Specified by:
        rebuffer in interface Rebufferer
      • getCrcCheckChance

        public double getCrcCheckChance()
        Description copied from interface: ReaderFileProxy
        Needed for tests. Returns the table's CRC check chance, which is only set for compressed tables.
        Specified by:
        getCrcCheckChance in interface ReaderFileProxy
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface ReaderFileProxy
      • closeReader

        public void closeReader()
        Description copied from interface: Rebufferer
        Called when a reader is closed. Should clean up reader-specific data.
        Specified by:
        closeReader in interface Rebufferer
      • toString

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

        public java.nio.ByteBuffer buffer()
        Description copied from interface: Rebufferer.BufferHolder
        Returns a useable buffer (i.e. one whose position and limit can be freely modified). Its limit will be set to the size of the available data in the buffer. The buffer must be treated as read-only.
        Specified by:
        buffer in interface Rebufferer.BufferHolder
      • release

        public void release()
        Description copied from interface: Rebufferer.BufferHolder
        To be called when this buffer is no longer in use. Must be called for all BufferHolders, or ChunkCache will not be able to free blocks.
        Specified by:
        release in interface Rebufferer.BufferHolder