org.prevayler.implementation
Class PrevaylerImpl<P>

java.lang.Object
  extended by org.prevayler.implementation.PrevaylerImpl<P>
All Implemented Interfaces:
Prevayler<P>

public class PrevaylerImpl<P>
extends Object
implements Prevayler<P>


Constructor Summary
PrevaylerImpl(GenericSnapshotManager<P> snapshotManager, TransactionPublisher transactionPublisher, Serializer journalSerializer, boolean transactionDeepCopyMode)
          Creates a new Prevayler
 
Method Summary
 Clock clock()
          Returns the Clock used to determine the execution time of all Transaction and Queries executed using this Prevayler.
 void close()
          Closes any files or other system resources opened by this Prevayler.
<R> R
execute(Query<? super P,R> sensitiveQuery)
          Executes the given sensitiveQuery on the prevalentSystem().
<R> R
execute(SureTransactionWithQuery<? super P,R> sureTransactionWithQuery)
          The same as execute(TransactionWithQuery) except no Exception is thrown.
 void execute(Transaction<? super P> transaction)
          Executes the given Transaction on the prevalentSystem().
<R> R
execute(TransactionWithQuery<? super P,R> transactionWithQuery)
          Executes the given transactionWithQuery on the prevalentSystem().
 P prevalentSystem()
          Returns the object which holds direct or indirect references to all other Business Objects in the system.
 File takeSnapshot()
          Produces a complete serialized image of the underlying PrevalentSystem.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrevaylerImpl

public PrevaylerImpl(GenericSnapshotManager<P> snapshotManager,
                     TransactionPublisher transactionPublisher,
                     Serializer journalSerializer,
                     boolean transactionDeepCopyMode)
              throws IOException,
                     ClassNotFoundException
Creates a new Prevayler

Parameters:
snapshotManager - The SnapshotManager that will be used for reading and writing snapshot files.
transactionPublisher - The TransactionPublisher that will be used for publishing transactions executed with this PrevaylerImpl.
journalSerializer -
Throws:
IOException
ClassNotFoundException
Method Detail

prevalentSystem

public P prevalentSystem()
Description copied from interface: Prevayler
Returns the object which holds direct or indirect references to all other Business Objects in the system.

Specified by:
prevalentSystem in interface Prevayler<P>

clock

public Clock clock()
Description copied from interface: Prevayler
Returns the Clock used to determine the execution time of all Transaction and Queries executed using this Prevayler. This Clock is useful only to Communication Objects and must NOT be used by Transactions, Queries or Business Objects, since that would make them become non-deterministic. Instead, Transactions, Queries and Business Objects must use the executionTime parameter which is passed on their execution.

Specified by:
clock in interface Prevayler<P>

execute

public void execute(Transaction<? super P> transaction)
Description copied from interface: Prevayler
Executes the given Transaction on the prevalentSystem(). ALL operations that alter the observable state of the prevalentSystem() must be implemented as Transaction or TransactionWithQuery objects and must be executed using the Prevayler.execute() methods. This method synchronizes on the prevalentSystem() to execute the Transaction. It is therefore guaranteed that only one Transaction is executed at a time. This means the prevalentSystem() does not have to worry about concurrency issues among Transactions. Implementations of this interface can log the given Transaction for crash or shutdown recovery, for example, or execute it remotely on replicas of the prevalentSystem() for fault-tolerance and load-balancing purposes.

Specified by:
execute in interface Prevayler<P>
See Also:
PrevaylerFactory

execute

public <R> R execute(Query<? super P,R> sensitiveQuery)
          throws Exception
Description copied from interface: Prevayler
Executes the given sensitiveQuery on the prevalentSystem(). A sensitiveQuery is a Query that would be affected by the concurrent execution of a Transaction or other sensitiveQuery. This method synchronizes on the prevalentSystem() to execute the sensitiveQuery. It is therefore guaranteed that no other Transaction or sensitiveQuery is executed at the same time.
Robust Queries (queries that do not affect other operations and that are not affected by them) can be executed directly as plain old method calls on the prevalentSystem() without the need of being implemented as Query objects. Examples of Robust Queries are queries that read the value of a single field or historical queries such as: "What was this account's balance at mid-night?".

Specified by:
execute in interface Prevayler<P>
Returns:
The result returned by the execution of the sensitiveQuery on the prevalentSystem().
Throws:
Exception - The Exception thrown by the execution of the sensitiveQuery on the prevalentSystem().

execute

public <R> R execute(TransactionWithQuery<? super P,R> transactionWithQuery)
          throws Exception
Description copied from interface: Prevayler
Executes the given transactionWithQuery on the prevalentSystem(). Implementations of this interface can log the given transaction for crash or shutdown recovery, for example, or execute it remotely on replicas of the prevalentSystem() for fault-tolerance and load-balancing purposes.

Specified by:
execute in interface Prevayler<P>
Returns:
The result returned by the execution of the transactionWithQuery on the prevalentSystem().
Throws:
Exception - The Exception thrown by the execution of the sensitiveQuery on the prevalentSystem().
See Also:
PrevaylerFactory

execute

public <R> R execute(SureTransactionWithQuery<? super P,R> sureTransactionWithQuery)
Description copied from interface: Prevayler
The same as execute(TransactionWithQuery) except no Exception is thrown.

Specified by:
execute in interface Prevayler<P>
Returns:
The result returned by the execution of the sureTransactionWithQuery on the prevalentSystem().

takeSnapshot

public File takeSnapshot()
                  throws Exception
Description copied from interface: Prevayler
Produces a complete serialized image of the underlying PrevalentSystem. This will accelerate future system startups. Taking a snapshot once a day is enough for most applications. This method synchronizes on the prevalentSystem() in order to take the snapshot. This means that transaction execution will be blocked while the snapshot is taken.

Specified by:
takeSnapshot in interface Prevayler<P>
Returns:
The file to which the snapshot was written. This file should be left where it is, so that Prevayler can read it during startup. You can copy it to another location for backup purposes if desired.
Throws:
Exception - if there is trouble writing to the snapshot file or serializing the prevalent system.

close

public void close()
           throws IOException
Description copied from interface: Prevayler
Closes any files or other system resources opened by this Prevayler.

Specified by:
close in interface Prevayler<P>
Throws:
IOException - if there is trouble closing a file or some other system resource.


Copyright © 2001-2013. All Rights Reserved.