Mobios v0.91

mobios.util
Class MckoiObjectIOManager

java.lang.Object
  extended by mobios.util.MckoiObjectIOManager
All Implemented Interfaces:
ObjectIOManager

public class MckoiObjectIOManager
extends Object
implements ObjectIOManager

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 Areas. 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.

//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:

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);
if (myManger.open() == false)
System.out.println("Error opening ObjectIOManager: myManager!");

Version:
2005.11.01
Author:
Rui Mao

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

MckoiObjectIOManager

public MckoiObjectIOManager(Store store)
Constructor.

Parameters:
store - the mckoi store to use as the backing store.

MckoiObjectIOManager

public MckoiObjectIOManager(String fileHeader,
                            String fileExt,
                            long fileSize,
                            String bufferType,
                            int cacheSize,
                            int pageSize,
                            boolean readOnly)
Constructor.

Parameters:
fileHeader - header of backing file names, may include the path
fileExt - 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 used
bufferType - 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 only
Method Detail

open

public boolean open()
Description copied from interface: ObjectIOManager
Opens the backing stream. Makes the manager ready for I/O operations.

Specified by:
open in interface ObjectIOManager
Returns:
boolean true is sucessfully opened, otherwise false

flush

public void flush()
           throws IOException
Description copied from interface: ObjectIOManager
Flushes the backing stream. Saves all unsaved modifications.

Specified by:
flush in interface ObjectIOManager
Throws:
IOException

close

public void close()
Description copied from interface: ObjectIOManager
Closes the backing stream.

Specified by:
close in interface ObjectIOManager

readObject

public Object readObject(long pointer)
                  throws IOException,
                         ClassNotFoundException,
                         InstantiationException,
                         IllegalAccessException
Description copied from interface: ObjectIOManager
Reads a previously written object at a given position.

Specified by:
readObject in interface ObjectIOManager
Parameters:
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)
Returns:
the object that has been read
Throws:
IOException
ClassNotFoundException
InstantiationException
IllegalAccessException

readPersistObject

public Object readPersistObject(long pointer)
                         throws IOException,
                                ClassNotFoundException,
                                InstantiationException,
                                IllegalAccessException
Description copied from interface: ObjectIOManager
Reads a previously written object at a given position, and holds this object in memory for the duration of the program.

Specified by:
readPersistObject in interface ObjectIOManager
Parameters:
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)
Returns:
the object that has been read
Throws:
IOException
ClassNotFoundException
InstantiationException
IllegalAccessException

writeObject

public Object writeObject(Object object,
                          long pointer)
                   throws IOException,
                          ClassNotFoundException
Description copied from interface: ObjectIOManager
Writes an object to a given position in the underlying stream. This method modifies a previously written object at the given position.

Specified by:
writeObject in interface ObjectIOManager
Parameters:
object - the object to be written, cannot be null.
pointer - pointer to the underlying stream
Returns:
the original object that is overwritten.
Throws:
IOException
ClassNotFoundException

writeObject

public long writeObject(Object object)
                 throws IOException
Description copied from interface: ObjectIOManager
Writes a new object to the underlying stream.

Specified by:
writeObject in interface ObjectIOManager
Parameters:
object - the object to be added to the stream
Returns:
the pointer to the object in the stream.
Throws:
IOException

removeObject

public Object removeObject(long pointer)
                    throws IOException,
                           ClassNotFoundException,
                           InstantiationException,
                           IllegalAccessException
Description copied from interface: ObjectIOManager
Deletes an object from the underlying stream.

Specified by:
removeObject in interface ObjectIOManager
Parameters:
pointer - pointer to the object to be deleted in the underlying stream.
Returns:
the object be deleted
Throws:
IOException
ClassNotFoundException
InstantiationException
IllegalAccessException

size

public long size()
          throws IOException
Specified by:
size in interface ObjectIOManager
Returns:
the number of objects in the underlying stream
Throws:
IOException

iterator

public Iterator iterator()
Specified by:
iterator in interface ObjectIOManager
Returns:
an Iterator over all of the Areas in the store

Mobios v0.91

(C) 2002 - 2006 The MoBIoS Group