Class AdvancedRangeCacheImpl<T>
java.lang.Object
org.aksw.commons.io.cache.AdvancedRangeCacheImpl<T>
- All Implemented Interfaces:
HasArrayOps<T>, ReadableChannelFactory<T>, ReadableChannelSource<T>
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ReadableChannelSource<T> protected Set<RangeRequestWorkerImpl<T>> protected ExecutorServiceprotected intprotected longprotected longprotected Durationprotected intprotected ReentrantLock -
Constructor Summary
ConstructorsConstructorDescriptionAdvancedRangeCacheImpl(ReadableChannelSource<T> dataSource, Slice<T> slice, long requestLimit, int workerBulkSize, Duration terminationDelay, int maxReadAheadItemCount, ExecutorService executorService) -
Method Summary
Modifier and TypeMethodDescriptionA lock that when held prevents creation of workers that put data into the slice.getSlice()static <A> AdvancedRangeCacheImpl.Builder<A> newExecutor(long offset, long initialLength) Creates a new worker and immediately starts it.newReadableChannel(com.google.common.collect.Range<Long> range) Create a RequestContext for the given requestRange: (1) Claim cached pages for the start-range of the request range (2) Check the running executors for whether they are suitable for (partially) servinge the request range If so, assign tasks to those executors (3) If no running executor is suitable then add the request to the 'pending queue' If the executor servicelongsize()If the size is requested but not yet known then try to obtain it from the dataSource and if this knows it then cache it with the sliceMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ReadableChannelFactory
newReadableChannel, newReadableChannelMethods inherited from interface ReadableChannelSource
newReadableChannel
-
Field Details
-
dataSource
-
slice
-
workerCreationLock
-
executors
-
readBeforeSize
protected long readBeforeSize -
requestLimit
protected long requestLimit -
terminationDelay
-
maxReadAheadItemCount
protected int maxReadAheadItemCount -
workerBulkSize
protected int workerBulkSize -
executorService
-
-
Constructor Details
-
AdvancedRangeCacheImpl
public AdvancedRangeCacheImpl(ReadableChannelSource<T> dataSource, Slice<T> slice, long requestLimit, int workerBulkSize, Duration terminationDelay, int maxReadAheadItemCount, ExecutorService executorService)
-
-
Method Details
-
getArrayOps
- Specified by:
getArrayOpsin interfaceHasArrayOps<T>
-
getDataSource
-
size
public long size()If the size is requested but not yet known then try to obtain it from the dataSource and if this knows it then cache it with the slice- Specified by:
sizein interfaceReadableChannelSource<T>
-
getSlice
-
getExecutors
-
getExecutorCreationReadLock
A lock that when held prevents creation of workers that put data into the slice. This allows for analyzing all existing workers during scheduling; i.e. when deciding whether for a data demand any new workers need to be created or existing ones can be reused. -
newExecutor
public Map.Entry<RangeRequestWorkerImpl<T>, Slot<Long>> newExecutor(long offset, long initialLength) Creates a new worker and immediately starts it. The executor creation is driven by the RangeRequestIterator which creates executors on demand whenever it detects any gaps in its read ahead range which are not served by any existing executors.- Parameters:
offset-initialLength-- Returns:
-
newReadableChannel
Create a RequestContext for the given requestRange: (1) Claim cached pages for the start-range of the request range (2) Check the running executors for whether they are suitable for (partially) servinge the request range If so, assign tasks to those executors (3) If no running executor is suitable then add the request to the 'pending queue' If the executor service- Specified by:
newReadableChannelin interfaceReadableChannelFactory<T>- Parameters:
requestRange-
-
newBuilder
-