SPT Object Database API

com.sptci.prevayler
Class PrevalentSystemFactory

java.lang.Object
  extended by com.sptci.prevayler.PrevalentSystemFactory

public final class PrevalentSystemFactory
extends Object

A factory class used to boot-strap PrevalentSystem instances.

This class may be configured using the following JVM system properties:

  1. sptodb.data.dir - The directory under which the database snapshot and journal files are stored. The default value used if this property is not specified is /var/data/sptodb.
  2. sptodb.snapshot.interval - The interval in seconds at which snapshots of the prevalent system are to be taken. The default value used is 86400 (one day).
  3. sptodb.serialiser.format - The format to use for taking snapshots of the prevalent system and creating transaction journals. The supported options are:
    1. java - Indicates that regular Java object serialisation be used to take the snapshot and write journals. This is the default unless otherwise specified.
    2. xml - Indicates that the journals should be written and snapshot taken using XStream. XML serialisation is slower (both serialisation and de-serialisation), however gives you more options processing the prevalent system for other purposes. Also useful if you need to restore the system after heavy modifications (refactoring) to the object model.

The following code shows sample usage of this class

   import com.sptci.prevayler.PrevalentSystemFactory;
   import com.sptci.prevayler.transaction.Save;

   ...
     // MyPrevalentObject is a sub-class of PrevalentObject
     final MyPrevalentObject obj1 = new MyPrevalentObject();
     obj1.setXXX();
     ...
     final Save<MyPrevalentObject> save = new Save<MyPrevalentObject>( obj1 );
     final MyPrevalentObject obj2 = PrevalentSystemFactory.getPrevayler().execute( save );
     System.out.format( "MyPrevalentObject created with OID: %s%n", obj2.getObjectId() );
 

Version:
$Id: PrevalentSystemFactory.java 23 2008-11-24 19:49:55Z sptrakesh $
Author:
Rakesh Vidyadharan 2008-05-22
See Also:

© Copyright 2008 Sans Pareil Technologies, Inc.


Nested Class Summary
private static class PrevalentSystemFactory.SnapshotTask
          A TimerTask that is used to snapshot the PrevalentSystemFactory.SnapshotTask.prevayler periodically.
 
Field Summary
static String DATA_DIRECTORY
          The system parameter used to configure the prevalent data directory.
static String DEFAULT_DIRECTORY
          The default value to use for the prevalent data directory.
static String DEFAULT_SEARCH_BATCH_SIZE
          The default value for the SEARCH_BATCH_SIZE property.
static String DEFAULT_SERIALISER_FORMAT
          The default value for the SERIALISER_FORMAT property.
static String DEFAULT_SNAPSHOT_INTERVAL
          The default snapshot interval to use.
private static Logger logger
          The logger to use to log messages.
static String OBJECT_STORAGE
          The directory under DATA_DIRECTORY in which the prevalent objects are stored.
static String SEARCH_BATCH_SIZE
          The JVM system property used to specify the size of the batches in which the search index writer is to be committed.
static String SEARCH_STORAGE
          The directory under DATA_DIRECTORY under which lucene search indices are stored.
static String SERIALISER_FORMAT
          The JVM system property used to configure the serialisation technique used for snapshots and transaction journals.
static String SNAPSHOT_INTERVAL
          The system property used to configure the interval at which a snapshot of the database is taken.
private static ConcurrentMap<Class,Prevayler> systems
          A map used to maintain the various prevalent systems maintained by the factory.
 
Constructor Summary
private PrevalentSystemFactory()
          Default constructor.
 
Method Summary
protected static String getDatabaseDirectory(Class system)
          Return the directory under which serialised instances of the specified class are to be stored.
protected static String getDataDirectory()
          Return the root directory under which the entire database system is stored.
static Prevayler getPrevayler()
          Boot-strap a prevalent system using the default PrevalentSystem class.
static Prevayler getPrevayler(Class system)
          Create a prevalent system for the specified system class.
static Prevayler getPrevayler(Class system, String directory)
          Create a prevalent system for the specified system class.
static Prevayler getPrevayler(Class system, String directory, String serialiser)
          Create a prevalent system for the specified system class.
protected static int getSearchBatchSize()
          Return the size of the batch at which lucene index writer is to be committed.
protected static String getSearchDirectory(Class system)
          Return the directory under which the lucene full-text search indices are to be stored.
private static void snapshot(Prevayler prevayler)
          Start a timer task for taking snapshots of the prevalent system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA_DIRECTORY

public static final String DATA_DIRECTORY
The system parameter used to configure the prevalent data directory. "sptodb.data.dir"

See Also:
Constant Field Values

DEFAULT_DIRECTORY

public static final String DEFAULT_DIRECTORY
The default value to use for the prevalent data directory. "/var/data/sptodb"

See Also:
Constant Field Values

OBJECT_STORAGE

public static final String OBJECT_STORAGE
The directory under DATA_DIRECTORY in which the prevalent objects are stored. "data"

See Also:
Constant Field Values

SEARCH_STORAGE

