Mobios v0.91

mobios.mckoi.store
Class AbstractStore

java.lang.Object
  extended by mobios.mckoi.store.AbstractStore
All Implemented Interfaces:
Store
Direct Known Subclasses:
ScatteringFileStore

public abstract class AbstractStore
extends Object
implements Store

Provides an abstract implementation of Store. This implements a bin based best-fit recycling algorithm. The store manages a structure that points to bins of freed space of specific sizes. When an allocation is requested the structure is searched for the first bin that contains an area that best fits the size requested.

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.

Version:
2003.07.29
Author:
Tobias Downer, Rui Mao

Method Summary
 long alloc(long size)
          Allocates a block of memory out of the store of the specified size, and returns a pointer to the block.
 void close()
          Closes the store.
 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.
 void free(long pointer)
          Frees a block of memory from the store that was previously allocated via 'alloc'.
 List getAllAreas()
          Returns a List of Long objects that contain a complete list of all areas in the store.
 Area getArea(long pointer)
          Returns an Area object that can be used to manipulate an area allocated from the store.
 Area getFixedArea()
          Returns an Area object that represents the 64 byte fixed area as can be changed by the 'getFixedArea' and 'setFixedArea' methods.
 void getFixedArea(byte[] buf, int off, int len)
           
 InputStream getInputStream(long pointer)
          Returns an InputStream for reading from the area of the store allocated via the 'alloc' method.
 OutputStream getOutputStream(long pointer)
          Returns an OutputStream for writing to the area of the store allocated via the 'alloc' method.
 Iterator iterator()
           
 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.
 void setFixedArea(byte[] buf, int off, int len)
           
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface mobios.mckoi.store.Store
flush, synch
 

Method Detail

open

public boolean open()
             throws IOException
Opens the data store. Returns true if the store did not close cleanly.

Throws:
IOException

close

public void close()
           throws IOException
Closes the store.

Throws:
IOException

openScanAndFix

public void openScanAndFix(UserTerminal terminal)
                    throws IOException
Opens/scans the store looking for any errors with the layout. If a problem with the store is detected, it attempts to fix it.

Throws:
IOException

statsScan

public void statsScan(HashMap properties)
               throws IOException
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)). This should be used for store diagnostics.

Assume the store is open.

Throws:
IOException

getAllAreas

public List getAllAreas()
                 throws IOException
Returns a List of Long objects that contain a complete list of all areas in the store. This is useful for checking if a given pointer is valid or not. The returned list is sorted from start area to end area.

Specified by:
getAllAreas in interface Store
Throws:
IOException

findAllocatedAreasNotIn

public ArrayList findAllocatedAreasNotIn(ArrayList list)
                                  throws IOException
Scans the area list, and any areas that aren't deleted and aren't found in the given ArrayList are returned as leaked areas. This is a useful method for finding any leaks in the store.

Throws:
IOException

totalAllocatedSinceStart

public long totalAllocatedSinceStart()
Returns the total allocated space since the file was openned.


alloc

public long alloc(long size)
           throws IOException
Description copied from interface: Store
Allocates a block of memory out of the store of the specified size, and returns a pointer to the block. If the store can not allocate an area of memory large enough for the request, a StoreException exception is thrown. This also throws a StoreException if the backing store is read-only.

Specified by:
alloc in interface Store
Parameters:
size - the amount of memory to allocate.
Returns:
a 64-bit pointer to the allocated memory.
Throws:
IOException - is the allocation can not happen.

free

public void free(long pointer)
          throws IOException
Description copied from interface: Store
Frees a block of memory from the store that was previously allocated via 'alloc'. Freeing an invalid pointer is implementation defined, however the ideal behaviour is for a StoreException to be thrown.

Specified by:
free in interface Store
Parameters:
pointer - a 64-bit pointer to the memory to free.
Throws:
IOException

setFixedArea

public void setFixedArea(byte[] buf,
                         int off,
                         int len)
                  throws IOException
Throws:
IOException

getFixedArea

public void getFixedArea(byte[] buf,
                         int off,
                         int len)
                  throws IOException
Throws:
IOException

getFixedArea

public Area getFixedArea()
                  throws IOException
Description copied from interface: Store
Returns an Area object that represents the 64 byte fixed area as can be changed by the 'getFixedArea' and 'setFixedArea' methods.

Specified by:
getFixedArea in interface Store
Throws:
IOException

getInputStream

public InputStream getInputStream(long pointer)
                           throws IOException
Description copied from interface: Store
Returns an InputStream for reading from the area of the store allocated via the 'alloc' method. Trying to read from an invalid pointer is implementation defined, however the ideal behaviour is for a StoreException to be thrown.

The returned stream does not perform buffering. For efficiency, it is a good idea to wrap the returned steam with a BufferedInputStream.

Specified by:
getInputStream in interface Store
Parameters:
pointer - a 64-bit pointer to the memory to read.
Returns:
an InputStream for reading from the allocated resource.
Throws:
IOException

getOutputStream

public OutputStream getOutputStream(long pointer)
                             throws IOException
Description copied from interface: Store
Returns an OutputStream for writing to the area of the store allocated via the 'alloc' method. Trying to write to an invalid pointer is implementation defined, however the ideal behaviour is for a StoreException to be thrown. This also throws a StoreException if the backing store is read-only.

The returned stream does not perform buffering. For efficiency, it is a good idea to wrap the returned steam with a BufferedOutputStream.

Specified by:
getOutputStream in interface Store
Parameters:
pointer - a 64-bit pointer to the memory to write.
Returns:
an OutputStream for writing to the allocated resource.
Throws:
IOException

getArea

public Area getArea(long pointer)
             throws IOException
Description copied from interface: Store
Returns an Area object that can be used to manipulate an area allocated from the store. The returned Area performs buffering.

Specified by:
getArea in interface Store
Parameters:
pointer - a 64-bit pointer to the area (allocated via 'alloc').
Returns:
an Area object for manipulating the area.
Throws:
IOException

lastCloseClean

public boolean lastCloseClean()
Description copied from interface: Store
Returns true if the store was closed cleanly. This is important information that may need to be considered when reading information from the store. This is typically used to issue a scan on the data in the store when it is not closed cleanly.

Specified by:
lastCloseClean in interface Store

iterator

public Iterator iterator()

Mobios v0.91

(C) 2002 - 2006 The MoBIoS Group