KEY
- key typeVALUE
- value typeCHUNK_IDENTIFIER
- the type of the chunk identifier, i.e., an object which uniquely identifies a chunk in the store.
Often times this is the chunk's key as stored in the data grid.public abstract class ChunkedCollectionReader<KEY,VALUE,CHUNK_IDENTIFIER> extends KeyValueProducer<KEY,VALUE>
This is the base class for chunked collection readers. Chunked collection readers read key-value collections
organized as a set of chunks, each holding a number of entries. The purpose of this class is to provide
an abstraction for sequentially reading key-value entries in the same order they were put into the collection
by a ChunkedCollectionWriter
. To read all the objects in the chunked collection, readNext()
should be called until it returns false
.
The reader pre-reads a configurable number of chunks by using a thread pool to call
readChunkFromTheGrid(Object, ChunkBuffer, int)
. There is always one chunk served
at that time (i.e., its underlying buffer is used to get the next object entry). The chunks
are served in the same order provided by their identifiers nextChunkIdentifier()
.
Constructor and Description |
---|
ChunkedCollectionReader(com.scaleoutsoftware.soss.client.map.impl.ChunkBufferPool chunkBufferPool,
int readTimeoutMilliseconds)
Create the chunk reader instance.
|
Modifier and Type | Method and Description |
---|---|
abstract KEY |
getKey()
Gets the current key.
|
long |
getMaxWaitingTime()
Gets the maximum time spent waiting for unavailable chunk.
|
long |
getTotalWaitingTime()
Gets the total time spent waiting for unavailable chunks.
|
abstract VALUE |
getValue()
Gets the current value.
|
void |
prepareChunk(CHUNK_IDENTIFIER identifier,
DataInputStream dataInput,
ByteBuffer buffer,
int chunkIndex)
This method is called once before the chunk is served.
|
boolean |
readNext()
Reads the next entry from the chunks.
|
void |
startReading()
Starts reading the chunks from the grid.
|
public ChunkedCollectionReader(com.scaleoutsoftware.soss.client.map.impl.ChunkBufferPool chunkBufferPool, int readTimeoutMilliseconds)
chunkBufferPool
- buffer pool to use for the read chunksreadTimeoutMilliseconds
- time to wait for the read to completepublic void startReading() throws IOException
IOException
- if an error occurred while constructing chunk readerpublic boolean readNext() throws IOException, TimeoutException
readNext
in class KeyValueProducer<KEY,VALUE>
true
if the object was read successfully, false if there are no more objects to be read.IOException
- if there was a ScaleOut hServer access errorTimeoutException
- if the read timed outpublic void prepareChunk(CHUNK_IDENTIFIER identifier, DataInputStream dataInput, ByteBuffer buffer, int chunkIndex) throws IOException
identifier
- Chunk identifierdataInput
- A DataInputStream
view of the chunkbuffer
- A ByteBuffer
view of the chunkchunkIndex
- The index of the chunk in the chunk sequenceIOException
- If a reading error occurredpublic abstract KEY getKey()
readNext()
.getKey
in class KeyValueProducer<KEY,VALUE>
public abstract VALUE getValue()
readNext()
.getValue
in class KeyValueProducer<KEY,VALUE>
public long getTotalWaitingTime()
public long getMaxWaitingTime()
Copyright (C) 2007-2014 ScaleOut Software, Inc.