public static final String SEARCH_STORAGE
The directory under DATA_DIRECTORY under which lucene search indices are stored. "search"

See Also:
Constant Field Values

SNAPSHOT_INTERVAL

public static final String SNAPSHOT_INTERVAL
The system property used to configure the interval at which a snapshot of the database is taken. Note that the value should be specified in seconds. "sptodb.snapshot.interval"

See Also:
Constant Field Values

DEFAULT_SNAPSHOT_INTERVAL

public static final String DEFAULT_SNAPSHOT_INTERVAL
The default snapshot interval to use. Default is 24 hours. "86400"

See Also:
Constant Field Values

SERIALISER_FORMAT

public static final String SERIALISER_FORMAT
The JVM system property used to configure the serialisation technique used for snapshots and transaction journals. "sptodb.serialiser.format"

See Also:
Constant Field Values

DEFAULT_SERIALISER_FORMAT

public static final String DEFAULT_SERIALISER_FORMAT
The default value for the SERIALISER_FORMAT property. Defaults to Java serialisation. "java"

See Also:
Constant Field Values

SEARCH_BATCH_SIZE

public static final String SEARCH_BATCH_SIZE
The JVM system property used to specify the size of the batches in which the search index writer is to be committed.

See Also:
Constant Field Values

DEFAULT_SEARCH_BATCH_SIZE

public static final String DEFAULT_SEARCH_BATCH_SIZE
The default value for the SEARCH_BATCH_SIZE property. "20"

See Also:
Constant Field Values

logger

private static final Logger logger
The logger to use to log messages.


systems

private static final ConcurrentMap<Class,Prevayler> systems
A map used to maintain the various prevalent systems maintained by the factory.

Constructor Detail

PrevalentSystemFactory

private PrevalentSystemFactory()
Default constructor. Cannot be instantiated.

Method Detail

getPrevayler

public static Prevayler getPrevayler()
                              throws PrevalentException
Boot-strap a prevalent system using the default PrevalentSystem class.

Returns:
The initialised prevayler instance to use.
Throws:
PrevalentException - If errors are encountered while boot strapping the prevalent system.
See Also:
getPrevayler( Class )

getPrevayler

public static Prevayler getPrevayler(Class system)
                              throws PrevalentException
Create a prevalent system for the specified system class.

Parameters:
system - The class that represents the prevalent system to be managed.
Returns:
The initialised prevayler instance to use.
Throws:
PrevalentException - If errors are encountered while boot strapping the prevalent system.
See Also:
getPrevayler( Class, String )

getPrevayler

public static Prevayler getPrevayler(Class system,
                                     String directory)
                              throws PrevalentException
Create a prevalent system for the specified system class.

Parameters:
system - The class that represents the prevalent system to be managed.
directory - The directory in which serialised state of the prevalent system is to be stored. Note that you must specify different directories if you are using this factory to boot-strap multiple prevalent system instances.
Returns:
The initialised prevayler instance to use.
Throws:
PrevalentException - If errors are encountered while boot strapping the prevalent system. Also thrown if the system specified is not a sub-class of PrevalentSystem.
See Also:
getPrevayler( Class, String, String )

getPrevayler

public static Prevayler getPrevayler(Class system,
                                     String directory,
                                     String serialiser)
                              throws PrevalentException
Create a prevalent system for the specified system class.

Parameters:
system - The class that represents the prevalent system to be managed.
directory - The directory in which serialised state of the prevalent system is to be stored. Note that you must specify different directories if you are using this factory to boot-strap multiple prevalent system instances.
serialiser - The serialiser to use for the transaction journals and snapshots. Valid values are java or xml.
Returns:
The initialised prevayler instance to use.
Throws:
PrevalentException - If errors are encountered while boot strapping the prevalent system. Also thrown if the system specified is not a sub-class of PrevalentSystem.
See Also:
snapshot(org.prevayler.Prevayler)

getDataDirectory

protected static String getDataDirectory()
Return the root directory under which the entire database system is stored. Note that this is the value of the DATA_DIRECTORY as configured or the default value.

Returns:
The configured directory or the default value.

getDatabaseDirectory

protected static String getDatabaseDirectory(Class system)
Return the directory under which serialised instances of the specified class are to be stored.

Parameters:
system - The class whose instances are to be stored.
Returns:
The directory under which the instances are to be serialised.

getSearchDirectory

protected static String getSearchDirectory(Class system)
Return the directory under which the lucene full-text search indices are to be stored.

Parameters:
system - The class whose search index location is to be returned
Returns:
The directory under which the search indices are stored.

getSearchBatchSize

protected static int getSearchBatchSize()
Return the size of the batch at which lucene index writer is to be committed.

Returns:
The number of transactions after which the index writer is to be committed and index reader re-opened.

snapshot

private static void snapshot(Prevayler prevayler)
Start a timer task for taking snapshots of the prevalent system. This method will be enhanced to take snapshots at configured intervals.

Parameters:
prevayler - The prevalent system to snapshot.

SPT Object Database API