Class SliceAccessorImpl<A>

Type Parameters:
A -
All Implemented Interfaces:
AutoCloseable, SliceAccessor<A>

public class SliceAccessorImpl<A> extends AutoCloseableWithLeakDetectionBase implements SliceAccessor<A>
A sequence of claimed ranges within a certain range, whereas the range can be modified resulting in an incremental change of the claims. An individual page range should only be operated by a single thread though multiple threads may each have their own page range. - claimByOffsetRange() only triggers loading of the pages but does not wait for them to become ready - lock() waits for all claimed pages to become ready and afterwards locks them - unlock() must be called after lock(); unlocks all pages
Author:
raven
  • Field Details

    • slice

      protected SliceWithPages<A> slice
    • offsetRange

      protected com.google.common.collect.Range<Long> offsetRange
    • claimedPages

      protected ConcurrentNavigableMap<Long, RefFuture<BufferView<A>>> claimedPages
    • isLocked

      protected boolean isLocked
    • evictionGuards

      protected Collection<Disposable> evictionGuards
    • bulkSize

      protected int bulkSize
      The number of items to process in one batch (before checking for conditions such as interrupts or no-more-demand)
  • Constructor Details

  • Method Details

    • getSlice

      public Slice<A> getSlice()
      Specified by:
      getSlice in interface SliceAccessor<A>
    • getOffsetRange

      public com.google.common.collect.Range<Long> getOffsetRange()
    • getCache

      public SliceWithPages<A> getCache()
    • getClaimedPages

      public ConcurrentNavigableMap<Long, RefFuture<BufferView<A>>> getClaimedPages()
    • claimByOffsetRange

      public void claimByOffsetRange(long startOffset, long endOffset)
      Description copied from interface: SliceAccessor
      Set or update the claimed range - this will immediately request references to any pages providing the data for that range. Pages outside of that range are considered as no longer needed pages will immediately be released. This method prepares the pages which can be subsequently locked. Calling this method while the page range is locked (SliceAccessor.lock()) raises an IllegalStateException.
      Specified by:
      claimByOffsetRange in interface SliceAccessor<A>
      Parameters:
      startOffset -
      endOffset -
    • claimByPageIdRange

      protected void claimByPageIdRange(long startPageId, long endPageId)
    • computePageMap

      protected NavigableMap<Long, BufferView<A>> computePageMap()
    • ensureUnlocked

      protected void ensureUnlocked()
    • lock

      public void lock()
      Description copied from interface: SliceAccessor
      Lock the range for writing
      Specified by:
      lock in interface SliceAccessor<A>
    • unlock

      public void unlock()
      Description copied from interface: SliceAccessor
      Unlock the range
      Specified by:
      unlock in interface SliceAccessor<A>
    • releaseEvictionGuards

      public void releaseEvictionGuards()
    • releaseAll

      public void releaseAll()
      Description copied from interface: SliceAccessor
      Releases all currently held pages. Future requests via SliceAccessor.claimByOffsetRange(long, long) are allowed.
      Specified by:
      releaseAll in interface SliceAccessor<A>
    • write

      public void write(long offset, A arrayWithItemsOfTypeT, int arrOffset, int arrLength)
      Description copied from interface: SliceAccessor
      Put a sequence of items into the claimed range Attempts to put items outside of the claimed range raises an IndexOutOfBoundsException The page range should be locked when calling this method.
      Specified by:
      write in interface SliceAccessor<A>
    • unsafeRead

      public int unsafeRead(A tgt, int tgtOffset, long srcOffset, int length) throws IOException
      Read a range of data - does not await any new data
      Specified by:
      unsafeRead in interface SliceAccessor<A>
      Throws:
      IOException
    • blockingRead

      public int blockingRead(A tgt, int tgtOffset, long srcOffset, int length) throws IOException
      Method is subject to removal - use sequentialReaderForSlice.read The range [srcOffset, srcOffset + length) must be within the claimed range!
      Throws:
      IOException
    • closeActual

      protected void closeActual()
      Overrides:
      closeActual in class AutoCloseableBase
    • addEvictionGuard

      public void addEvictionGuard(com.google.common.collect.RangeSet<Long> ranges)
      Description copied from interface: SliceAccessor
      Adds an eviction guard (if the slice support it) and couples it's life cycle to this accessor. Closing an accessor also removes all eviction guards created by it. This method must be called after acquiring a read lock on the slice's metadata. Protects TODO Should this method also suppress future loaded ranges?
      Specified by:
      addEvictionGuard in interface SliceAccessor<A>