Package org.aksw.commons.io.cache
Class ReadableChannelOverSliceWithCache<A>
java.lang.Object
org.aksw.commons.util.closeable.AutoCloseableBase
org.aksw.commons.util.closeable.AutoCloseableWithLeakDetectionBase
org.aksw.commons.io.cache.ReadableChannelOverSliceWithCache<A>
- Type Parameters:
T-
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,HasArrayOps<A>,ReadableChannel<A>,ReadableSource<A>
public class ReadableChannelOverSliceWithCache<A>
extends AutoCloseableWithLeakDetectionBase
implements ReadableChannel<A>
The class drives the iteration of items from the cache
and triggers fetching of data as necessary.
Thereby this class does not fetch the data directly, but it declares
interest in data ranges. The SmartRangeCache will schedule loading of the region
at least as long as interest is expressed.
- Author:
- raven
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AdvancedRangeCacheImpl<A>protected longprotected intprotected longprotected longAt a checkpoint the data fetching tasks for the next blocks are scheduledprotected SliceAccessor<A>protected com.google.common.collect.Range<Long>The original request range by this request.protected Map<RangeRequestWorkerImpl<A>,Slot<Long>> Fields inherited from class org.aksw.commons.util.closeable.AutoCloseableWithLeakDetectionBase
instantiationStackTraceFields inherited from class org.aksw.commons.util.closeable.AutoCloseableBase
closeStackTrace, enableCloseStackTrace, isClosed -
Constructor Summary
ConstructorsConstructorDescriptionReadableChannelOverSliceWithCache(AdvancedRangeCacheImpl<A> cache, long nextCheckpointOffset, LongSupplier offsetSupplier) ReadableChannelOverSliceWithCache(AdvancedRangeCacheImpl<A> cache, com.google.common.collect.Range<Long> requestRange, int maxReadAheadItemCount) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckpoint(long n) Schedule ensured loading of the next 'n' items since the last checkpoint.voidClear all slots of workers with a value less than the currentOffset.protected voidlongbooleanisOpen()protected voidprocessGaps(com.google.common.collect.RangeSet<Long> gaps, long start, long end) intRead method following the usual InputStream protocol.protected voidscheduleWorkerToGaps(com.google.common.collect.RangeSet<Long> gaps) Methods inherited from class org.aksw.commons.util.closeable.AutoCloseableWithLeakDetectionBase
finalize, getInstantiationStackTraceMethods inherited from class org.aksw.commons.util.closeable.AutoCloseableBase
close, ensureOpen, throwClosedExceptionMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.aksw.commons.io.input.ReadableSource
readRaw
-
Field Details
-
slice
-
cache
-
pageRange
-
requestRange
The original request range by this request. In general, the original request range has to be broken down into smaller ranges because of result size limits of the backend -
nextCheckpointOffset
protected long nextCheckpointOffsetAt a checkpoint the data fetching tasks for the next blocks are scheduled -
currentOffset
protected long currentOffset -
maxReadAheadItemCount
protected int maxReadAheadItemCount -
workerToSlot
-
maxRedundantFetchSize
protected long maxRedundantFetchSize
-
-
Constructor Details
-
ReadableChannelOverSliceWithCache
public ReadableChannelOverSliceWithCache(AdvancedRangeCacheImpl<A> cache, com.google.common.collect.Range<Long> requestRange, int maxReadAheadItemCount) -
ReadableChannelOverSliceWithCache
public ReadableChannelOverSliceWithCache(AdvancedRangeCacheImpl<A> cache, long nextCheckpointOffset, LongSupplier offsetSupplier)
-
-
Method Details
-
getNextCheckpointOffset
public long getNextCheckpointOffset() -
getPageRange
-
checkpoint
protected void checkpoint(long n) Schedule ensured loading of the next 'n' items since the last checkpoint. Check whether there are any gaps ahead that require scheduling requests to the backend -
clearPassedSlots
public void clearPassedSlots()Clear all slots of workers with a value less than the currentOffset. These are workers for which we did not schedule any further tasks -
scheduleWorkerToGaps
-
processGaps
-
isOpen
public boolean isOpen() -
closeActual
protected void closeActual()- Overrides:
closeActualin classAutoCloseableBase
-
read
Description copied from interface:ReadableSourceRead method following the usual InputStream protocol.- Specified by:
readin interfaceReadableSource<A>- Parameters:
tgt- The array into which to put the read datatgtOffset- Offset into array where to start writinglength- Maximum number of items to read.- Returns:
- The number of items read. Return -1 if end of data was reached, and 0 iff length was 0.
- Throws:
IOException
-
getArrayOps
- Specified by:
getArrayOpsin interfaceHasArrayOps<A>
-