Class AbstractPoolAccessor

  • All Implemented Interfaces:
    PoolAccessor<PoolParticipant>

    public abstract class AbstractPoolAccessor
    extends java.lang.Object
    implements PoolAccessor<PoolParticipant>
    Abstract PoolAccessor implementation providing pool to store binding functionality.
    Author:
    Chris Dennis, Alex Snaps
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract long add​(long sizeOf, boolean force)
      Add a specific number of bytes to the pool.
      long add​(java.lang.Object key, java.lang.Object value, java.lang.Object container, boolean force)
      Add an element to the pool.
      protected abstract boolean canAddWithoutEvicting​(long sizeOf)
      Check if there is enough room in the pool to add a specific number of bytes without provoking any eviction
      boolean canAddWithoutEvicting​(java.lang.Object key, java.lang.Object value, java.lang.Object container)
      Check if there is enough room in the pool to add an element without provoking any eviction
      protected void checkLinked()
      Throws IllegalStateException if this accessor is not linked to it's pool.
      void clear()
      Free resources used by this accessor.
      protected abstract void doClear()
      Free resources used by this accessor.
      PoolParticipant getParticipant()
      Return the store that uses this accessor
      protected Pool getPool()
      Return the pool this accessor is associated with.
      long getPoolOccupancy()
      Returns the occupied size for this pool.
      long getPoolSize()
      Returns the size of this pool.
      boolean hasAbortedSizeOf()
      Check if the store may contain elements which the SizeOf engine could not fully size.
      long replace​(long currentSize, java.lang.Object key, java.lang.Object value, java.lang.Object container, boolean force)
      Delete a fixed number of bytes from the pool with the given objects.
      void setMaxSize​(long newValue)
      Sets the max size for this pool
      void unlink()
      unlink this PoolAccessor from its pool.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractPoolAccessor

        public AbstractPoolAccessor​(Pool pool,
                                    PoolParticipant participant,
                                    SizeOfEngine sizeOfEngine)
        Creates an accessor for the specified participant to access the specified pool.
        Parameters:
        pool - pool to be accessed
        participant - accessing participant
    • Method Detail

      • add

        public final long add​(java.lang.Object key,
                              java.lang.Object value,
                              java.lang.Object container,
                              boolean force)
        Add an element to the pool.
        Specified by:
        add in interface PoolAccessor<PoolParticipant>
        Parameters:
        key - the key of the element
        value - the value of the element
        container - the element-container object
        force - true if the pool should accept adding the element, even if it's out of resources
        Returns:
        how many bytes have been added to the pool or -1 if add failed.
      • canAddWithoutEvicting

        public final boolean canAddWithoutEvicting​(java.lang.Object key,
                                                   java.lang.Object value,
                                                   java.lang.Object container)
        Check if there is enough room in the pool to add an element without provoking any eviction
        Specified by:
        canAddWithoutEvicting in interface PoolAccessor<PoolParticipant>
        Parameters:
        key - the key of the element
        value - the value of the element
        container - the element-container object
        Returns:
        true if there is enough room left
      • add

        protected abstract long add​(long sizeOf,
                                    boolean force)
                             throws java.lang.IllegalArgumentException
        Add a specific number of bytes to the pool.
        Parameters:
        sizeOf - number of bytes to add
        force - true if the pool should accept adding the element, even if it's out of resources
        Returns:
        how many bytes have been added to the pool or -1 if add failed.
        Throws:
        java.lang.IllegalArgumentException - when sizeOf is negative
      • canAddWithoutEvicting

        protected abstract boolean canAddWithoutEvicting​(long sizeOf)
        Check if there is enough room in the pool to add a specific number of bytes without provoking any eviction
        Parameters:
        sizeOf - number of bytes to test against
        Returns:
        true if there is enough room left
      • replace

        public final long replace​(long currentSize,
                                  java.lang.Object key,
                                  java.lang.Object value,
                                  java.lang.Object container,
                                  boolean force)
        Delete a fixed number of bytes from the pool with the given objects.
        Specified by:
        replace in interface PoolAccessor<PoolParticipant>
        Parameters:
        currentSize - the size of the object(s) being replaced
        key - the key of the element
        value - the value of the element
        container - the element-container object
        force - true if the pool should accept replacing the element, even if it's out of resources
        Returns:
        the change in size of the pool, or Long.MIN_VALUE if replace failed.
      • doClear

        protected abstract void doClear()
        Free resources used by this accessor. This method is called by clear().
      • setMaxSize

        public void setMaxSize​(long newValue)
        Sets the max size for this pool
        Specified by:
        setMaxSize in interface PoolAccessor<PoolParticipant>
        Parameters:
        newValue - the value in bytes
      • checkLinked

        protected final void checkLinked()
                                  throws java.lang.IllegalStateException
        Throws IllegalStateException if this accessor is not linked to it's pool.
        Throws:
        java.lang.IllegalStateException - if not linked
      • getPool

        protected final Pool getPool()
        Return the pool this accessor is associated with.
        Returns:
        associated pool
      • hasAbortedSizeOf

        public boolean hasAbortedSizeOf()
        Check if the store may contain elements which the SizeOf engine could not fully size.
        Specified by:
        hasAbortedSizeOf in interface PoolAccessor<PoolParticipant>
        Returns:
        true if the store may contain partially sized objects