Prevayler™
The Free Software
Prevalence Layer

org.prevayler
Class PrevaylerFactory

java.lang.Object
  extended byorg.prevayler.PrevaylerFactory

public class PrevaylerFactory
extends java.lang.Object

Provides easy access to all Prevayler configurations and implementations available in this distribution. Static methods are also provided as short-cuts for the most common configurations.
By default, the Prevayler instances created by this class will write their Transactions to .transactionLog files before executing them. The FileDescriptor.sync() method is called to make sure the Java file write-buffers have been written to the operating system. Many operating systems, including most recent versions of Linux and Windows, allow the hard-drive's write-cache to be disabled. This guarantees no executed Transaction will be lost in the event of a power shortage, for example.
Also by default, the Prevayler instances created by this class will filter out all Transactions that would throw a RuntimeException or Error if executed on the Prevalent System. This requires enough RAM to hold another copy of the prevalent system.

See Also:
Prevayler

Field Summary
static int DEFAULT_REPLICATION_PORT
           
 
Constructor Summary
PrevaylerFactory()
           
 
Method Summary
 void configureClock(Clock clock)
          Configures the Clock that will be used by the created Prevayler.
 void configurePrevalenceBase(java.lang.String prevalenceBase)
          Configures the directory where the created Prevayler will read and write its .transactionLog and .snapshot files.
 void configurePrevalentSystem(java.lang.Object newPrevalentSystem)
          Configures the prevalent system that will be used by the Prevayler created by this factory.
 void configureReplicationClient(java.lang.String remoteServerIpAddress, int remoteServerPort)
          Reserved for future implementation.
 void configureReplicationServer(int port)
          Reserved for future implementation.
 void configureSnapshotManager(SnapshotManager snapshotManager)
          Configures the SnapshotManager to be used by the Prevayler created by this factory.
 void configureTransactionFiltering(boolean transactionFiltering)
          Determines whether the Prevayler created by this factory should filter out all Transactions that would throw a RuntimeException or Error if executed on the Prevalent System (default is true).
 void configureTransactionLogFileAgeThreshold(long ageInMilliseconds)
           
 void configureTransactionLogFileSizeThreshold(long sizeInBytes)
           
 void configureTransientMode(boolean transientMode)
          Determines whether the Prevayler created by this factory should be transient (transientMode = true) or persistent (transientMode = false).
 Prevayler create()
          Returns a Prevayler created according to what was defined by calls to the configuration methods above.
static Prevayler createCheckpointPrevayler(java.io.Serializable newPrevalentSystem, java.lang.String snapshotDirectory)
          Creates a Prevayler that will execute Transactions WITHOUT writing them to disk.
static Prevayler createPrevayler(java.io.Serializable newPrevalentSystem)
          Creates a Prevayler that will use a directory called "PrevalenceBase" under the current directory to read and write its .snapshot and .transactionLog files.
static Prevayler createPrevayler(java.io.Serializable newPrevalentSystem, java.lang.String prevalenceBase)
          Creates a Prevayler that will use the given prevalenceBase directory to read and write its .snapshot and .transactionLog files.
static Prevayler createTransientPrevayler(java.io.Serializable newPrevalentSystem)
          Creates a Prevayler that will execute Transactions WITHOUT writing them to disk.
static Prevayler createTransientPrevayler(java.io.Serializable newPrevalentSystem, java.lang.String snapshotDirectory)
          Deprecated. Use createCheckpointPrevayler() instead of this method. Deprecated since Prevayler2.00.001.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_REPLICATION_PORT

public static final int DEFAULT_REPLICATION_PORT
See Also:
Constant Field Values
Constructor Detail

PrevaylerFactory

public PrevaylerFactory()
Method Detail

createPrevayler

public static Prevayler createPrevayler(java.io.Serializable newPrevalentSystem)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
Creates a Prevayler that will use a directory called "PrevalenceBase" under the current directory to read and write its .snapshot and .transactionLog files.

Parameters:
newPrevalentSystem - The newly started, "empty" prevalent system that will be used as a starting point for every system startup, until the first snapshot is taken.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

createPrevayler

public static Prevayler createPrevayler(java.io.Serializable newPrevalentSystem,
                                        java.lang.String prevalenceBase)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
Creates a Prevayler that will use the given prevalenceBase directory to read and write its .snapshot and .transactionLog files.

