|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.prevayler.PrevaylerFactory<P>
P
- The type of object you intend to persist as a Prevalent System. public class PrevaylerFactory<P>
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 .journal 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 execute deep copies of transactions, not the transactions themselves, so that unrecoverable changes to the prevalent system and unrecoverable uses of reference equality inside transactions fail fast as they would upon recovery.
Prevayler
Field Summary | |
---|---|
static int |
DEFAULT_REPLICATION_PORT
|
Constructor Summary | |
---|---|
PrevaylerFactory()
Example:
Use if you want access to any configuration options not available via the static method short-cuts. |
Method Summary | ||
---|---|---|
void |
configureClock(Clock clock)
Configures the Clock that will be used by the created Prevayler. |
|
void |
configureJournalDiskSync(boolean journalDiskSync)
Configures whether the journal will sync writes to disk. |
|
void |
configureJournalFileAgeThreshold(long ageInMilliseconds)
Sets the age (in milliseconds) of the journal file. |
|
void |
configureJournalFileSizeThreshold(long sizeInBytes)
Configures the size (in bytes) of the journal file. |
|
void |
configureJournalSerializer(JavaSerializer serializer)
|
|
void |
configureJournalSerializer(String suffix,
Serializer serializer)
Configures the transaction journal Serializer to be used by the Prevayler created by this factory. |
|
void |
configureJournalSerializer(XStreamSerializer serializer)
|
|
void |
configureMonitor(Monitor monitor)
Assigns a monitor object to receive notifications from Prevayler. |
|
void |
configurePrevalenceDirectory(String prevalenceDirectory)
Configures the directory where the created Prevayler will read and write its .journal and .snapshot files. |
|
void |
configurePrevalentSystem(P newPrevalentSystem)
Configures the prevalent system that will be used by the Prevayler created by this factory. |
|
void |
configureReplicationClient(String remoteServerIpAddress,
int remoteServerPort)
Reserved for future implementation. |
|
void |
configureReplicationServer(int port)
Reserved for future implementation. |
|
void |
configureSnapshotSerializer(JavaSerializer serializer)
|
|
void |
configureSnapshotSerializer(String suffix,
Serializer serializer)
Configure a serialization strategy for snapshots. |
|
void |
configureSnapshotSerializer(XStreamSerializer serializer)
|
|
void |
configureTransactionDeepCopy(boolean transactionDeepCopyMode)
Configures whether deep copies of transactions are executed instead of the transactions themselves, upon calling ".execute" on the created Prevayler. |
|
void |
configureTransientMode(boolean transientMode)
Determines whether the Prevayler created by this factory should be transient or persistent. |
|
Prevayler<P> |
create()
Returns a Prevayler created according to what was defined by calls to the configuration methods above. |
|
static
|
createCheckpointPrevayler(P newPrevalentSystem,
String snapshotDirectory)
Creates a Prevayler that will execute Transactions WITHOUT writing them to disk. |
|
static
|
createPrevayler(P newPrevalentSystem)
Creates a Prevayler that will use a directory called "PrevalenceBase" under the current directory to read and write its .snapshot and .journal files, using standard Java serialization. |
|
static
|
createPrevayler(P newPrevalentSystem,
String prevalenceBase)
Creates a Prevayler that will use the given prevalenceBase directory to read and write its .snapshot and .journal files, using standard Java serialization. |
|
static
|
createTransientPrevayler(P newPrevalentSystem)
Creates a Prevayler that will execute Transactions WITHOUT writing them to disk. |
|
static
|
createTransientPrevayler(P newPrevalentSystem,
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 |
---|
public static final int DEFAULT_REPLICATION_PORT
Constructor Detail |
---|
public PrevaylerFactory()
PrevaylerFactory<MyObjectToPersist> f = new PrevaylerFactory<MyObjectToPersist>();
Method Detail |
---|
public static <P> Prevayler<P> createPrevayler(P newPrevalentSystem, String prevalenceBase) throws Exception
//Your object:
MyObjectToPersist newPrevalentSystem = new MyObjectToPersist();
String prevalenceBase = "myDirectory";
Prevayler<MyObjectToPersist> prevayler = PrevaylerFactory.createPrevayler(newPrevalentSystem, prevalenceBase);
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 .journal files will be read and written.
Exception
public static <P> Prevayler<P> createPrevayler(P newPrevalentSystem) throws Exception
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.
Exception
createPrevayler(Object, String)
public static <P> Prevayler<P> createCheckpointPrevayler(P newPrevalentSystem, String snapshotDirectory)
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.createPrevayler(Object, String)
public static <P> Prevayler<P> createTransientPrevayler(P newPrevalentSystem)
newPrevalentSystem
- The newly started, "empty" prevalent system.createCheckpointPrevayler(Object, String)
public static <P> Prevayler<P> createTransientPrevayler(P newPrevalentSystem, String snapshotDirectory)
public void configurePrevalentSystem(P newPrevalentSystem)
newPrevalentSystem
- If the default Serializer is used, this prevalentSystem must be Serializable. If another Serializer is used, this prevalentSystem must be compatible with it.configureSnapshotSerializer(String, Serializer)
public void configurePrevalenceDirectory(String prevalenceDirectory)
prevalenceDirectory
- Will be ignored for the .snapshot files if a SnapshotManager is configured.public void configureTransactionDeepCopy(boolean transactionDeepCopyMode)
true
.
transactionDeepCopyMode
- false
, references passed in to transactions are used naturally, as they are during ordinary Java method calls, allowing their underlying objects to be changed inside transactions. However, any unrecoverable changes to the prevalent system and unrecoverable uses of reference equality inside transactions will not fail fast as they would upon recovery.
true
(default), a deep copy of the transaction is executed each time. This allows any unrecoverable changes to the prevalent system and unrecoverable uses of reference equality inside transactions to fail fast as they would upon recovery. However, it only allows changes to deep copies of the objects passed in, not the original objects.public void configureClock(Clock clock)
public void configureMonitor(Monitor monitor)
monitor
- the Monitor implementation to use.SimpleMonitor
public void configureTransientMode(boolean transientMode)
false
(persistent).
transientMode
- true
, a "transient" Prevayler will be created, which 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.
false
(default), a persistent Prevayler will be created.public void configureReplicationClient(String remoteServerIpAddress, int remoteServerPort)
public void configureReplicationServer(int port)
public void configureJournalFileSizeThreshold(long sizeInBytes)
public void configureJournalFileAgeThreshold(long ageInMilliseconds)
public void configureJournalDiskSync(boolean journalDiskSync)
true
.
journalDiskSync
- false
, transactions may execute without necessarily being written to the
physical disk. Transactions are still flushed to the operating system before being
executed, but FileDescriptor.sync() is never called. This increases transaction
throughput dramatically, but allows transactions to be lost if the system
does not shut down cleanly. Calling Prevayler.close()
will close the
underlying journal file and therefore cause all transactions to be written to
disk.
true
(default), every transaction is forced to be written to the
physical disk before it is executed (using FileDescriptor.sync()
).
(Many transactions may be written at once, but no transaction will be executed
before it is written to disk.)public void configureJournalSerializer(JavaSerializer serializer)
public void configureJournalSerializer(XStreamSerializer serializer)
public void configureJournalSerializer(String suffix, Serializer serializer)
public void configureSnapshotSerializer(JavaSerializer serializer)
public void configureSnapshotSerializer(XStreamSerializer serializer)
public void configureSnapshotSerializer(String suffix, Serializer serializer)
public Prevayler<P> create() throws Exception
IOException
- If there is trouble creating the Prevalence Base directory or reading a .journal or .snapshot file.
ClassNotFoundException
- If a class of a serialized Object is not found when reading a .journal or .snapshot file.
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |