acid-state-0.3: Add ACID guarantees to any serializable Haskell data structure.




Low-level controls for transaction-based state changes. This module defines structures and tools for running state modifiers indexed either by an Method or a serialized Method. This module should rarely be used directly although the Method class is needed when defining events manually.

The term 'Event' is loosely used for transactions with ACID guarantees. 'Method' is loosely used for state operations without ACID guarantees



data Core st Source

The control structure at the very center of acid-state. This module provides access to a mutable state through methods. No efforts towards durability, checkpointing or sharding happens at this level. Important things to keep in mind in this module: * We don't distinguish between updates and queries. * We allow direct access to the core state as well as through events.

class (Typeable ev, Binary ev, Typeable (MethodResult ev), Binary (MethodResult ev)) => Method ev whereSource

The basic Method class. Each Method has an indexed result type and a unique tag.

Associated Types

type MethodResult ev Source

type MethodState ev Source


methodTag :: ev -> TagSource

data MethodContainer st whereSource

Method container structure that hides the exact type of the method.


Method :: Method method => (method -> State (MethodState method) (MethodResult method)) -> MethodContainer (MethodState method) 

type Tagged a = (Tag, a)Source



:: [MethodContainer st]

List of methods capable of modifying the state.

-> st

Initial state value.

-> IO (Core st) 

Construct a new Core using an initial state and a list of Methods.

closeCore :: Core st -> IO ()Source

Mark Core as closed. Any subsequent use will throw an exception.

modifyCoreState :: Core st -> (st -> IO (st, a)) -> IO aSource

Modify the state component. The resulting state is ensured to be in WHNF.

modifyCoreState_ :: Core st -> (st -> IO st) -> IO ()Source

Modify the state component. The resulting state is ensured to be in WHNF.

withCoreState :: Core st -> (st -> IO a) -> IO aSource

Access the state component.

lookupHotMethod :: Method method => Core (MethodState method) -> method -> State (MethodState method) (MethodResult method)Source

Find the state action that corresponds to an in-memory method.

lookupColdMethod :: Core st -> Tagged ByteString -> State st ByteStringSource

Find the state action that corresponds to a tagged and serialized method.

runHotMethod :: Method method => Core (MethodState method) -> method -> IO (MethodResult method)Source

Apply an in-memory method to the state.

runColdMethod :: Core st -> Tagged ByteString -> IO ByteStringSource

Execute a method as given by a type identifier and an encoded string. The exact format of the encoded string depends on the type identifier. Results are encoded and type tagged before they're handed back out. This function is used when running events from a log-file or from another server. Events that originate locally are most likely executed with the faster runHotMethod.