|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mckoi.store.HeapStore
public final class HeapStore
An implementation of the Store interface that persists information in the volatile JVM heap memory. Each Area in the store is represented by a byte[] array from the Java heap.
Note that in Java there is no way to cast a reference to a numeric value, or to cast a numeric value back into a reference. This means that Area lookup has to be coordinated via a hashing algorithm over an array. There would prehaps be a more efficient way to achieve this with JNI but it would mean we can't be pure Java and it would require locking the address of objects in the heap.
Another alternative way of implementing this class would be to use JNI to access a C style 'malloc' function in the operating system and wrap the memory with a native Area implementation.
Constructor Summary | |
---|---|
HeapStore()
Defaults heap size to 257 elements. |
|
HeapStore(int hash_size)
Creates the HeapStore. |
Method Summary | |
---|---|
AreaWriter |
createArea(long size)
Allocates a block of memory in the store of the specified size and returns an AreaWriter object that can be used to initialize the contents of the area. |
void |
deleteArea(long pointer)
Deletes an area that was previously allocated by the 'createArea' method by the area id. |
void |
flush()
|
java.util.List |
getAllAreas()
Returns a complete list of pointers to all areas in the Store as Long objects sorted from lowest pointer to highest. |
Area |
getArea(long pointer)
Returns an object that allows for the contents of an area (represented by the 'id' parameter) to be read. |
java.io.InputStream |
getAreaInputStream(long pointer)
Returns an InputStream implementation that allows for the area with the given identifier to be read sequentially. |
MutableArea |
getMutableArea(long pointer)
Returns an object that allows for the contents of an area (represented by the 'id' parameter) to be read and written. |
boolean |
lastCloseClean()
Returns true if the store was closed cleanly. |
void |
lockForWrite()
It is often useful to guarentee that a certain sequence of updates to a store is completed and not broken in the middle. |
void |
synch()
|
void |
unlockForWrite()
See the 'lockForWrite' method description. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HeapStore(int hash_size)
public HeapStore()
Method Detail |
---|
public AreaWriter createArea(long size) throws java.io.IOException
Store
createArea
in interface Store
size
- the amount of memory to allocate.
java.io.IOException
- if not enough space available to create the area or
the store is read-only.public void deleteArea(long pointer) throws java.io.IOException
Store
deleteArea
in interface Store
pointer
- the identifier of the area to delete.
java.io.IOException
- (optional) if the id is invalid or the area can not
otherwise by deleted.public java.io.InputStream getAreaInputStream(long pointer) throws java.io.IOException
Store
When 'id' is -1 then a fixed area (64 bytes in size) in the store is returned. The fixed area can be used to store important static static information.
getAreaInputStream
in interface Store
pointer
- the identifier of the area to read, or id = -1 is a 64 byte
fixed area in the store.
java.io.IOException
- (optional) if the id is invalid or the area can not
otherwise be accessed.public Area getArea(long pointer) throws java.io.IOException
Store
When 'id' is -1 then a fixed area (64 bytes in size) in the store is returned. The fixed area can be used to store important static static information.
getArea
in interface Store
pointer
- the identifier of the area to read, or id = -1 is a 64 byte
fixed area in the store.
java.io.IOException
- (optional) if the id is invalid or the area can not
otherwise be accessed.public MutableArea getMutableArea(long pointer) throws java.io.IOException
Store
When 'id' is -1 then a fixed area (64 bytes in size) in the store is returned. The fixed area can be used to store important static static information.
getMutableArea
in interface Store
pointer
- the identifier of the area to access, or id = -1 is a 64 byte
fixed area in the store.
java.io.IOException
- (optional) if the id is invalid or the area can not
otherwise be accessed.public void flush() throws java.io.IOException
java.io.IOException
public void synch() throws java.io.IOException
java.io.IOException
public void lockForWrite()
Store
To achieve this, the 'lockForWrite' and 'unlockForWrite' methods are available. When 'lockForWrite' has been called, a check point can not created until there are no write locks obtained on the table.
lockForWrite
in interface Store
public void unlockForWrite()
Store
unlockForWrite
in interface Store
public boolean lastCloseClean()
Store
lastCloseClean
in interface Store
public java.util.List getAllAreas() throws java.io.IOException
Store
getAllAreas
in interface Store
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |