public final class HeapStore extends Object implements Store
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 and Description |
---|
HeapStore()
Defaults heap size to 257 elements.
|
HeapStore(int hash_size)
Creates the HeapStore.
|
Modifier and Type | Method and Description |
---|---|
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() |
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.
|
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.
|
public HeapStore(int hash_size)
public HeapStore()
public AreaWriter createArea(long size) throws IOException
Store
createArea
in interface Store
size
- the amount of memory to allocate.IOException
- if not enough space available to create the area or
the store is read-only.public void deleteArea(long pointer) throws IOException
Store
deleteArea
in interface Store
pointer
- the identifier of the area to delete.IOException
- (optional) if the id is invalid or the area can not
otherwise by deleted.public InputStream getAreaInputStream(long pointer) throws 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.IOException
- (optional) if the id is invalid or the area can not
otherwise be accessed.public Area getArea(long pointer) throws 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.IOException
- (optional) if the id is invalid or the area can not
otherwise be accessed.public MutableArea getMutableArea(long pointer) throws 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.IOException
- (optional) if the id is invalid or the area can not
otherwise be accessed.public void flush() throws IOException
IOException
public void synch() throws IOException
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 List getAllAreas() throws IOException
Store
getAllAreas
in interface Store
IOException
Copyright © 2015. All rights reserved.