Class PortabilityBasedStorageEngine<K,V>

java.lang.Object
org.terracotta.offheapstore.storage.listener.AbstractListenableStorageEngine<K,V>
org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine<K,V>
All Implemented Interfaces:
BinaryStorageEngine, ListenableStorageEngine<K,V>, StorageEngine<K,V>
Direct Known Subclasses:
FileBackedStorageEngine, OffHeapBufferStorageEngine

public abstract class PortabilityBasedStorageEngine<K,V> extends AbstractListenableStorageEngine<K,V> implements StorageEngine<K,V>, BinaryStorageEngine
  • Field Details

  • Constructor Details

    • PortabilityBasedStorageEngine

      public PortabilityBasedStorageEngine(Portability<? super K> keyPortability, Portability<? super V> valuePortability)
      Creates a storage engine using the given portabilities.
      Parameters:
      keyPortability - key type portability
      valuePortability - value type portability
  • Method Details

    • writeMapping

      public final Long writeMapping(K key, V value, int hash, int metadata)
      Description copied from interface: StorageEngine
      Converts the supplied key and value objects into their encoded form.
      Specified by:
      writeMapping in interface StorageEngine<K,V>
      Parameters:
      key - a key object
      value - a value object
      hash - the key hash
      metadata - the metadata bits
      Returns:
      the encoded mapping
    • attachedMapping

      public void attachedMapping(long encoding, int hash, int metadata)
      Specified by:
      attachedMapping in interface StorageEngine<K,V>
    • freeMapping

      public final void freeMapping(long encoding, int hash, boolean removal)
      Description copied from interface: StorageEngine
      Called to indicate that the associated encoded value is no longer needed.

      This call can be used to free any associated resources tied to the lifecycle of the supplied encoded value.

      Specified by:
      freeMapping in interface StorageEngine<K,V>
      Parameters:
      encoding - encoded value
      hash - hash of the freed mapping
      removal - marks removal from a map
    • clear

      public final void clear()
      Description copied from interface: StorageEngine
      Called to indicate that all keys and values are now free.
      Specified by:
      clear in interface StorageEngine<K,V>
    • readValue

      public V readValue(long encoding)
      Description copied from interface: StorageEngine
      Converts the supplied encoded value into its correct object form.
      Specified by:
      readValue in interface StorageEngine<K,V>
      Parameters:
      encoding - encoded value
      Returns:
      a decoded value object
    • equalsValue

      public boolean equalsValue(Object value, long encoding)
      Description copied from interface: StorageEngine
      Called to determine the equality of the given Java object value against the given encoded form.

      Simple implementations will probably perform a decode on the given encoded form in order to do a regular Object.equals(Object) comparison. This method is provided to allow implementations to optimize this comparison if possible.

      Specified by:
      equalsValue in interface StorageEngine<K,V>
      Parameters:
      value - a value object
      encoding - encoded value
      Returns:
      true if the value and the encoding are equal
    • readKey

      public K readKey(long encoding, int hashCode)
      Description copied from interface: StorageEngine
      Converts the supplied encoded key into its correct object form.
      Specified by:
      readKey in interface StorageEngine<K,V>
      Parameters:
      encoding - encoded key
      hashCode - hash-code of the decoded key
      Returns:
      a decoded key object
    • equalsKey

      public boolean equalsKey(Object key, long encoding)
      Description copied from interface: StorageEngine
      Called to determine the equality of the given object against the given encoded form.

      Simple implementations will probably perform a decode on the given encoded form in order to do a regular Object.equals(Object) comparison. This method is provided to allow implementations to optimize this comparison if possible.

      Specified by:
      equalsKey in interface StorageEngine<K,V>
      Parameters:
      key - a key object
      encoding - encoded value
      Returns:
      true if the key and the encoding are equal
    • readBinaryKey

      public ByteBuffer readBinaryKey(long encoding)
      Specified by:
      readBinaryKey in interface BinaryStorageEngine
    • readBinaryValue

      public ByteBuffer readBinaryValue(long encoding)
      Specified by:
      readBinaryValue in interface BinaryStorageEngine
    • equalsBinaryKey

      public boolean equalsBinaryKey(ByteBuffer binaryKey, long encoding)
      Specified by:
      equalsBinaryKey in interface BinaryStorageEngine
    • writeBinaryMapping

      public Long writeBinaryMapping(ByteBuffer[] binaryKey, ByteBuffer[] binaryValue, int pojoHash, int metadata)
      Specified by:
      writeBinaryMapping in interface BinaryStorageEngine
    • writeBinaryMapping

      public Long writeBinaryMapping(ByteBuffer binaryKey, ByteBuffer binaryValue, int pojoHash, int metadata)
      Specified by:
      writeBinaryMapping in interface BinaryStorageEngine
    • writeMappingBuffersGathering

      protected Long writeMappingBuffersGathering(ByteBuffer[] keyBuffers, ByteBuffer[] valueBuffers, int hash)
    • free

      protected abstract void free(long address)
    • clearInternal

      protected abstract void clearInternal()
    • readKeyBuffer

      protected abstract ByteBuffer readKeyBuffer(long address)
    • getKeyWriteContext

      protected abstract WriteContext getKeyWriteContext(long address)
    • readValueBuffer

      protected abstract ByteBuffer readValueBuffer(long address)
    • getValueWriteContext

      protected abstract WriteContext getValueWriteContext(long address)
    • writeMappingBuffers

      protected abstract Long writeMappingBuffers(ByteBuffer keyBuffer, ByteBuffer valueBuffer, int hash)
    • invalidateCache

      public void invalidateCache()
      Description copied from interface: StorageEngine
      Invalidate any local key/value caches.

      This is called to indicate the termination of a map write "phase". Caching is permitted within a write operation (i.e. to cache around allocation failures during eviction processes).

      Specified by:
      invalidateCache in interface StorageEngine<K,V>