@@ -15,7 +15,7 @@
15-- > import Control.Distributed.Process.Node (initRemoteTable)
15-- > import Control.Distributed.Process.Node (initRemoteTable)
16-- > import Control.Distributed.Process.Backend.Local
16-- > import Control.Distributed.Process.Backend.Local
18−-- > master :: LocalBackend -> [NodeId] -> Process ()
18+-- > master :: Backend -> [NodeId] -> Process ()
19-- > master backend slaves = do
19-- > master backend slaves = do
20-- > -- Do something interesting with the slaves
20-- > -- Do something interesting with the slaves
21-- > liftIO . putStrLn $ "Slaves: " ++ show slaves
21-- > liftIO . putStrLn $ "Slaves: " ++ show slaves
@@ -34,9 +34,9 @@
34-- > backend <- initializeBackend host port initRemoteTable
34-- > backend <- initializeBackend host port initRemoteTable
35-- > startSlave backend
35-- > startSlave backend
36{-# OPTIONS_GHC -fno-warn-orphans #-}
36{-# OPTIONS_GHC -fno-warn-orphans #-}
37−module Control.Distributed.Process.Backend.Local
37+module Control.Distributed.Process.Backend.SimpleLocalnet
38 ( -- * Initialization
38 ( -- * Initialization
39− LocalBackend(..)
39+ Backend(..)
40 , initializeBackend
40 , initializeBackend
41 -- * Slave nodes
41 -- * Slave nodes
42 , startSlave
42 , startSlave
@@ -89,10 +89,10 @@ import qualified Network.Transport.TCP as NT
90import qualified Network.Transport as NT (Transport)
90import qualified Network.Transport as NT (Transport)
91import qualified Network.Socket as N (HostName, ServiceName, SockAddr)
91import qualified Network.Socket as N (HostName, ServiceName, SockAddr)
92−import Control.Distributed.Process.Internal.Multicast (initMulticast)
92+import Control.Distributed.Process.Backend.SimpleLocalnet.Internal.Multicast (initMulticast)
94-- | Local backend
94-- | Local backend
95−data LocalBackend = LocalBackend {
95+data Backend = Backend {
96 -- | Create a new local node
96 -- | Create a new local node
97 newLocalNode :: IO Node.LocalNode
97 newLocalNode :: IO Node.LocalNode
98 -- | @findPeers t@ sends out a /who's there?/ request, waits 't' msec,
98 -- | @findPeers t@ sends out a /who's there?/ request, waits 't' msec,
@@ -103,19 +103,19 @@ data LocalBackend = LocalBackend {
103 , redirectLogsHere :: Process ()
103 , redirectLogsHere :: Process ()
106−data LocalBackendState = LocalBackendState {
106+data BackendState = BackendState {
107 _localNodes :: [Node.LocalNode]
107 _localNodes :: [Node.LocalNode]
108 , _peers :: Set NodeId
108 , _peers :: Set NodeId
109 , discoveryDaemon :: ThreadId
109 , discoveryDaemon :: ThreadId
112-- | Initialize the backend
112-- | Initialize the backend
113−initializeBackend :: N.HostName -> N.ServiceName -> RemoteTable -> IO LocalBackend
113+initializeBackend :: N.HostName -> N.ServiceName -> RemoteTable -> IO Backend
114initializeBackend host port rtable = do
114initializeBackend host port rtable = do
115 mTransport <- NT.createTransport host port NT.defaultTCPParameters
115 mTransport <- NT.createTransport host port NT.defaultTCPParameters
116 (recv, send) <- initMulticast "224.0.0.99" 9999 1024
116 (recv, send) <- initMulticast "224.0.0.99" 9999 1024
117 (_, backendState) <- fixIO $ \ ~(tid, _) -> do
117 (_, backendState) <- fixIO $ \ ~(tid, _) -> do
118− backendState <- newMVar LocalBackendState
118+ backendState <- newMVar BackendState
119 { _localNodes = []
119 { _localNodes = []
120 , _peers = Set.empty
120 , _peers = Set.empty
121 , discoveryDaemon = tid
121 , discoveryDaemon = tid
@@ -125,7 +125,7 @@ initializeBackend host port rtable = do
125 case mTransport of
125 case mTransport of
126 Left err -> throw err
126 Left err -> throw err
127 Right transport ->
127 Right transport ->
128− let backend = LocalBackend {
128+ let backend = Backend {
129 newLocalNode = apiNewLocalNode transport rtable backendState
129 newLocalNode = apiNewLocalNode transport rtable backendState
130 , findPeers = apiFindPeers send backendState
130 , findPeers = apiFindPeers send backendState
131 , redirectLogsHere = apiRedirectLogsHere backend
131 , redirectLogsHere = apiRedirectLogsHere backend
@@ -135,7 +135,7 @@ initializeBackend host port rtable = do
135-- | Create a new local node
135-- | Create a new local node
136apiNewLocalNode :: NT.Transport
136apiNewLocalNode :: NT.Transport
137 -> RemoteTable
137 -> RemoteTable
138− -> MVar LocalBackendState
138+ -> MVar BackendState
139 -> IO Node.LocalNode
139 -> IO Node.LocalNode
140apiNewLocalNode transport rtable backendState = do
140apiNewLocalNode transport rtable backendState = do
141 localNode <- Node.newLocalNode transport rtable
141 localNode <- Node.newLocalNode transport rtable
@@ -144,7 +144,7 @@ apiNewLocalNode transport rtable backendState = do
145-- | Peer discovery
145-- | Peer discovery
146apiFindPeers :: (PeerDiscoveryMsg -> IO ())
146apiFindPeers :: (PeerDiscoveryMsg -> IO ())
147− -> MVar LocalBackendState
147+ -> MVar BackendState
149 -> IO [NodeId]
149 -> IO [NodeId]
150apiFindPeers send backendState delay = do
150apiFindPeers send backendState delay = do
@@ -167,7 +167,7 @@ instance Binary PeerDiscoveryMsg where
167 _ -> fail "PeerDiscoveryMsg.get: invalid"
167 _ -> fail "PeerDiscoveryMsg.get: invalid"
169-- | Respond to peer discovery requests sent by other nodes
169-- | Respond to peer discovery requests sent by other nodes
170−peerDiscoveryDaemon :: MVar LocalBackendState
170+peerDiscoveryDaemon :: MVar BackendState
171 -> IO (PeerDiscoveryMsg, N.SockAddr)
171 -> IO (PeerDiscoveryMsg, N.SockAddr)
172 -> (PeerDiscoveryMsg -> IO ())
172 -> (PeerDiscoveryMsg -> IO ())
@@ -187,7 +187,7 @@ peerDiscoveryDaemon backendState recv send = forever go
187--------------------------------------------------------------------------------
187--------------------------------------------------------------------------------
189-- | Make sure that all log messages are printed by the logger on this node
189-- | Make sure that all log messages are printed by the logger on this node
190−apiRedirectLogsHere :: LocalBackend -> Process ()
190+apiRedirectLogsHere :: Backend -> Process ()
191apiRedirectLogsHere backend = do
191apiRedirectLogsHere backend = do
192 mLogger <- whereis "logger"
192 mLogger <- whereis "logger"
193 forM_ mLogger $ \logger -> do
193 forM_ mLogger $ \logger -> do
@@ -219,7 +219,7 @@ instance Binary SlaveControllerMsg where
220-- This function does not return. The only way to exit the slave is to CTRL-C
220-- This function does not return. The only way to exit the slave is to CTRL-C
221-- the process or call terminateSlave from another node.
221-- the process or call terminateSlave from another node.
222−startSlave :: LocalBackend -> IO ()
222+startSlave :: Backend -> IO ()
223startSlave backend = do
223startSlave backend = do
224 node <- newLocalNode backend
224 node <- newLocalNode backend
225 Node.runProcess node slaveController
225 Node.runProcess node slaveController
@@ -241,7 +241,7 @@ terminateSlave :: NodeId -> Process ()
241terminateSlave nid = nsendRemote nid "slaveController" SlaveTerminate
241terminateSlave nid = nsendRemote nid "slaveController" SlaveTerminate
243-- | Find slave nodes
243-- | Find slave nodes
244−findSlaves :: LocalBackend -> Process [NodeId]
244+findSlaves :: Backend -> Process [NodeId]
245findSlaves backend = do
245findSlaves backend = do
246 nodes <- liftIO $ findPeers backend 1000000
246 nodes <- liftIO $ findPeers backend 1000000
247 -- Fire of asynchronous requests for the slave controller
247 -- Fire of asynchronous requests for the slave controller
@@ -254,7 +254,7 @@ findSlaves backend = do
256-- | Terminate all slaves
256-- | Terminate all slaves
257−terminateAllSlaves :: LocalBackend -> Process ()
257+terminateAllSlaves :: Backend -> Process ()
258terminateAllSlaves backend = do
258terminateAllSlaves backend = do
259 slaves <- findSlaves backend
259 slaves <- findSlaves backend
260 forM_ slaves terminateSlave
260 forM_ slaves terminateSlave
@@ -272,7 +272,7 @@ terminateAllSlaves backend = do
272-- Terminates when the specified process terminates. If you want to terminate
272-- Terminates when the specified process terminates. If you want to terminate
273-- the slaves when the master terminates, you should manually call
273-- the slaves when the master terminates, you should manually call
274-- 'terminateAllSlaves'.
274-- 'terminateAllSlaves'.
275−startMaster :: LocalBackend -> ([NodeId] -> Process ()) -> IO ()
275+startMaster :: Backend -> ([NodeId] -> Process ()) -> IO ()
276startMaster backend proc = do
276startMaster backend proc = do
277 node <- newLocalNode backend
277 node <- newLocalNode backend
278 Node.runProcess node $ do
278 Node.runProcess node $ do
@@ -284,8 +284,8 @@ startMaster backend proc = do
284-- Accessors --
284-- Accessors --
285--------------------------------------------------------------------------------
285--------------------------------------------------------------------------------
287−localNodes :: Accessor LocalBackendState [Node.LocalNode]
287+localNodes :: Accessor BackendState [Node.LocalNode]
288localNodes = accessor _localNodes (\ns st -> st { _localNodes = ns })
288localNodes = accessor _localNodes (\ns st -> st { _localNodes = ns })
290−peers :: Accessor LocalBackendState (Set NodeId)
290+peers :: Accessor BackendState (Set NodeId)
291peers = accessor _peers (\ps st -> st { _peers = ps })
291peers = accessor _peers (\ps st -> st { _peers = ps })