org.terracotta.offheapstore.storage
Class PortabilityBasedStorageEngine<K,V>

java.lang.Object
  extended by org.terracotta.offheapstore.storage.listener.AbstractListenableStorageEngine<K,V>
      extended by 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

Author:
Chris Dennis

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.terracotta.offheapstore.storage.StorageEngine
StorageEngine.Owner
 
Field Summary
protected  Portability<? super K> keyPortability
           
protected  Portability<? super V> valuePortability
           
 
Constructor Summary
PortabilityBasedStorageEngine(Portability<? super K> keyPortability, Portability<? super V> valuePortability)
          Creates a storage engine using the given portabilities.
 
Method Summary
 void attachedMapping(long encoding, int hash, int metadata)
           
 void clear()
          Called to indicate that all keys and values are now free.
protected abstract  void clearInternal()
           
 boolean equalsBinaryKey(ByteBuffer binaryKey, long encoding)
           
 boolean equalsKey(Object key, long encoding)
          Called to determine the equality of the given object against the given encoded form.
 boolean equalsValue(Object value, long encoding)
          Called to determine the equality of the given Java object value against the given encoded form.
protected abstract  void free(long address)
           
 void freeMapping(long encoding, int hash, boolean removal)
          Called to indicate that the associated encoded value is no longer needed.
protected abstract  WriteContext getKeyWriteContext(long address)
           
protected abstract  WriteContext getValueWriteContext(long address)
           
 void invalidateCache()
          Invalidate any local key/value caches.
 ByteBuffer readBinaryKey(long encoding)
           
 ByteBuffer readBinaryValue(long encoding)
           
 K readKey(long encoding, int hashCode)
          Converts the supplied encoded key into its correct object form.
protected abstract  ByteBuffer readKeyBuffer(long address)
           
 V readValue(long encoding)
          Converts the supplied encoded value into its correct object form.
protected abstract  ByteBuffer readValueBuffer(long address)
           
 Long writeBinaryMapping(ByteBuffer[] binaryKey, ByteBuffer[] binaryValue, int pojoHash, int metadata)
           
 Long writeBinaryMapping(ByteBuffer binaryKey, ByteBuffer binaryValue, int pojoHash, int metadata)
           
 Long writeMapping(K key, V value, int hash, int metadata)
          Converts the supplied key and value objects into their encoded form.
protected abstract  Long writeMappingBuffers(ByteBuffer keyBuffer, ByteBuffer valueBuffer, int hash)
           
protected  Long writeMappingBuffersGathering(ByteBuffer[] keyBuffers, ByteBuffer[] valueBuffers, int hash)
           
 
Methods inherited from class org.terracotta.offheapstore.storage.listener.AbstractListenableStorageEngine
fireCleared, fireCopied, fireFreed, fireRecovered, fireWritten, hasListeners, hasRecoveryListeners, registerListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.terracotta.offheapstore.storage.StorageEngine
bind, destroy, getAllocatedMemory, getDataSize, getOccupiedMemory, getVitalMemory, shrink
 
Methods inherited from interface org.terracotta.offheapstore.storage.BinaryStorageEngine
readKeyHash
 

Field Detail

keyPortability

protected final Portability<? super K> keyPortability

valuePortability

protected final Portability<? super V> valuePortability
Constructor Detail

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 Detail

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>


Copyright © 2016. All Rights Reserved.