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

java.lang.Object
  extended by org.terracotta.offheapstore.storage.listener.AbstractListenableStorageEngine<K,V>
      extended by org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine<K,V>
          extended by org.terracotta.offheapstore.storage.OffHeapBufferStorageEngine<K,V>
Type Parameters:
K - key type handled by this engine
V - value type handled by this engine
All Implemented Interfaces:
OffHeapStorageArea.Owner, BinaryStorageEngine, ListenableStorageEngine<K,V>, StorageEngine<K,V>
Direct Known Subclasses:
SerializableStorageEngine, StringStorageEngine

public class OffHeapBufferStorageEngine<K,V>
extends PortabilityBasedStorageEngine<K,V>
implements OffHeapStorageArea.Owner

A generic ByteBuffer based key/value store.

This storage engine implementation uses Portability instances to convert key/value instances in to ByteBuffers. The content of these ByteBuffers are then stored in slices of a single large data area.

Author:
Chris Dennis

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.terracotta.offheapstore.storage.StorageEngine
StorageEngine.Owner
 
Field Summary
protected  StorageEngine.Owner owner
           
protected  OffHeapStorageArea storageArea
           
 
Fields inherited from class org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine
keyPortability, valuePortability
 
Constructor Summary
OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability)
           
OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)
           
OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)
           
OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, float compressThreshold)
           
OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability)
          Creates a storage engine using the given page source, and portabilities.
OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)
           
OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)
           
OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, float compressThreshold)
           
 
Method Summary
 void bind(StorageEngine.Owner m)
           
protected  void clearInternal()
           
static
<K,V> Factory<OffHeapBufferStorageEngine<K,V>>
createFactory(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)
           
static
<K,V> Factory<OffHeapBufferStorageEngine<K,V>>
createFactory(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)
           
static
<K,V> Factory<OffHeapBufferStorageEngine<K,V>>
createFactory(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)
           
static
<K,V> Factory<OffHeapBufferStorageEngine<K,V>>
createFactory(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)
           
 void destroy()
           
 boolean evictAtAddress(long address, boolean shrink)
           
protected  void free(long address)
           
 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.
protected  WriteContext getKeyWriteContext(long address)
           
 long getOccupiedMemory()
          Returns a measure of the amount of memory consumed by this storage engine.
protected  WriteContext getValueWriteContext(long address)
           
 long getVitalMemory()
          Returns a measure of the amount of vital memory allocated for this storage engine.
 boolean isThief()
           
 boolean moved(long from, long to)
           
 ByteBuffer readKeyBuffer(long address)
           
 int readKeyHash(long encoding)
           
 ByteBuffer readValueBuffer(long address)
           
 boolean shrink()
           
 int sizeOf(long address)
           
 String toString()
           
 Lock writeLock()
           
protected  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.PortabilityBasedStorageEngine
attachedMapping, clear, equalsBinaryKey, equalsKey, equalsValue, freeMapping, invalidateCache, readBinaryKey, readBinaryValue, readKey, readValue, writeBinaryMapping, writeBinaryMapping, writeMapping
 
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, wait, wait, wait
 

Field Detail

storageArea

protected final OffHeapStorageArea storageArea

owner

protected volatile StorageEngine.Owner owner
Constructor Detail

OffHeapBufferStorageEngine

public OffHeapBufferStorageEngine(PointerSize width,
                                  PageSource source,
                                  int pageSize,
                                  Portability<? super K> keyPortability,
                                  Portability<? super V> valuePortability)
Creates a storage engine using the given page source, and portabilities.

Parameters:
width - int or long based engine
source - allocator used for storage allocation
pageSize - internal (constant) page size
keyPortability - key type portability
valuePortability - value type portability

OffHeapBufferStorageEngine

public OffHeapBufferStorageEngine(PointerSize width,
                                  PageSource source,
                                  int pageSize,
                                  Portability<? super K> keyPortability,
                                  Portability<? super V> valuePortability,
                                  float compressThreshold)

OffHeapBufferStorageEngine

public OffHeapBufferStorageEngine(PointerSize width,
                                  PageSource source,
                                  int initialPageSize,
                                  int maximalPageSize,
                                  Portability<? super K> keyPortability,
                                  Portability<? super V> valuePortability)

OffHeapBufferStorageEngine

public OffHeapBufferStorageEngine(PointerSize width,
                                  PageSource source,
                                  int initialPageSize,
                                  int maximalPageSize,
                                  Portability<? super K> keyPortability,
                                  Portability<? super V> valuePortability,
                                  float compressThreshold)

OffHeapBufferStorageEngine

public OffHeapBufferStorageEngine(PointerSize width,
                                  PageSource source,
                                  int pageSize,
                                  Portability<? super K> keyPortability,
                                  Portability<? super V> valuePortability,
                                  boolean thief,
                                  boolean victim)

OffHeapBufferStorageEngine

