legion 0.3.0.0 → 0.4.0.0
raw patch · 4 files changed
+45/−45 lines, 4 files
Files
- legion.cabal +1/−1
- src/Network/Legion.hs +23/−18
- src/Network/Legion/Runtime.hs +16/−17
- src/Network/Legion/Settings.hs +5/−9
legion.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: legion-version: 0.3.0.0+version: 0.4.0.0 synopsis: Distributed, stateful, homogeneous microservice framework. description: Legion is a framework for writing distributed, homogeneous, stateful microservices in Haskell.
src/Network/Legion.hs view
@@ -23,34 +23,39 @@ -} module Network.Legion (- -- * Service Implementation+ -- * Using Legion++ -- ** Starting the Legion Runtime+ -- $startup+ forkLegionary,+ StartupMode(..),+ Runtime,++ -- ** Runtime Configuration+ -- $framework-config+ RuntimeSettings(..),++ -- ** Making Runtime Requests+ makeRequest,+ search,++ -- * Implementing a Legion Application -- $service-implementaiton -- ** Indexing -- $indexing- Legionary(..), LegionConstraints, Persistence(..), ApplyDelta(..), Tag(..),- -- * Invoking Legion- -- $invocation- forkLegionary,- StartupMode(..),- Runtime,- makeRequest,- search,++ -- * Other Types SearchTag(..), IndexRecord(..),- -- * Fundamental Types PartitionKey(..), PartitionPowerState,- projected,- infimum,- -- * Framework Configuration- -- $framework-config- LegionarySettings(..),+ -- * Utils newMemoryPersistence, diskPersistence,@@ -65,11 +70,11 @@ import Network.Legion.Index (Tag(Tag, unTag), IndexRecord(IndexRecord, irTag, irKey), SearchTag(SearchTag, stTag, stKey)) import Network.Legion.PartitionKey (PartitionKey(K, unKey))-import Network.Legion.PartitionState (PartitionPowerState, infimum, projected)+import Network.Legion.PartitionState (PartitionPowerState) import Network.Legion.PowerState (ApplyDelta(apply)) import Network.Legion.Runtime (StartupMode(NewCluster, JoinCluster), forkLegionary, Runtime, makeRequest, search)-import Network.Legion.Settings (LegionarySettings(LegionarySettings,+import Network.Legion.Settings (RuntimeSettings(RuntimeSettings, adminHost, adminPort, peerBindAddr, joinBindAddr)) --------------------------------------------------------------------------------@@ -187,7 +192,7 @@ -------------------------------------------------------------------------------- --- $invocation+-- $startup -- While this section is being worked on, you can check out the -- [legion-cache](https://github.com/taphu/legion-cache) project for a -- working example of how to build a basic distributed key-value store
src/Network/Legion/Runtime.hs view
@@ -54,7 +54,7 @@ PeerMessagePayload(ForwardRequest, ForwardResponse, ClusterMerge, PartitionMerge, Search, SearchResponse), MessageId, newSequence, nextMessageId)-import Network.Legion.Settings (LegionarySettings(LegionarySettings,+import Network.Legion.Settings (RuntimeSettings(RuntimeSettings, adminHost, adminPort, peerBindAddr, joinBindAddr)) import Network.Legion.StateMachine (partitionMerge, clusterMerge, NodeState, newNodeState, runSM, UserResponse(Forward, Respond),@@ -86,7 +86,7 @@ runLegionary :: (LegionConstraints i o s) => Legionary i o s {- ^ The user-defined legion application to run. -}- -> LegionarySettings+ -> RuntimeSettings {- ^ Settings and configuration of the legionary framework. -} -> StartupMode -> Source IO (RequestMsg i o)@@ -99,7 +99,7 @@ runLegionary legionary- settings@LegionarySettings {adminHost, adminPort}+ settings@RuntimeSettings {adminHost, adminPort} startupMode requestSource = do@@ -422,9 +422,9 @@ where {- | Figure out which index record returned to us by the various peers- is the most appropriate to return. This is mostly like 'min' but- we can't use 'min' (or fancy applicative formulations) because we- want to favor 'Just' instead of 'Nothing'.+ is the most appropriate to return to the user. This is mostly like+ 'min' but we can't use 'min' (or fancy applicative formulations)+ because we want to favor 'Just' instead of 'Nothing'. -} bestOf :: Maybe IndexRecord -> Maybe IndexRecord -> Maybe IndexRecord bestOf (Just a) (Just b) = Just (min a b)@@ -511,10 +511,10 @@ @Source LIO PeerMessage@. -} startPeerListener :: (LegionConstraints i o s)- => LegionarySettings+ => RuntimeSettings -> LIO (Source LIO (PeerMessage i o s)) -startPeerListener LegionarySettings {peerBindAddr} =+startPeerListener RuntimeSettings {peerBindAddr} = catchAll (do (inputChan, so) <- lift $ do inputChan <- newChan@@ -574,11 +574,11 @@ {- | Figure out how to construct the initial node state. -} makeNodeState :: (Show i)- => LegionarySettings+ => RuntimeSettings -> StartupMode -> LIO (Peer, NodeState i s, Map Peer BSockAddr) -makeNodeState LegionarySettings {peerBindAddr} NewCluster = do+makeNodeState RuntimeSettings {peerBindAddr} NewCluster = do {- Build a brand new node state, for the first node in a cluster. -} self <- newPeer clusterId <- getUUID@@ -587,7 +587,7 @@ nodeState = newNodeState self cluster return (self, nodeState, C.getPeers cluster) -makeNodeState LegionarySettings {peerBindAddr} (JoinCluster addr) = do+makeNodeState RuntimeSettings {peerBindAddr} (JoinCluster addr) = do {- Join a cluster by either starting fresh, or recovering from a shutdown or crash.@@ -624,10 +624,10 @@ {- | A source of cluster join request messages. -} joinMsgSource- :: LegionarySettings+ :: RuntimeSettings -> Source LIO (JoinRequest, JoinResponse -> LIO ()) -joinMsgSource LegionarySettings {joinBindAddr} = join . lift $+joinMsgSource RuntimeSettings {joinBindAddr} = join . lift $ catchAll (do (chan, so) <- lift $ do chan <- newChan@@ -700,7 +700,7 @@ forkLegionary :: (LegionConstraints i o s, MonadLoggerIO io) => Legionary i o s {- ^ The user-defined legion application to run. -}- -> LegionarySettings+ -> RuntimeSettings {- ^ Settings and configuration of the legionary framework. -} -> StartupMode -> io (Runtime i o)@@ -737,7 +737,7 @@ -} data Runtime i o = Runtime { {- |- Send your customized request to the legion runtime, and get back+ Send an application request to the legion runtime, and get back a response. -} rtMakeRequest :: PartitionKey -> i -> IO o,@@ -798,8 +798,7 @@ executing search. Whether this counts as a premature optimization hack or a beautifully elegant expression of platonic reality is left as an exercise for the reader. It does help simplify the code a little bit because we don't have- to specify some kind of UUID to identify otherwise identical searches.-+ to specify some kind of UUID to differentiate otherwise identical searches. -} data RuntimeState i o s = RuntimeState { self :: Peer,
src/Network/Legion/Settings.hs view
@@ -2,14 +2,14 @@ This module contains the user settings. -} module Network.Legion.Settings (- LegionarySettings(..),+ RuntimeSettings(..), ) where import Network.Socket (SockAddr) import Network.Wai.Handler.Warp (HostPreference, Port) -{- | Settings used when starting up the legion framework. -}-data LegionarySettings = LegionarySettings {+{- | Settings used when starting up the legion framework runtime. -}+data RuntimeSettings = RuntimeSettings { peerBindAddr :: SockAddr, {- ^ The address on which the legion framework will listen for@@ -21,13 +21,9 @@ join requests. -} adminHost :: HostPreference,- {- ^- The host address on which the admin service should run.- -}+ {- ^ The host address on which the admin service should run. -} adminPort :: Port- {- ^- The host port on which the admin service should run.- -}+ {- ^ The host port on which the admin service should run. -} }