Class S3ReadAheadByteChannel

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel

    public class S3ReadAheadByteChannel
    extends java.lang.Object
    implements java.nio.channels.ReadableByteChannel
    A ReadableByteChannel delegate for an S3SeekableByteChannel that maintains internal read ahead buffers to reduce the amount of high latency requests to S3. If the bytes required by a read are already in the buffer, they will be fulfilled from the buffer rather than making another S3 request.

    As reads are made this object will update the current read position of the delegating S3SeekableByteChannel

    • Constructor Summary

      Constructors 
      Constructor Description
      S3ReadAheadByteChannel​(S3Path path, int maxFragmentSize, int maxNumberFragments, software.amazon.awssdk.services.s3.S3AsyncClient client, S3SeekableByteChannel delegator, java.lang.Long timeout, java.util.concurrent.TimeUnit timeUnit)
      Construct a new S3ReadAheadByteChannel which is used by its parent delegator to perform read operations.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected com.github.benmanes.caffeine.cache.stats.CacheStats cacheStatistics()
      Obtain a snapshot of the statistics of the internal cache, provides information about hits, misses, requests, evictions etc.
      void close()  
      protected java.lang.Integer fragmentIndexForByteNumber​(long byteNumber)
      Compute which buffer a byte should be in
      boolean isOpen()  
      protected int numberOfCachedFragments()
      The number of fragments currently in the cache.
      int read​(java.nio.ByteBuffer dst)  
      • Methods inherited from class java.lang.Object

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

      • S3ReadAheadByteChannel

        public S3ReadAheadByteChannel​(S3Path path,
                                      int maxFragmentSize,
                                      int maxNumberFragments,
                                      software.amazon.awssdk.services.s3.S3AsyncClient client,
                                      S3SeekableByteChannel delegator,
                                      java.lang.Long timeout,
                                      java.util.concurrent.TimeUnit timeUnit)
                               throws java.io.IOException
        Construct a new S3ReadAheadByteChannel which is used by its parent delegator to perform read operations. The channel is backed by a cache that holds the buffered fragments of the object identified by the path.
        Parameters:
        path - the path to the S3 object being read
        maxFragmentSize - the maximum amount of bytes in a read ahead fragment. Must be >= 1.
        maxNumberFragments - the maximum number of read ahead fragments to hold. Must be >= 2.
        client - the client used to read from the path
        delegator - the S3SeekableByteChannel that delegates reading to this object.
        timeout - the amount of time to wait for a read ahead fragment to be available.
        timeUnit - the TimeUnit for the timeout.
        Throws:
        java.io.IOException - if a problem occurs initializing the cached fragments
    • Method Detail

      • read

        public int read​(java.nio.ByteBuffer dst)
                 throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
        Throws:
        java.io.IOException
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
      • numberOfCachedFragments

        protected int numberOfCachedFragments()
        The number of fragments currently in the cache.
        Returns:
        the size of the cache after any async evictions or reloads have happened.
      • cacheStatistics

        protected com.github.benmanes.caffeine.cache.stats.CacheStats cacheStatistics()
        Obtain a snapshot of the statistics of the internal cache, provides information about hits, misses, requests, evictions etc. that are useful for tuning.
        Returns:
        the statistics of the internal cache.
      • fragmentIndexForByteNumber

        protected java.lang.Integer fragmentIndexForByteNumber​(long byteNumber)
        Compute which buffer a byte should be in
        Parameters:
        byteNumber - the number of the byte in the object accessed by this channel
        Returns:
        the index of the fragment in which byteNumber will be found.