@@ -9,7 +9,7 @@ module Control.Distributed.Process.Node
11import Prelude hiding (catch)
11import Prelude hiding (catch)
12−import System.IO (fixIO)
12+import System.IO (fixIO, hPutStrLn, stderr)
13import qualified Data.ByteString.Lazy as BSL (fromChunks)
13import qualified Data.ByteString.Lazy as BSL (fromChunks)
14import Data.Binary (decode)
14import Data.Binary (decode)
15import Data.Map (Map)
15import Data.Map (Map)
@@ -120,6 +120,7 @@ import Control.Distributed.Process.Internal.Closure
120 , resolveClosure
120 , resolveClosure
122import Control.Distributed.Process.Internal.Node (runLocalProcess)
122import Control.Distributed.Process.Internal.Node (runLocalProcess)
123+import Control.Distributed.Process.Internal.Primitives (expect, register)
124--------------------------------------------------------------------------------
125--------------------------------------------------------------------------------
125-- Initialization --
126-- Initialization --
@@ -131,26 +132,42 @@ import Control.Distributed.Process.Internal.Node (runLocalProcess)
132newLocalNode :: NT.Transport -> RemoteTable -> IO LocalNode
133newLocalNode :: NT.Transport -> RemoteTable -> IO LocalNode
133newLocalNode transport rtable = do
134newLocalNode transport rtable = do
134− mEndPoint <- NT.newEndPoint transport
135+ mEndPoint <- NT.newEndPoint transport
135− case mEndPoint of
136+ case mEndPoint of
136− Left ex -> throwIO ex
137+ Left ex -> throwIO ex
137− Right endPoint -> do
138+ Right endPoint -> do
139+ localNode <- createBareLocalNode endPoint rtable
140+ startServiceProcesses localNode
143+-- | Create a new local node (without any service processes running)
144+createBareLocalNode :: NT.EndPoint -> RemoteTable -> IO LocalNode
145+createBareLocalNode endPoint rtable = do
138− unq <- randomIO
146+ unq <- randomIO
139− state <- newMVar LocalNodeState
147+ state <- newMVar LocalNodeState
140− { _localProcesses = Map.empty
148+ { _localProcesses = Map.empty
141− , _localPidCounter = 0
149+ , _localPidCounter = 0
142− , _localPidUnique = unq
150+ , _localPidUnique = unq
144− ctrlChan <- newChan
152+ ctrlChan <- newChan
145− let node = LocalNode { localNodeId = NodeId $ NT.address endPoint
153+ let node = LocalNode { localNodeId = NodeId $ NT.address endPoint
146− , localEndPoint = endPoint
154+ , localEndPoint = endPoint
147− , localState = state
155+ , localState = state
148− , localCtrlChan = ctrlChan
156+ , localCtrlChan = ctrlChan
149− , remoteTable = rtable
157+ , remoteTable = rtable
151− void . forkIO $ runNodeController node
159+ void . forkIO $ runNodeController node
152− void . forkIO $ handleIncomingMessages node
160+ void . forkIO $ handleIncomingMessages node
153− return node
161+ return node
163+-- | Start and register the service processes on a node
164+-- (for now, this is only the logger)
165+startServiceProcesses :: LocalNode -> IO ()
166+startServiceProcesses node = do
167+ logger <- forkProcess node . forever $ do
168+ (time, pid, string) <- expect :: Process (String, ProcessId, String)
169+ liftIO . hPutStrLn stderr $ time ++ " " ++ show pid ++ ": " ++ string
170+ runProcess node $ register "logger" logger
155-- | Force-close a local node
172-- | Force-close a local node