public OffHeapBufferStorageEngine(PointerSize width,
                                  PageSource source,
                                  int pageSize,
                                  Portability<? super K> keyPortability,
                                  Portability<? super V> valuePortability,
                                  boolean thief,
                                  boolean victim,
                                  float compressThreshold)

OffHeapBufferStorageEngine

public OffHeapBufferStorageEngine(PointerSize width,
                                  PageSource source,
                                  int initialPageSize,
                                  int maximalPageSize,
                                  Portability<? super K> keyPortability,
                                  Portability<? super V> valuePortability,
                                  boolean thief,
                                  boolean victim)

OffHeapBufferStorageEngine

public OffHeapBufferStorageEngine(PointerSize width,
                                  PageSource source,
                                  int initialPageSize,
                                  int maximalPageSize,
                                  Portability<? super K> keyPortability,
                                  Portability<? super V> valuePortability,
                                  boolean thief,
                                  boolean victim,
                                  float compressThreshold)
Method Detail

createFactory

public static <K,V> Factory<OffHeapBufferStorageEngine<K,V>> createFactory(PointerSize width,
                                                                           PageSource source,
                                                                           int pageSize,
                                                                           Portability<? super K> keyPortability,
                                                                           Portability<? super V> valuePortability,
                                                                           boolean thief,
                                                                           boolean victim)

createFactory

public static <K,V> Factory<OffHeapBufferStorageEngine<K,V>> createFactory(PointerSize width,
                                                                           PageSource source,
                                                                           int pageSize,
                                                                           Portability<? super K> keyPortability,
                                                                           Portability<? super V> valuePortability,
                                                                           boolean thief,
                                                                           boolean victim,
                                                                           float compressThreshold)

createFactory

public static <K,V> Factory<OffHeapBufferStorageEngine<K,V>> createFactory(PointerSize width,
                                                                           PageSource source,
                                                                           int initialPageSize,
                                                                           int maximalPageSize,
                                                                           Portability<? super K> keyPortability,
                                                                           Portability<? super V> valuePortability,
                                                                           boolean thief,
                                                                           boolean victim)

createFactory

public static <K,V> Factory<OffHeapBufferStorageEngine<K,V>> createFactory(PointerSize width,
                                                                           PageSource source,
                                                                           int initialPageSize,
                                                                           int maximalPageSize,
                                                                           Portability<? super K> keyPortability,
                                                                           Portability<? super V> valuePortability,
                                                                           boolean thief,
                                                                           boolean victim,
                                                                           float compressThreshold)

clearInternal

protected void clearInternal()
Specified by:
clearInternal in class PortabilityBasedStorageEngine<K,V>

free

protected void free(long address)
Specified by:
free in class PortabilityBasedStorageEngine<K,V>

readKeyBuffer

public ByteBuffer readKeyBuffer(long address)
Specified by:
readKeyBuffer in class PortabilityBasedStorageEngine<K,V>

getKeyWriteContext

protected WriteContext getKeyWriteContext(long address)
Specified by:
getKeyWriteContext in class PortabilityBasedStorageEngine<K,V>

readValueBuffer

public ByteBuffer readValueBuffer(long address)
Specified by:
readValueBuffer in class PortabilityBasedStorageEngine<K,V>

getValueWriteContext

protected WriteContext getValueWriteContext(long address)
Specified by:
getValueWriteContext in class PortabilityBasedStorageEngine<K,V>

writeMappingBuffers

protected Long writeMappingBuffers(ByteBuffer keyBuffer,
                                   ByteBuffer valueBuffer,
                                   int hash)
Specified by:
writeMappingBuffers in class PortabilityBasedStorageEngine<K,V>

writeMappingBuffersGathering

protected Long writeMappingBuffersGathering(ByteBuffer[] keyBuffers,
                                            ByteBuffer[] valueBuffers,
                                            int hash)
Overrides:
writeMappingBuffersGathering in class PortabilityBasedStorageEngine<K,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<K,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<K,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<K,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<K,V>
Returns:
size of the stored keys and values in bytes

toString

public String toString()
Overrides:
toString in class Object

destroy

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

shrink

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

evictAtAddress

public boolean evictAtAddress(long address,
                              boolean shrink)
Specified by:
evictAtAddress in interface OffHeapStorageArea.Owner

isThief

public boolean isThief()
Specified by:
isThief in interface OffHeapStorageArea.Owner

readKeyHash

public int readKeyHash(long encoding)
Specified by:
readKeyHash in interface BinaryStorageEngine

moved

public boolean moved(long from,
                     long to)
Specified by:
moved in interface OffHeapStorageArea.Owner

sizeOf

public int sizeOf(long address)
Specified by:
sizeOf in interface OffHeapStorageArea.Owner

bind

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

writeLock

public Lock writeLock()
Specified by:
writeLock in interface OffHeapStorageArea.Owner


Copyright © 2016. All rights reserved.