public abstract class AbstractStore extends Object implements Store
Provided the derived class supports safe atomic IO operations, this store is designed for robustness to the level that at no point is the store left in a unworkable (corrupt) state.
Modifier and Type | Field and Description |
---|---|
protected static long |
BIN_AREA_OFFSET
The offset into the file that the bin area starts.
|
protected static int |
BIN_ENTRIES |
protected static long |
DATA_AREA_OFFSET
The offset into the file that the data areas start.
|
protected static long |
FIXED_AREA_OFFSET
The offset into the file of the 64 byte fixed area.
|
protected long[] |
free_bin_list
The free bin list contains 128 entries pointing to the first available
block in the bin.
|
protected byte[] |
header_buf |
protected static int |
MAGIC
The magic value.
|
protected boolean |
read_only
True if this is read-only.
|
protected long |
total_allocated_space
The total amount of allocated space within this store since the store
was openned.
|
protected long |
wilderness_pointer
A pointer to the wilderness area (the last deleted area in the store),
or -1 if there is no wilderness area.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractStore(boolean read_only)
Constructs the store.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkPointer(long pointer)
Checks the pointer is valid.
|
void |
close()
Closes the store.
|
protected void |
coalescArea(long pointer,
long size)
Coalesc one or more areas into a larger area.
|
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 id)
Deletes an area that was previously allocated by the 'createArea' method
by the area id.
|
protected abstract long |
endOfDataAreaPointer()
Returns a pointer to the end of the current data area.
|
protected long |
expandDataArea(long minimum_size)
Expands the data area by at least the minimum size given.
|
ArrayList |
findAllocatedAreasNotIn(ArrayList list)
Scans the area list, and any areas that aren't deleted and aren't found
in the given ArrayList are returned as leaked areas.
|
List |
getAllAreas()
Returns a List of Long objects that contain a complete list of all areas
in the store.
|
Area |
getArea(long id)
Returns an object that allows for the contents of an area (represented by
the 'id' parameter) to be read.
|
protected void |
getAreaHeader(long pointer,
long[] header)
Sets the 'header' array with information from the header of the given
pointer.
|
InputStream |
getAreaInputStream(long id)
Returns an InputStream implementation that allows for the area with the
given identifier to be read sequentially.
|
MutableArea |
getMutableArea(long id)
Returns an object that allows for the contents of an area (represented by
the 'id' parameter) to be read and written.
|
protected long |
getNextAreaHeader(long pointer,
long[] header)
Sets the 'header' array with information from the next header to the
given pointer, and returns a pointer to the next area.
|
protected long |
getPreviousAreaHeader(long pointer,
long[] header)
Sets the 'header' array with information from the previous header to the
given pointer, and returns a pointer to the previous area.
|
protected abstract void |
internalClose()
Internally closes the backing area.
|
protected abstract void |
internalOpen(boolean read_only)
Internally opens the backing area.
|
protected static boolean |
isValidBoundarySize(long size)
Returns true if the given area size is valid.
|
boolean |
lastCloseClean()
Returns true if the store was closed cleanly.
|
boolean |
open()
Opens the data store.
|
void |
openScanAndFix(UserTerminal terminal)
Opens/scans the store looking for any errors with the layout.
|
protected void |
readBins()
Reads the bins from the header information in the file.
|
protected abstract int |
readByteArrayFrom(long position,
byte[] buf,
int off,
int len)
Reads a byte array from the given position in the file.
|
protected abstract int |
readByteFrom(long position)
Reads a byte from the given position in the file.
|
protected void |
reboundArea(long pointer,
long[] header,
boolean write_headers)
Rebounds the given area with the given header information.
|
protected abstract void |
setDataAreaSize(long length)
Sets the size of the data area.
|
protected void |
splitArea(long pointer,
long new_boundary)
Splits an area pointed to by 'pointer' at a new boundary point.
|
void |
statsScan(HashMap properties)
Performs an extensive lookup on all the tables in this store and sets a
number of properties in the given HashMap
(property name(String) -> property description(Object)).
|
long |
totalAllocatedSinceStart()
Returns the total allocated space since the file was openned.
|
protected void |
writeAllBins()
Updates all bins to the data area header area.
|
protected void |
writeBinIndex(int index)
Updates the given bin index to the data area header area.
|
protected abstract void |
writeByteArrayTo(long position,
byte[] buf,
int off,
int len)
Writes a byte array to the given position in the file.
|
protected abstract void |
writeByteTo(long position,
int b)
Writes a byte to the given position in the file.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
lockForWrite, unlockForWrite
protected long[] free_bin_list
protected long wilderness_pointer
protected boolean read_only
protected long total_allocated_space
protected static final long DATA_AREA_OFFSET
protected static final long FIXED_AREA_OFFSET
protected static final long BIN_AREA_OFFSET
protected static final int MAGIC
protected final byte[] header_buf
protected static final int BIN_ENTRIES
public boolean open() throws IOException
IOException
public void close() throws IOException
IOException
protected static boolean isValidBoundarySize(long size)
public void openScanAndFix(UserTerminal terminal) throws IOException
IOException
public void statsScan(HashMap properties) throws IOException
Assume the store is open.
IOException
public List getAllAreas() throws IOException
getAllAreas
in interface Store
IOException
public ArrayList findAllocatedAreasNotIn(ArrayList list) throws IOException
IOException
public long totalAllocatedSinceStart()
protected abstract void internalOpen(boolean read_only) throws IOException
IOException
protected abstract void internalClose() throws IOException
IOException
protected abstract int readByteFrom(long position) throws IOException
IOException
protected abstract int readByteArrayFrom(long position, byte[] buf, int off, int len) throws IOException
IOException
protected abstract void writeByteTo(long position, int b) throws IOException
IOException
protected abstract void writeByteArrayTo(long position, byte[] buf, int off, int len) throws IOException
IOException
protected abstract long endOfDataAreaPointer() throws IOException
IOException
protected abstract void setDataAreaSize(long length) throws IOException
IOException
protected void checkPointer(long pointer) throws IOException
IOException
protected void readBins() throws IOException
IOException
protected void writeAllBins() throws IOException
IOException
protected void writeBinIndex(int index) throws IOException
IOException
protected void getAreaHeader(long pointer, long[] header) throws IOException
IOException
protected long getPreviousAreaHeader(long pointer, long[] header) throws IOException
IOException
protected long getNextAreaHeader(long pointer, long[] header) throws IOException
IOException
protected void reboundArea(long pointer, long[] header, boolean write_headers) throws IOException
IOException
protected void coalescArea(long pointer, long size) throws IOException
IOException
protected long expandDataArea(long minimum_size) throws IOException
IOException
protected void splitArea(long pointer, long new_boundary) throws IOException
IOException
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 id) throws IOException
Store
deleteArea
in interface Store
id
- 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 id) 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
id
- 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 id) 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
id
- 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 id) 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
id
- 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 boolean lastCloseClean()
Store
lastCloseClean
in interface Store
Copyright © 2015. All rights reserved.