Parameters:
newPrevalentSystem - The newly started, "empty" prevalent system that will be used as a starting point for every system startup, until the first snapshot is taken.
prevalenceBase - The directory where the .snapshot files and .transactionLog files will be read and written.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

createTransientPrevayler

public static Prevayler createTransientPrevayler(java.io.Serializable newPrevalentSystem)
Creates a Prevayler that will execute Transactions WITHOUT writing them to disk. This is useful for running automated tests or demos MUCH faster than with a regular Prevayler. Attempts to take snapshots on this transient Prevayler will throw an IOException.

Parameters:
newPrevalentSystem - The newly started, "empty" prevalent system.
See Also:
createCheckpointPrevayler(Serializable newPrevalentSystem, String snapshotDirectory)

createTransientPrevayler

public static Prevayler createTransientPrevayler(java.io.Serializable newPrevalentSystem,
                                                 java.lang.String snapshotDirectory)
Deprecated. Use createCheckpointPrevayler() instead of this method. Deprecated since Prevayler2.00.001.


createCheckpointPrevayler

public static Prevayler createCheckpointPrevayler(java.io.Serializable newPrevalentSystem,
                                                  java.lang.String snapshotDirectory)
Creates a Prevayler that will execute Transactions WITHOUT writing them to disk. Snapshots will work as "checkpoints" for the system, therefore. This is useful for stand-alone applications that have a "Save" button, for example.

Parameters:
newPrevalentSystem - The newly started, "empty" prevalent system that will be used as a starting point for every system startup, until the first snapshot is taken.
snapshotDirectory - The directory where the .snapshot files will be read and written.

configureTransientMode

public void configureTransientMode(boolean transientMode)
Determines whether the Prevayler created by this factory should be transient (transientMode = true) or persistent (transientMode = false). A transient Prevayler will execute its Transactions WITHOUT writing them to disk. This is useful for stand-alone applications which have a "Save" button, for example, or for running automated tests MUCH faster than with a persistent Prevayler.


configureClock

public void configureClock(Clock clock)
Configures the Clock that will be used by the created Prevayler. The Clock interface can be implemented by the application if it requires Prevayler to use a special time source other than the machine clock (default).


configurePrevalenceBase

public void configurePrevalenceBase(java.lang.String prevalenceBase)
Configures the directory where the created Prevayler will read and write its .transactionLog and .snapshot files. The default is a directory called "PrevalenceBase" under the current directory.

Parameters:
prevalenceBase - Will be ignored for the .snapshot files if a SnapshotManager is configured.

configurePrevalentSystem

public void configurePrevalentSystem(java.lang.Object newPrevalentSystem)
Configures the prevalent system that will be used by the Prevayler created by this factory.

Parameters:
newPrevalentSystem - Will be ignored if a SnapshotManager is configured too because a SnapshotManager already has a prevalent system. If the default SnapshotManager is used, this prevalentSystem must be Serializable. If another SnapshotManager is used, this prevalentSystem must be compatible with it.
See Also:
configureSnapshotManager(SnapshotManager)

configureReplicationClient

public void configureReplicationClient(java.lang.String remoteServerIpAddress,
                                       int remoteServerPort)
Reserved for future implementation.


configureReplicationServer

public void configureReplicationServer(int port)
Reserved for future implementation.


configureSnapshotManager

public void configureSnapshotManager(SnapshotManager snapshotManager)
Configures the SnapshotManager to be used by the Prevayler created by this factory. The default is a SnapshotManager which uses plain Java serialization to create its .snapshot files.


configureTransactionFiltering

public void configureTransactionFiltering(boolean transactionFiltering)
Determines whether the Prevayler created by this factory should filter out all Transactions that would throw a RuntimeException or Error if executed on the Prevalent System (default is true). This requires enough RAM to hold another copy of the prevalent system.


create

public Prevayler create()
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Returns a Prevayler created according to what was defined by calls to the configuration methods above.

Throws:
java.io.IOException - If there is trouble creating the Prevalence Base directory or reading a .transactionLog or .snapshot file.
java.lang.ClassNotFoundException - If a class of a serialized Object is not found when reading a .transactionLog or .snapshot file.

configureTransactionLogFileSizeThreshold

public void configureTransactionLogFileSizeThreshold(long sizeInBytes)

configureTransactionLogFileAgeThreshold

public void configureTransactionLogFileAgeThreshold(long ageInMilliseconds)


'Prevayler' is a trademark of Klaus Wuestefeld.
Copyleft 2001-2004 Klaus Wuestefeld.