org.oreodata.standalone
Class InMemoryDataSource

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--org.oreodata.AbstractDataSource
                          |
                          +--org.oreodata.standalone.InMemoryDataSource
All Implemented Interfaces:
DataListener, java.util.EventListener, OreoDataSource, java.rmi.Remote, java.io.Serializable

public class InMemoryDataSource
extends AbstractDataSource

A simple standalone implementation of the org.oreodata.OreoDataSource interface. All of the records are held in memory. You must specify a DATA_PATH property when configuring an instance of this data source. This must be a directory on which your process has read/write privileges. You may optionally specify the base filename. If none is specified, it will use the name of the data source. You can use the USE_XML init parameter to indicate that the data file should be stored in an XML format. If you use XML, you can specify the optional parameter ENCODING to indicate the encoding in which the XML files will be stored. The default is UTF-8. You may also specify a SNAPSHOT_FREQUENCY parameter, which says how frequently to rotate the transaction log. The default (if no value is specified) is 100. When the log is rotated, this datasource archives a snapshot+log in gzip format. Compression seems logical, since the XML format is so extremely fat and redundant!

You can set the following properties in your datasources.xml config file.

Parameter Description Default
DATA_PATH The directory in which to store the data and log files. This must be a location where your process has read/write priveleges. This is required if FILENAME is not specified or is not an absolute path.
FILENAME The filename for the data file. If this is an absolute filename, it must refer to a a directory where your process has read/write priveleges. The name of the datasource
LOGFILE The filename for the log file. The data filename + _log
SNAPSHOT_REQUENCY The frequency (in number of logged transactions) to write a new snapshot of the data and rotate the data logfiles. "100"
GZIP_SNAPSHOTS Whether to archive the most recent data file in .gz format. "Y"
GZIP_OLD_SNAPSHOTS Whether to archive old snapshots in .gz format "Y"
GZIP_OLD_LOGS Whether to archive old logs in .gz format "Y"
USE_XML Whether to store the log and snapshot in an XML format. location of the XML files. "N"
ENCODING The character encoding to write the XML files. (Only relevant if USE_XML is set to "Y" "UTF-8quot;

Author:
Jonathan Revusky
See Also:
Serialized Form

Field Summary
protected  DataLogger dataLogger
           
 
Fields inherited from class org.oreodata.AbstractDataSource
defaultCharEncoding, lastLogRotation, transactionCount
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
InMemoryDataSource()
           
 
Method Summary
 Record delete(Record record)
          Delete a record.
 Record delete(java.lang.String type, java.lang.Object key)
          Delete a record.
protected  void fireDataEvent(DataEvent event)
          Fire a data event to the listeners.
 Record get(java.lang.String type, java.lang.Object key)
           
 void init(java.util.Properties properties)
          A method that initializes a DataSource with a set of initialization properties.
protected  void initDataLogger(java.util.Properties properties)
           
 Record insert(Record record)
          Adds a new record to the managed pool.
 java.util.List keys(java.lang.String type)
           
 void reload(Record rec)
          loads a Record without any notification to listeners or any synchronization.
 java.util.List select(RecordFilter filter, RecordComparator comparator)
          Fetches a list of records matching filter.
protected  boolean timeToRotate()
           
 Record update(Record oldRec, Record newRec)
          Replaces an existing version of a record with a new updated version.
 
Methods inherited from class org.oreodata.AbstractDataSource
addDataListener, close, fireEvents, freeze, freeze, get, getName, handleEvent, keys, lookup, markStale, normalizeKey, reload, removeDataListener, select, setFireEvents, setUseXML, useXML, wipeCache, writeElement, writeSnapshot
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

dataLogger

protected DataLogger dataLogger
Constructor Detail

InMemoryDataSource

public InMemoryDataSource()
                   throws java.io.IOException
Method Detail

init

public void init(java.util.Properties properties)
          throws java.io.IOException
Description copied from interface: OreoDataSource
A method that initializes a DataSource with a set of initialization properties. This is called internally within Oreo and should not be called by application code. As an implementor, you should make sure that this method is only called once, for example, throw a RuntimeException if an attempt is made to call this on a DataSource a second time.

Specified by:
init in interface OreoDataSource
Overrides:
init in class AbstractDataSource
java.io.IOException

initDataLogger

protected void initDataLogger(java.util.Properties properties)
                       throws java.io.IOException
java.io.IOException

delete

public Record delete(Record record)
              throws java.io.IOException
Description copied from interface: OreoDataSource
Delete a record.

Specified by:
delete in interface OreoDataSource
Overrides:
delete in class AbstractDataSource
Parameters:
record - the record to delete.
Returns:
the deleted Record of the given type, with the given lookup key.
java.io.IOException

delete

public Record delete(java.lang.String type,
                     java.lang.Object key)
              throws java.io.IOException
Description copied from interface: OreoDataSource
Delete a record.

Specified by:
delete in interface OreoDataSource
Overrides:
delete in class AbstractDataSource
Parameters:
type - the type of the record, if this is null, then any type will do.
key - the primary key of the record to delete.
Returns:
the deleted Record of the given type, with the given lookup key.
java.io.IOException

update

public Record update(Record oldRec,
                     Record newRec)
              throws java.io.IOException
Description copied from interface: OreoDataSource
Replaces an existing version of a record with a new updated version. Some implementations may use the oldRec parameter to guarantee that there are no concurrency issues. In such case, it would throw a ConcurrentModificationException

Specified by:
update in interface OreoDataSource
Overrides:
update in class AbstractDataSource
Parameters:
oldRec - the record to replace.
newRec - the new record.
Returns:
the updated record (frozen).
Throws:
java.io.IOException - thrown in case of any other database or communication error.

insert

public Record insert(Record record)
              throws java.io.IOException
Description copied from interface: OreoDataSource
Adds a new record to the managed pool.

Specified by:
insert in interface OreoDataSource
Overrides:
insert in class AbstractDataSource
Parameters:
record - the record to add
Returns:
the added record (frozen).
Throws:
java.io.IOException - if the record cannot be initialized (i.e. has missing fields or invalid field values, etc.), or in case of a low-level error.

select

public java.util.List select(RecordFilter filter,
                             RecordComparator comparator)
                      throws java.io.IOException
Description copied from interface: OreoDataSource
Fetches a list of records matching filter. If filter is null, returns all the records in the container. If the comparator is null, no sorting is carried out on the resulting list.

Specified by:
select in interface OreoDataSource
Overrides:
select in class AbstractDataSource
Parameters:
filter - the record filter, or null.
comparator - defines an ordering for the records.
Returns:
a List of all the records that are an instance of a given class. If no records match the filter, an empty List.
java.io.IOException

get

public Record get(java.lang.String type,
                  java.lang.Object key)
           throws java.io.IOException
Parameters:
type - the type of the record, if this is null, then any type will do.
key - the lookup key
Returns:
a Record of the given type, with the given lookup key.
java.io.IOException

keys

public java.util.List keys(java.lang.String type)
                    throws java.io.IOException
Specified by:
keys in interface OreoDataSource
Overrides:
keys in class AbstractDataSource
Parameters:
type - the record type we are interested, under some circumstances, this may be null.
Returns:
a list of all valid lookup keys that correspond to a given record type.
java.io.IOException

reload

public void reload(Record rec)
            throws java.io.IOException
Description copied from interface: OreoDataSource
loads a Record without any notification to listeners or any synchronization. Should only be used when restarting an app and restoring the data.

Specified by:
reload in interface OreoDataSource
Overrides:
reload in class AbstractDataSource
java.io.IOException

fireDataEvent

protected void fireDataEvent(DataEvent event)
                      throws java.io.IOException
Description copied from class: AbstractDataSource
Fire a data event to the listeners.

Overrides:
fireDataEvent in class AbstractDataSource
java.io.IOException

timeToRotate

protected boolean timeToRotate()