org.apache.directmemory.memory
Class MemoryManagerServiceImpl<V>

java.lang.Object
  extended by org.apache.directmemory.memory.MemoryManagerServiceImpl<V>
All Implemented Interfaces:
MemoryManagerService<V>

public class MemoryManagerServiceImpl<V>
extends Object
implements MemoryManagerService<V>


Field Summary
protected  AllocationPolicy allocationPolicy
           
protected static org.slf4j.Logger logger
           
protected static long NEVER_EXPIRES
           
protected  AtomicLong used
           
 
Constructor Summary
MemoryManagerServiceImpl()
           
MemoryManagerServiceImpl(AllocationPolicy allocationPolicy, boolean returnNullWhenFull)
           
MemoryManagerServiceImpl(boolean returnNullWhenFull)
           
 
Method Summary
<T extends V>
Pointer<V>
allocate(Class<T> type, int size, long expiresIn, long expires)
          Deprecated. 
 long capacity()
           
 void clear()
           
 long collectExpired()
           
 void collectLFU()
           
protected  long free(Iterable<Pointer<V>> pointers)
           
 void free(Pointer<V> pointer)
           
protected  ByteBufferAllocator getAllocator(int allocatorIndex)
           
protected  List<ByteBufferAllocator> getAllocators()
           
protected  ByteBufferAllocator getCurrentAllocator()
           
 Set<Pointer<V>> getPointers()
           
 void init(int numberOfBuffers, int size)
          Initialize the internal structure.
protected  ByteBufferAllocator instanciateByteBufferAllocator(int allocatorNumber, int size)
           
protected  Pointer<V> instanciatePointer(ByteBuffer buffer, int allocatorIndex, long expiresIn, long expires)
           
 byte[] retrieve(Pointer<V> pointer)
           
protected  boolean returnsNullWhenFull()
           
 Pointer<V> store(byte[] payload)
          Same function as MemoryManagerService.store(byte[]), but add an relative expiration delta in milliseconds
 Pointer<V> store(byte[] payload, int expiresIn)
          Store function family.
 Pointer<V> update(Pointer<V> pointer, byte[] payload)
          Update value of a {@link Pointer
 long used()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEVER_EXPIRES

protected static final long NEVER_EXPIRES
See Also:
Constant Field Values

logger

protected static org.slf4j.Logger logger

used

protected final AtomicLong used

allocationPolicy

protected final AllocationPolicy allocationPolicy
Constructor Detail

MemoryManagerServiceImpl

public MemoryManagerServiceImpl()

MemoryManagerServiceImpl

public MemoryManagerServiceImpl(boolean returnNullWhenFull)

MemoryManagerServiceImpl

public MemoryManagerServiceImpl(AllocationPolicy allocationPolicy,
                                boolean returnNullWhenFull)
Method Detail

init

public void init(int numberOfBuffers,
                 int size)
Description copied from interface: MemoryManagerService
Initialize the internal structure. Need to be called before the service can be used.

Specified by:
init in interface MemoryManagerService<V>
Parameters:
numberOfBuffers - : number of internal bucket
size - : size in B of internal buckets

instanciateByteBufferAllocator

protected ByteBufferAllocator instanciateByteBufferAllocator(int allocatorNumber,
                                                             int size)

getAllocator

protected ByteBufferAllocator getAllocator(int allocatorIndex)

getCurrentAllocator

protected ByteBufferAllocator getCurrentAllocator()

store

public Pointer<V> store(byte[] payload,
                        int expiresIn)
Description copied from interface: MemoryManagerService
Store function family. Store the given payload at a certain offset in a MemoryBuffer, returning the pointer to the value.

Specified by:
store in interface MemoryManagerService<V>
Parameters:
payload - : the data to store
Returns:
the pointer to the value, or null if not enough space has been found.

store

public Pointer<V> store(byte[] payload)
Description copied from interface: MemoryManagerService
Same function as MemoryManagerService.store(byte[]), but add an relative expiration delta in milliseconds

Specified by:
store in interface MemoryManagerService<V>
Parameters:
payload - : the data to store
Returns:
the pointer to the value, or null if not enough space has been found.

update

public Pointer<V> update(Pointer<V> pointer,
                         byte[] payload)
Description copied from interface: MemoryManagerService
Update value of a {@link Pointer

Specified by:
update in interface MemoryManagerService<V>
Returns:

retrieve

public byte[] retrieve(Pointer<V> pointer)
Specified by:
retrieve in interface MemoryManagerService<V>

free

public void free(Pointer<V> pointer)
Specified by:
free in interface MemoryManagerService<V>

clear

public void clear()
Specified by:
clear in interface MemoryManagerService<V>

capacity

public long capacity()
Specified by:
capacity in interface MemoryManagerService<V>

used

public long used()
Specified by:
used in interface MemoryManagerService<V>

collectExpired

public long collectExpired()
Specified by:
collectExpired in interface MemoryManagerService<V>

collectLFU

public void collectLFU()
Specified by:
collectLFU in interface MemoryManagerService<V>

free

protected long free(Iterable<Pointer<V>> pointers)

getAllocators

protected List<ByteBufferAllocator> getAllocators()

allocate

@Deprecated
public <T extends V> Pointer<V> allocate(Class<T> type,
                                                    int size,
                                                    long expiresIn,
                                                    long expires)
Deprecated. 

Specified by:
allocate in interface MemoryManagerService<V>

instanciatePointer

protected Pointer<V> instanciatePointer(ByteBuffer buffer,
                                        int allocatorIndex,
                                        long expiresIn,
                                        long expires)

returnsNullWhenFull

protected boolean returnsNullWhenFull()

getPointers

public Set<Pointer<V>> getPointers()


Copyright © 2011-2012 The Apache Software Foundation. All Rights Reserved.