Class AdvancedRangeCacheImpl<T>

java.lang.Object
org.aksw.commons.io.cache.AdvancedRangeCacheImpl<T>
All Implemented Interfaces:
HasArrayOps<T>, ReadableChannelFactory<T>, ReadableChannelSource<T>

public class AdvancedRangeCacheImpl<T> extends Object implements ReadableChannelSource<T>
  • Field Details

    • dataSource

      protected ReadableChannelSource<T> dataSource
    • slice

      protected Slice<T> slice
    • workerCreationLock

      protected ReentrantLock workerCreationLock
    • executors

      protected Set<RangeRequestWorkerImpl<T>> executors
    • readBeforeSize

      protected long readBeforeSize
    • requestLimit

      protected long requestLimit
    • terminationDelay

      protected Duration terminationDelay
    • maxReadAheadItemCount

      protected int maxReadAheadItemCount
    • workerBulkSize

      protected int workerBulkSize
    • executorService

      protected ExecutorService executorService
  • Constructor Details

  • Method Details

    • getArrayOps

      public ArrayOps<T> getArrayOps()
      Specified by:
      getArrayOps in interface HasArrayOps<T>
    • getDataSource

      public ReadableChannelSource<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:
      size in interface ReadableChannelSource<T>
    • getSlice

      public Slice<T> getSlice()
    • getExecutors

      public Set<RangeRequestWorkerImpl<T>> getExecutors()
    • getExecutorCreationReadLock

      public Lock 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

      public ReadableChannel<T> 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 service
      Specified by:
      newReadableChannel in interface ReadableChannelFactory<T>
      Parameters:
      requestRange -
    • newBuilder

      public static <A> AdvancedRangeCacheImpl.Builder<A> newBuilder()