T - The type of Record specialization that is to be returned by the get operationspublic class RandomReader<T extends Record> extends Object implements IRecordReader<T>, Iterable<T>
RandomReader class provides access over an authored IBuffer in a random access fashion. The Records
retrieved can be defined to be cast to the specific Record extending class. The random way of record access is enabled
through the use of a IRecordStore that persists all the records that are retrieved in the forward fashion. This way
whenever a previous record than the current forward record, it is retrieved by the record store. The deserialization from the
record store is not performed on a per record only fashion, but a window can be defined that will include a number of pre-stored
records| Modifier and Type | Field and Description |
|---|---|
static int |
DefaultIteratorTimeout
The default timeout to be used by the
RandomReaderIterators initialized by this reader when retrieving
records or checking if more records are available. |
static TimeUnit |
DefaultIteratorTimeUnit
The default time unit to be used by the
RandomReaderIterators initialized by this reader when retrieving
records or checking if more records are available. |
static int |
DefaultWindowSize
The default size of the window used to resume records that are already in the
IRecordStore and need to be
made available in memory. |
| Constructor and Description |
|---|
RandomReader(URI locator)
Creates a new reader accessing the
IBuffer referenced by the provided locator |
RandomReader(URI locator,
int capacity)
|
| Modifier and Type | Method and Description |
|---|---|
int |
availableRecords()
The number of readily available for consumption
Records |
protected boolean |
canCallNext()
Checks if according to the
IRecordStore and the current window a client can request a next to the
current Record |
protected boolean |
canCallPrevious()
Checks if according to the
IRecordStore and the current window a client can request a previous to the
current Record |
void |
close()
Closes and disposes the underlying buffer.
|
long |
currentRecord()
The index of the last
Record retrieved through the reader. |
void |
emit(BufferEvent event)
Emits the provided event to the writer.
|
T |
get()
|
T |
get(long timeout,
TimeUnit unit)
|
int |
getCapacity()
The underlying
IBuffer capacity used. |
int |
getConcurrentPartialCapacity()
The underlying
IBuffer concurrent partial capacity used |
long |
getInactivityTimeout()
Retrieves the Inactivity timeout set for the lifecycle management of the underlying
IBuffer. |
TimeUnit |
getInactivityTimeUnit()
Retrieves the Inactivity time unit set for the lifecycle management of the underlying
IBuffer. |
long |
getIteratorTimeout()
The timeout that is used by the
Iterators that are created by this reader. |
TimeUnit |
getIteratorTimeUnit()
The time unit that is used by the
Iterators that are created by this reader. |
RecordDefinition[] |
getRecordDefinitions()
Retrieves the
RecordDefinitions that define the Records that are accessible through the reader |
IBuffer.Status |
getStatus()
Retrieves the status of the underlying
IBuffer. |
int |
getWindowSize()
Retrieves the window size that will be used whenever a pre-read record is requested.
|
Iterator<T> |
iterator() |
ListIterator<T> |
listIterator()
The iterator returned is an instance of
RandomReaderIterator |
BufferEvent |
receive()
Receives a previously emitted event from a writer.
|
long |
seek(long len)
|
void |
setIteratorTimeout(long iteratorTimeout)
The timeout that should be used by the
Iterators that are created by this reader. |
void |
setIteratorTimeUnit(TimeUnit iteratorTimeUnit)
The time unit that should be used by the
Iterators that are created by this reader. |
void |
setWindowSize(int windowSize)
Sets the window size that will be used whenever a pre-read record is requested.
|
long |
totalRecords()
|
boolean |
waitAvailable(long timeout,
TimeUnit unit)
Makes sure that within the provided time frame, there is a
Record that can be retrieved without blocking. |
public static final int DefaultIteratorTimeout
RandomReaderIterators initialized by this reader when retrieving
records or checking if more records are available. This value should be interpreted in conjunction with the
value of DefaultIteratorTimeUnitpublic static final TimeUnit DefaultIteratorTimeUnit
RandomReaderIterators initialized by this reader when retrieving
records or checking if more records are available. This value should be interpreted in conjunction with the
value of DefaultIteratorTimeoutpublic static final int DefaultWindowSize
IRecordStore and need to be
made available in memory. Currently set to 1public RandomReader(URI locator) throws GRS2ReaderException
IBuffer referenced by the provided locatorlocator - the locator identifying the IBuffer to consumeGRS2ReaderException - the operation could not be completedpublic RandomReader(URI locator, int capacity) throws GRS2ReaderException
IBuffer referenced by the provided locator
The IBuffer will have the specified capacity, if possiblelocator - the locator identifying the IBuffer to consumecapacity - a desired capacity for the IBuffer which will be consumed. Used as
a hint to the underlying IReaderProxy, which might or might not honor it depending
on its strategyGRS2ReaderException - the operation could not be completedpublic RecordDefinition[] getRecordDefinitions() throws GRS2ReaderException
RecordDefinitions that define the Records that are accessible through the readergetRecordDefinitions in interface IRecordReader<T extends Record>RecordDefinitions as were provided by the corresponding writerGRS2ReaderException - the operation could not be completedIBuffer.getRecordDefinitions()public long getInactivityTimeout()
throws GRS2ReaderException
IBuffer. This value
should be interpreted in conjunction with the value of IRecordReader.getInactivityTimeUnit().getInactivityTimeout in interface IRecordReader<T extends Record>GRS2ReaderException - the operation could not be completedIRecordReader#getInactivityTimeout()}public TimeUnit getInactivityTimeUnit() throws GRS2ReaderException
IBuffer. This value
should be interpreted in conjunction with the value of IRecordReader.getInactivityTimeout()getInactivityTimeUnit in interface IRecordReader<T extends Record>GRS2ReaderException - the operation could not be completedIRecordReader#getInactivityTimeUnit()}public void setWindowSize(int windowSize)
IRecordStore and made availablewindowSize - the size of the windowpublic int getWindowSize()
IRecordStore and made availablepublic void setIteratorTimeout(long iteratorTimeout)
Iterators that are created by this reader. This value
is interpreted in conjunction with the value of IRecordReader.getIteratorTimeUnit()
The Iterators which will use the timeout are instances of RandomReaderIterator.
setIteratorTimeout in interface IRecordReader<T extends Record>iteratorTimeout - the timeoutIRecordReader#setIteratorTimeout(long)}public long getIteratorTimeout()
Iterators that are created by this reader. This value
is interpreted in conjunction with the value of IRecordReader.getIteratorTimeUnit().
The Iterators which use the timeout are instances of RandomReaderIterator.getIteratorTimeout in interface IRecordReader<T extends Record>IRecordReader#getIteratorTimeout()}public void setIteratorTimeUnit(TimeUnit iteratorTimeUnit)
Iterators that are created by this reader. This value
is interpreted in conjunction with the value of IRecordReader.getIteratorTimeout()
The Iterators which will use the time unit are instances of RandomReaderIterator.
setIteratorTimeUnit in interface IRecordReader<T extends Record>iteratorTimeUnit - the time unitIRecordReader#setIteratorTimeUnit(TimeUnit)}public TimeUnit getIteratorTimeUnit()
Iterators that are created by this reader. This value
is interpreted in conjunction with the value of IRecordReader.getIteratorTimeout()
The Iterators which use the time unit are instances of RandomReaderIterator.
getIteratorTimeUnit in interface IRecordReader<T extends Record>IRecordReader#getIteratorTimeUnit()}public int getCapacity()
throws GRS2ReaderException
IBuffer capacity used.getCapacity in interface IRecordReader<T extends Record>GRS2ReaderException - the operation could not be completedIRecordReader#getCapacity()}public int getConcurrentPartialCapacity()
throws GRS2ReaderException
IBuffer concurrent partial capacity usedgetConcurrentPartialCapacity in interface IRecordReader<T extends Record>GRS2ReaderException - the operation could not be completedIRecordReader#getConcurrentPartialCapacity()}public IBuffer.Status getStatus()
IBuffer.getStatus in interface IRecordReader<T extends Record>IRecordReader#getStatus()}public void close()
throws GRS2ReaderException
close in interface IRecordReader<T extends Record>GRS2ReaderException - the operation could not be completedIRecordStore.dispose(),
IRecordReader#close()}public long totalRecords()
throws GRS2ReaderException
totalRecords in interface IRecordReader<T extends Record>Records that have passed through the IBuffer this farGRS2ReaderException - the operation could not be completedIRecordReader#totalRecords()}public long currentRecord()
throws GRS2ReaderException
Record retrieved through the reader.currentRecord in interface IRecordReader<T extends Record>Record retrieved through the readerGRS2ReaderException - the operation could not be completed because no records were retrieved yetIRecordReader#currentRecord()}public int availableRecords()
throws GRS2ReaderException
RecordsavailableRecords in interface IRecordReader<T extends Record>GRS2ReaderException - the operation could not be completedIBuffer.availableRecords()public T get() throws GRS2ReaderException
Record from the IBuffer. An explicit cast is performed to the
type provided in the generic declaration of the reader. If the request can be served by the IRecordStore
then only the local store is touched and not the IBufferget in interface IRecordReader<T extends Record>Record or null if none was readily availableGRS2ReaderException - the operation could not be completedIBuffer.get()public T get(long timeout, TimeUnit unit) throws GRS2ReaderException
Record from the IBuffer. An explicit cast is performed to the
type provided in the generic declaration of the reader. If no record is readily available the reader will
block for a maximum of timeout unit units of time waiting for a record to become
available or until the IBuffer uses the IBuffer.getReaderImmediateNotificationObject()
to notify blocked readers.
If the request can be served by the IRecordStore then only the local store is touched and not the IBufferget in interface IRecordReader<T extends Record>timeout - the timeout to wait forunit - the unit of time to use to interpret the timeout valueRecord retrieved, or null if the timeout expired without a Record becoming availableGRS2ReaderException - the operation could not be completedIBuffer.get()public long seek(long len)
throws GRS2ReaderException
Records provided in the list of Records available.
Depending on the actual IRecordReader implementation, forward and/or backward seeks may be supported.
Seeks the number of Records provided forward or backward in the list of Records available depending on
whether the provided length is a positive or negative number. If the seek length is larger than the readily available
Records, then the timeout and time unit available through ForwardReader.getIteratorTimeout() and
ForwardReader.getIteratorTimeUnit(). If the seek can be completely served by the local IRecordStore then
the IBuffer is not used.seek in interface IRecordReader<T extends Record>len - the number of Record}s to skipRecords actually skippedGRS2ReaderException - the operation could not be completedpublic Iterator<T> iterator()
The iterator returned is an instance of RandomReaderIterator
iterator in interface IRecordReader<T extends Record>iterator in interface Iterable<T extends Record>Iterable.iterator()public ListIterator<T> listIterator()
RandomReaderIteratorpublic void emit(BufferEvent event) throws GRS2ReaderException, GRS2ReaderInvalidArgumentException
BufferEvent.EventSource.Reader.emit in interface IRecordReader<T extends Record>event - the event to send to the writerGRS2ReaderException - the operation could not be completedGRS2ReaderInvalidArgumentException - the event provided cannot be nullIRecordReader.emit(BufferEvent)public BufferEvent receive() throws GRS2ReaderException
receive in interface IRecordReader<T extends Record>GRS2ReaderException - the operation could not be completedIRecordReader.receive()public boolean waitAvailable(long timeout,
TimeUnit unit)
throws GRS2ReaderException
Record that can be retrieved without blocking.
If the timeout defined expires and no Record has been made available, false is returned. Otherwise, or if
there are already available Records, true is returned.
If the request can be served by the local IRecordStore
then the IBuffer is not usedwaitAvailable in interface IRecordReader<T extends Record>timeout - the timeout value interpreted in conjunction with the unit valueunit - the time unit to use to interpret the timeout valueRecord available before the timeout has expired, false otherwiseGRS2ReaderException - the operation could not be completedIRecordReader#waitAvailable(long, TimeUnit)}protected boolean canCallPrevious()
IRecordStore and the current window a client can request a previous to the
current Recordprotected boolean canCallNext()
IRecordStore and the current window a client can request a next to the
current RecordCopyright © 2014. All Rights Reserved.