Package software.amazon.nio.spi.s3
Class S3ReadAheadByteChannel
- java.lang.Object
-
- software.amazon.nio.spi.s3.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.ReadableByteChannelAReadableByteChanneldelegate for anS3SeekableByteChannelthat 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 newS3ReadAheadByteChannelwhich 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.CacheStatscacheStatistics()Obtain a snapshot of the statistics of the internal cache, provides information about hits, misses, requests, evictions etc.voidclose()protected java.lang.IntegerfragmentIndexForByteNumber(long byteNumber)Compute which buffer a byte should be inbooleanisOpen()protected intnumberOfCachedFragments()The number of fragments currently in the cache.intread(java.nio.ByteBuffer dst)
-
-
-
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 newS3ReadAheadByteChannelwhich 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 thepath.- Parameters:
path- the path to the S3 object being readmaxFragmentSize- 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 thepathdelegator- theS3SeekableByteChannelthat delegates reading to this object.timeout- the amount of time to wait for a read ahead fragment to be available.timeUnit- theTimeUnitfor thetimeout.- 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:
readin interfacejava.nio.channels.ReadableByteChannel- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.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
byteNumberwill be found.
-
-