org.terracotta.offheapstore.storage
Class LongStorageEngine<V>

java.lang.Object
  extended by org.terracotta.offheapstore.storage.LongStorageEngine<V>
All Implemented Interfaces:
StorageEngine<Long,V>

public class LongStorageEngine<V>
extends Object
implements StorageEngine<Long,V>

A Long key storage engine.

This engine stores long keys as their primitive representations split between the hashCode and value fields.

Author:
Chris Dennis

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.terracotta.offheapstore.storage.StorageEngine
StorageEngine.Owner
 
Constructor Summary
LongStorageEngine(HalfStorageEngine<V> valueStorage)
           
 
Method Summary
 void attachedMapping(long encoding, int hash, int metadata)
           
 void bind(StorageEngine.Owner owner)
           
 void clear()
          Called to indicate that all keys and values are now free.
static
<V> Factory<LongStorageEngine<V>>
createFactory(Factory<? extends HalfStorageEngine<V>> valueFactory)
           
 void destroy()
           
 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.
 void freeMapping(long encoding, int hash, boolean removal)
          Called to indicate that the associated encoded value is no longer needed.
 long getAllocatedMemory()
          Returns a measure of the amount of memory allocated for this storage engine.
 long getDataSize()
          Returns a measure of the total size of the keys and values stored in this storage engine.
 long getOccupiedMemory()
          Returns a measure of the amount of memory consumed by this storage engine.
 long getVitalMemory()
          Returns a measure of the amount of vital memory allocated for this storage engine.
 void invalidateCache()
          Invalidate any local key/value caches.
 Long readKey(long encoding, int hashCode)
          Converts the supplied encoded key into its correct object form.
 V readValue(long encoding)
          Converts the supplied encoded value into its correct object form.
 boolean shrink()
           
 String toString()
           
 Long writeMapping(Long key, V value, int hash, int metadata)
          Converts the supplied key and value objects into their encoded form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LongStorageEngine

public LongStorageEngine(HalfStorageEngine<V> valueStorage)
Method Detail

createFactory

public static <V> Factory<LongStorageEngine<V>> createFactory(Factory<? extends HalfStorageEngine<V>> valueFactory)

writeMapping

public Long writeMapping(Long 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<Long,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<Long,V>

freeMapping

public 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<Long,V>
Parameters:
encoding - encoded value
hash - hash of the freed mapping
removal - marks removal from a map

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<Long,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<Long,V>
Parameters:
value - a value object
encoding - encoded value
Returns:
true if the value and the encoding are equal

readKey

public Long 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<Long,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<Long,V>
Parameters:
key - a key object
encoding - encoded value
Returns:
true if the key and the encoding are equal

clear

public void clear()
Description copied from interface: StorageEngine
Called to indicate that all keys and values are now free.

Specified by:
clear in interface StorageEngine<Long,V>

getAllocatedMemory

public long getAllocatedMemory()
Description copied from interface: StorageEngine
Returns a measure of the amount of memory allocated for this storage engine.

Specified by:
getAllocatedMemory in interface StorageEngine<Long,V>
Returns:
memory allocated for this engine in bytes

getOccupiedMemory

public long getOccupiedMemory()
Description copied from interface: StorageEngine
Returns a measure of the amount of memory consumed by this storage engine.

Specified by:
getOccupiedMemory in interface StorageEngine<Long,V>
Returns:
memory occupied by this engine in bytes

getVitalMemory

public long getVitalMemory()
Description copied from interface: StorageEngine
Returns a measure of the amount of vital memory allocated for this storage engine.

Specified by:
getVitalMemory in interface StorageEngine<Long,V>
Returns:
vital memory allocated for this engine in bytes

getDataSize

public long getDataSize()
Description copied from interface: StorageEngine
Returns a measure of the total size of the keys and values stored in this storage engine.

Specified by:
getDataSize in interface StorageEngine<Long,V>
Returns:
size of the stored keys and values in bytes

toString

public String toString()
Overrides:
toString in class Object

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<Long,V>

bind

public void bind(StorageEngine.Owner owner)
Specified by:
bind in interface StorageEngine<Long,V>

destroy

public void destroy()
Specified by:
destroy in interface StorageEngine<Long,V>

shrink

public boolean shrink()
Specified by:
shrink in interface StorageEngine<Long,V>


Copyright © 2015. All Rights Reserved.