C# Class Bamboo.Prevalence.PrevalenceEngine

Object prevalence engine. Provides transparent object persistence to deterministic systems.

The prevalent system class must be serializable and deterministic: two instances of the same class when exposed to the same set of commands and queries must reach the same final state and yield the same query results.

In order to be deterministic, the prevalent system class must use PrevalenceEngine.Clock or PrevalenceEngine.Now for all its date/time related functions.

Any change to the prevalent system must be represented by a serializable command object (ICommand) executed through ExecuteCommand.

Queries to the prevalent system are best implemented as query objects (IQuery) executed through ExecuteQuery.

The prevalence engine employs a reader/writer lock strategy to coordenate the work of command and query objects - that way multiple query objects are allowed to execute in paralell and command objects are only allowed to execute one by one.

The great news is that if you design your prevalent system in such a way that its state is only manipulated and queried through command and query objects you don't have to worry about synchronization, to a simple example of such a system please refer to the Bamboo.Prevalence.Tests project.

Optionally, if you don't like the idea of designing your system around command and query objects and would rather use simple method calls onto your prevalent system class, take a look at PrevalenceActivator.CreateTransparentEngine or Bamboo.Prevalence.Attributes.TransparentPrevalenceAttribute.

Inheritance: System.MarshalByRefObject
Mostrar archivo Open project: bamboo/Bamboo.Prevalence Class Usage Examples

Protected Properties

Property Type Description
_system object

Public Methods

Method Description
AssertNotPaused ( ) : void
ExecuteCommand ( ICommand command ) : object

Executes a serializable command object. If the command throws an exception it WILL NOT be saved to the output log therefore any exception throwing command MUST NOT cause any change to the system state to occur.

ExecuteQuery ( Bamboo query ) : object

Executes a query object against the prevalent system.

HandsOffOutputLog ( ) : void

Closes the output log file so that it can be read/copied/deleted. Useful for testing.

Pause ( ) : void

Pauses the engine. When paused the engine will not accept any commands (ExecuteCommand will throw PausedEngineException instead). The engine never stops accepting queries. The engine will accept commands again after Resume.

Resume ( ) : void

Resumes the normal operations of the engine.

TakeSnapshot ( ) : void

Writes a snapshot of the current state of the system to disk to speed up the next start up.

Protected Methods

Method Description
OnExceptionDuringRecovery ( ExceptionDuringRecoveryHandler handler, ICommand command, Exception exception ) : void

Called whenever a exception is thrown by a command during recovery.
Notify the specified delegate of the exception.

Private Methods

Method Description
AcquireReaderLock ( ) : void
AcquireWriterLock ( ) : void
AfterQuery ( ) : void
ApplyCommandDecorators ( ICommand command ) : ICommand
BeforeQuery ( ) : void
CheckPrevalenceBase ( string prevalenceBase ) : DirectoryInfo
DoExecuteCommand ( ICommand command ) : object
GetCommandDecorators ( System systemType ) : ICommandDecorator[]
GetCurrent ( string methodName ) : PrevalenceEngine
PrevalenceEngine ( System systemType, string prevalenceBase, BinaryFormatter formatter ) : System

See PrevalenceActivator.CreateEngine(System.Type, string)

PrevalenceEngine ( System systemType, string prevalenceBase, BinaryFormatter formatter, ExceptionDuringRecoveryHandler handler ) : System

See PrevalenceActivator.CreateEngine(System.Type, string)

RecoverCommands ( Bamboo.Prevalence.Implementation.CommandLogReader reader, ExceptionDuringRecoveryHandler handler ) : void
RecoverSystem ( System systemType, Bamboo.Prevalence.Implementation.CommandLogReader reader, ExceptionDuringRecoveryHandler handler ) : void
ReleaseReaderLock ( ) : void
ReleaseWriterLock ( ) : void
ShareCurrentObject ( ) : void
UnshareCurrentObject ( ) : void

Method Details

AssertNotPaused() public method

public AssertNotPaused ( ) : void
return void

ExecuteCommand() public method

Executes a serializable command object. If the command throws an exception it WILL NOT be saved to the output log therefore any exception throwing command MUST NOT cause any change to the system state to occur.
when the engine
public ExecuteCommand ( ICommand command ) : object
command ICommand serializable command object that will be executed
return object

ExecuteQuery() public method

Executes a query object against the prevalent system.
public ExecuteQuery ( Bamboo query ) : object
query Bamboo the query object
return object

HandsOffOutputLog() public method

Closes the output log file so that it can be read/copied/deleted. Useful for testing.
public HandsOffOutputLog ( ) : void
return void

OnExceptionDuringRecovery() protected method

Called whenever a exception is thrown by a command during recovery.
Notify the specified delegate of the exception.
protected OnExceptionDuringRecovery ( ExceptionDuringRecoveryHandler handler, ICommand command, Exception exception ) : void
handler ExceptionDuringRecoveryHandler a delegate that should be notified of the exception
command ICommand commands that has thrown the exception
exception System.Exception the exception
return void

Pause() public method

Pauses the engine. When paused the engine will not accept any commands (ExecuteCommand will throw PausedEngineException instead). The engine never stops accepting queries. The engine will accept commands again after Resume.
public Pause ( ) : void
return void

Resume() public method

Resumes the normal operations of the engine.
public Resume ( ) : void
return void

TakeSnapshot() public method

Writes a snapshot of the current state of the system to disk to speed up the next start up.
public TakeSnapshot ( ) : void
return void

Property Details

_system protected_oe property

the prevalent system.
protected object _system
return object