C# Класс 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.

Наследование: System.MarshalByRefObject
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
_system object

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
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.

Приватные методы

Метод Описание
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

Описание методов

AssertNotPaused() публичный метод

public AssertNotPaused ( ) : void
Результат void

ExecuteCommand() публичный метод

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
Результат object

ExecuteQuery() публичный метод

Executes a query object against the prevalent system.
public ExecuteQuery ( Bamboo query ) : object
query Bamboo the query object
Результат object

HandsOffOutputLog() публичный метод

Closes the output log file so that it can be read/copied/deleted. Useful for testing.
public HandsOffOutputLog ( ) : void
Результат void

OnExceptionDuringRecovery() защищенный метод

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
Результат void

Pause() публичный метод

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
Результат void

Resume() публичный метод

Resumes the normal operations of the engine.
public Resume ( ) : void
Результат void

TakeSnapshot() публичный метод

Writes a snapshot of the current state of the system to disk to speed up the next start up.
public TakeSnapshot ( ) : void
Результат void

Описание свойств

_system защищенное свойство

the prevalent system.
protected object _system
Результат object