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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classPortabilityBasedStorageEngine.CachedEncode<K,V>-
Nested classes/interfaces inherited from interface org.terracotta.offheapstore.storage.StorageEngine
StorageEngine.Owner
-
-
Field Summary
Fields Modifier and Type Field Description protected Portability<? super K>keyPortabilityprivate PortabilityBasedStorageEngine.CachedEncode<K,V>lastMappingprotected Portability<? super V>valuePortability
-
Constructor Summary
Constructors Constructor Description PortabilityBasedStorageEngine(Portability<? super K> keyPortability, Portability<? super V> valuePortability)Creates a storage engine using the given portabilities.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidattachedMapping(long encoding, int hash, int metadata)voidclear()Called to indicate that all keys and values are now free.protected abstract voidclearInternal()booleanequalsBinaryKey(java.nio.ByteBuffer binaryKey, long encoding)booleanequalsKey(java.lang.Object key, long encoding)Called to determine the equality of the given object against the given encoded form.booleanequalsValue(java.lang.Object value, long encoding)Called to determine the equality of the given Java object value against the given encoded form.protected abstract voidfree(long address)voidfreeMapping(long encoding, int hash, boolean removal)Called to indicate that the associated encoded value is no longer needed.protected abstract WriteContextgetKeyWriteContext(long address)protected abstract WriteContextgetValueWriteContext(long address)voidinvalidateCache()Invalidate any local key/value caches.java.nio.ByteBufferreadBinaryKey(long encoding)java.nio.ByteBufferreadBinaryValue(long encoding)KreadKey(long encoding, int hashCode)Converts the supplied encoded key into its correct object form.protected abstract java.nio.ByteBufferreadKeyBuffer(long address)VreadValue(long encoding)Converts the supplied encoded value into its correct object form.protected abstract java.nio.ByteBufferreadValueBuffer(long address)java.lang.LongwriteBinaryMapping(java.nio.ByteBuffer[] binaryKey, java.nio.ByteBuffer[] binaryValue, int pojoHash, int metadata)java.lang.LongwriteBinaryMapping(java.nio.ByteBuffer binaryKey, java.nio.ByteBuffer binaryValue, int pojoHash, int metadata)java.lang.LongwriteMapping(K key, V value, int hash, int metadata)Converts the supplied key and value objects into their encoded form.protected abstract java.lang.LongwriteMappingBuffers(java.nio.ByteBuffer keyBuffer, java.nio.ByteBuffer valueBuffer, int hash)protected java.lang.LongwriteMappingBuffersGathering(java.nio.ByteBuffer[] keyBuffers, java.nio.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.BinaryStorageEngine
readKeyHash
-
Methods inherited from interface org.terracotta.offheapstore.storage.StorageEngine
bind, destroy, getAllocatedMemory, getDataSize, getOccupiedMemory, getVitalMemory, shrink
-
-
-
-
Field Detail
-
keyPortability
protected final Portability<? super K> keyPortability
-
valuePortability
protected final Portability<? super V> valuePortability
-
lastMapping
private PortabilityBasedStorageEngine.CachedEncode<K,V> lastMapping
-
-
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 portabilityvaluePortability- value type portability
-
-
Method Detail
-
writeMapping
public final java.lang.Long writeMapping(K key, V value, int hash, int metadata)
Description copied from interface:StorageEngineConverts the supplied key and value objects into their encoded form.- Specified by:
writeMappingin interfaceStorageEngine<K,V>- Parameters:
key- a key objectvalue- a value objecthash- the key hashmetadata- the metadata bits- Returns:
- the encoded mapping
-
attachedMapping
public void attachedMapping(long encoding, int hash, int metadata)- Specified by:
attachedMappingin interfaceStorageEngine<K,V>
-
freeMapping
public final void freeMapping(long encoding, int hash, boolean removal)Description copied from interface:StorageEngineCalled 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:
freeMappingin interfaceStorageEngine<K,V>- Parameters:
encoding- encoded valuehash- hash of the freed mappingremoval- marks removal from a map
-
clear
public final void clear()
Description copied from interface:StorageEngineCalled to indicate that all keys and values are now free.- Specified by:
clearin interfaceStorageEngine<K,V>
-
readValue
public V readValue(long encoding)
Description copied from interface:StorageEngineConverts the supplied encoded value into its correct object form.- Specified by:
readValuein interfaceStorageEngine<K,V>- Parameters:
encoding- encoded value- Returns:
- a decoded value object
-
equalsValue
public boolean equalsValue(java.lang.Object value, long encoding)Description copied from interface:StorageEngineCalled 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:
equalsValuein interfaceStorageEngine<K,V>- Parameters:
value- a value objectencoding- encoded value- Returns:
trueif the value and the encoding are equal
-
readKey
public K readKey(long encoding, int hashCode)
Description copied from interface:StorageEngineConverts the supplied encoded key into its correct object form.- Specified by:
readKeyin interfaceStorageEngine<K,V>- Parameters:
encoding- encoded keyhashCode- hash-code of the decoded key- Returns:
- a decoded key object
-
equalsKey
public boolean equalsKey(java.lang.Object key, long encoding)Description copied from interface:StorageEngineCalled 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:
equalsKeyin interfaceStorageEngine<K,V>- Parameters:
key- a key objectencoding- encoded value- Returns:
trueif the key and the encoding are equal
-
readBinaryKey
public java.nio.ByteBuffer readBinaryKey(long encoding)
- Specified by:
readBinaryKeyin interfaceBinaryStorageEngine
-
readBinaryValue
public java.nio.ByteBuffer readBinaryValue(long encoding)
- Specified by:
readBinaryValuein interfaceBinaryStorageEngine
-
equalsBinaryKey
public boolean equalsBinaryKey(java.nio.ByteBuffer binaryKey, long encoding)- Specified by:
equalsBinaryKeyin interfaceBinaryStorageEngine
-
writeBinaryMapping
public java.lang.Long writeBinaryMapping(java.nio.ByteBuffer[] binaryKey, java.nio.ByteBuffer[] binaryValue, int pojoHash, int metadata)- Specified by:
writeBinaryMappingin interfaceBinaryStorageEngine
-
writeBinaryMapping
public java.lang.Long writeBinaryMapping(java.nio.ByteBuffer binaryKey, java.nio.ByteBuffer binaryValue, int pojoHash, int metadata)- Specified by:
writeBinaryMappingin interfaceBinaryStorageEngine
-
writeMappingBuffersGathering
protected java.lang.Long writeMappingBuffersGathering(java.nio.ByteBuffer[] keyBuffers, java.nio.ByteBuffer[] valueBuffers, int hash)
-
free
protected abstract void free(long address)
-
clearInternal
protected abstract void clearInternal()
-
readKeyBuffer
protected abstract java.nio.ByteBuffer readKeyBuffer(long address)
-
getKeyWriteContext
protected abstract WriteContext getKeyWriteContext(long address)
-
readValueBuffer
protected abstract java.nio.ByteBuffer readValueBuffer(long address)
-
getValueWriteContext
protected abstract WriteContext getValueWriteContext(long address)
-
writeMappingBuffers
protected abstract java.lang.Long writeMappingBuffers(java.nio.ByteBuffer keyBuffer, java.nio.ByteBuffer valueBuffer, int hash)
-
invalidateCache
public void invalidateCache()
Description copied from interface:StorageEngineInvalidate 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:
invalidateCachein interfaceStorageEngine<K,V>
-
-