|
Mobios v0.91 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object mobios.util.MckoiObjectIOManager
public class MckoiObjectIOManager
An implementation of ObjectIOManager
based on the Mckoi(http://www.mckoi.com/database)
I/O mechanism. It is backed by a Store
(defined in Mckoi), and is able to perform cached
page-based I/O on a file on disk or in memory. The serialized form of an object is read
from/written to the stream. In Mckoi, a Store
manages a collection of Area
s.
In this class, each Area saves the serialized format of an Object
. Therefore, an Object
that can be read/written by this class should be serializable. For example, the following code
creates a MckoiObjectIOManager
that works on multiple disk files, using the new java.nio
package, with cache and page-based access mechanism.
BufferManager myBM = new BufferManager("Java NIO", 65536, 4096);
//Create a ScatteringFileStore, the disk files are on current directory, file names start with "test"
if one file grows too big, it will be split, all files have extension names start from "0",
max file size is 1G. The buffer manager is the one just created, and the files are in read/write mode
If the last argument is true, then the file is read only:
Store myStore = new ScatteringFileStore("", "test", "0", 1024*1024*1024, myBM, false);
// create a MckoiObjectIOManager with the store instance just created
ObjectIOManager myManager = new MckoiObjectIOManager( mystore);
//Create a buffer manager, using java.nio mechanism, max page number:65536, page size:4096 bytes,
you can also use java IO mechsnism, by providing "java IO", which is recommended:
if (myManger.open() == false)
System.out.println("Error opening ObjectIOManager: myManager!");
Constructor Summary | |
---|---|
MckoiObjectIOManager(Store store)
Constructor. |
|
MckoiObjectIOManager(String fileHeader,
String fileExt,
long fileSize,
String bufferType,
int cacheSize,
int pageSize,
boolean readOnly)
Constructor. |
Method Summary | |
---|---|
void |
close()
Closes the backing stream. |
void |
flush()
Flushes the backing stream. |
Iterator |
iterator()
|
boolean |
open()
Opens the backing stream. |
Object |
readObject(long pointer)
Reads a previously written object at a given position. |
Object |
readPersistObject(long pointer)
Reads a previously written object at a given position, and holds this object in memory for the duration of the program. |
Object |
removeObject(long pointer)
Deletes an object from the underlying stream. |
long |
size()
|
long |
writeObject(Object object)
Writes a new object to the underlying stream. |
Object |
writeObject(Object object,
long pointer)
Writes an object to a given position in the underlying stream. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MckoiObjectIOManager(Store store)
store
- the mckoi store to use as the backing store.public MckoiObjectIOManager(String fileHeader, String fileExt, long fileSize, String bufferType, int cacheSize, int pageSize, boolean readOnly)
fileHeader
- header of backing file names, may include the pathfileExt
- extension name of backing files, normally use "000"fileSize
- max size of a backing file, if a file is not enough, more files will be usedbufferType
- type of buffer, should be one of "Java NIO" or "Java IO"cacheSize
- max number of pages in the buffer, could be 2 if only iterate over the data once.pageSize
- size of a page, in number of bytes. normally use "4096", could be larger for
sequential read / write, for example: 4M (4*1024*1024)readOnly
- if true, the backing files are read onlyMethod Detail |
---|
public boolean open()
ObjectIOManager
open
in interface ObjectIOManager
public void flush() throws IOException
ObjectIOManager
flush
in interface ObjectIOManager
IOException
public void close()
ObjectIOManager
close
in interface ObjectIOManager
public Object readObject(long pointer) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
ObjectIOManager
readObject
in interface ObjectIOManager
pointer
- the pointer to the object to be read from the underlying stream. The value is returned
when the object is first written to the stream with
ObjectIOManager.writeObject(java.lang.Object, long)
IOException
ClassNotFoundException
InstantiationException
IllegalAccessException
public Object readPersistObject(long pointer) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
ObjectIOManager
readPersistObject
in interface ObjectIOManager
pointer
- the pointer to the object to be read in the underlying stream. The value is returned
when the object is first written to the stream with
ObjectIOManager.writeObject(java.lang.Object, long)
IOException
ClassNotFoundException
InstantiationException
IllegalAccessException
public Object writeObject(Object object, long pointer) throws IOException, ClassNotFoundException
ObjectIOManager
writeObject
in interface ObjectIOManager
object
- the object to be written, cannot be null.pointer
- pointer to the underlying stream
IOException
ClassNotFoundException
public long writeObject(Object object) throws IOException
ObjectIOManager
writeObject
in interface ObjectIOManager
object
- the object to be added to the stream
IOException
public Object removeObject(long pointer) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
ObjectIOManager
removeObject
in interface ObjectIOManager
pointer
- pointer to the object to be deleted in the underlying stream.
IOException
ClassNotFoundException
InstantiationException
IllegalAccessException
public long size() throws IOException
size
in interface ObjectIOManager
IOException
public Iterator iterator()
iterator
in interface ObjectIOManager
Iterator
over all of the Area
s in the store
|
Mobios v0.91 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |