Portability | portable |
---|---|
Maintainer | lemmih@gmail.com |
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
- class (Typeable ev, Binary ev, Typeable (MethodResult ev), Binary (MethodResult ev)) => Method ev where
- type MethodResult ev
- methodTag :: ev -> Tag
- data MethodContainer st where
- Method :: Method method => (method -> State st (MethodResult method)) -> MethodContainer st
- type Tagged a = (Tag, a)
- mkCore :: [MethodContainer st] -> st -> IO (Core st)
- closeCore :: Core st -> IO ()
- modifyCoreState :: Core st -> (st -> IO (st, a)) -> IO a
- modifyCoreState_ :: Core st -> (st -> IO st) -> IO ()
- withCoreState :: Core st -> (st -> IO a) -> IO a
- lookupHotMethod :: Method method => Core st -> method -> State st (MethodResult method)
- lookupColdMethod :: Core st -> Tagged ByteString -> State st ByteString
- runHotMethod :: Method method => Core st -> method -> IO (MethodResult method)
- runColdMethod :: Core st -> Tagged ByteString -> IO ByteString
Documentation
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.
type MethodResult ev Source
data MethodContainer st whereSource
Method container structure that hides the exact type of the method.
Method :: Method method => (method -> State st (MethodResult method)) -> MethodContainer st |
:: [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.
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 st -> method -> State st (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 st -> 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
.