packages feed

distributed-process-simplelocalnet 0.2.0.4 → 0.2.0.5

raw patch · 2 files changed

+33/−10 lines, 2 filesdep ~distributed-processPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: distributed-process

API changes (from Hackage documentation)

Files

distributed-process-simplelocalnet.cabal view
@@ -1,5 +1,5 @@ Name:          distributed-process-simplelocalnet-Version:       0.2.0.4+Version:       0.2.0.5 Cabal-Version: >=1.8 Build-Type:    Simple License:       BSD3 @@ -56,7 +56,7 @@                      transformers >= 0.2 && < 0.4,                      network-transport >= 0.2 && < 0.3,                      network-transport-tcp >= 0.2 && < 0.3,-                     distributed-process >= 0.2 && < 0.3+                     distributed-process >= 0.2 && < 0.4   Extensions:        RankNTypes,                      DeriveDataTypeable   ghc-options:       -Wall -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind 
src/Control/Distributed/Process/Backend/SimpleLocalnet.hs view
@@ -97,7 +97,7 @@ import Data.Typeable (Typeable) import Control.Applicative ((<$>)) import Control.Exception (throw)-import Control.Monad (forever, forM)+import Control.Monad (forever, forM, replicateM) import Control.Monad.IO.Class (liftIO) import Control.Concurrent (forkIO, threadDelay, ThreadId) import Control.Concurrent.MVar (MVar, newMVar, readMVar, modifyMVar_)@@ -114,8 +114,12 @@   , expect   , nsendRemote   , receiveWait+  , match   , matchIf   , processNodeId+  , monitorNode+  , unmonitor+  , NodeMonitorNotification(..)   ) import qualified Control.Distributed.Process.Node as Node    ( LocalNode@@ -286,12 +290,24 @@ findSlaves backend = do   nodes <- liftIO $ findPeers backend 1000000      -- Fire of asynchronous requests for the slave controller-  forM_ nodes $ \nid -> whereisRemoteAsync nid "slaveController" +  refs <- forM nodes $ \nid -> do+    whereisRemoteAsync nid "slaveController" +    ref <- monitorNode nid+    return (nid, ref)   -- Wait for the replies-  catMaybes <$> forM nodes (\_ -> +  catMaybes <$> replicateM (length nodes) (      receiveWait        [ matchIf (\(WhereIsReply label _) -> label == "slaveController")-                (\(WhereIsReply _ mPid) -> return (processNodeId <$> mPid))+                (\(WhereIsReply _ mPid) -> +                  case mPid of+                    Nothing -> +                      return Nothing+                    Just pid -> do+                      let nid      = processNodeId pid+                          Just ref = lookup nid refs+                      unmonitor ref +                      return (Just nid))+      , match (\(NodeMonitorNotification {}) -> return Nothing)        ])  -- | Terminate all slaves@@ -305,14 +321,21 @@ -- Master nodes -------------------------------------------------------------------------------- --- | 'startMaster' finds all slaves currently available on the local network--- (which should therefore be started first), redirects all log messages to--- itself, and then calls the specified process, passing the list of slaves--- nodes. +-- | 'startMaster' finds all slaves /currently/ available on the local network,+-- redirects all log messages to itself, and then calls the specified process,+-- passing the list of slaves nodes.  -- -- Terminates when the specified process terminates. If you want to terminate -- the slaves when the master terminates, you should manually call  -- 'terminateAllSlaves'.+--+-- If you start more slave nodes after having started the master node, you can+-- discover them with later calls to 'findSlaves', but be aware that you will+-- need to call 'redirectLogHere' to redirect their logs to the master node.  +--+-- Note that you can use functionality of "SimpleLocalnet" directly (through+-- 'Backend'), instead of using 'startMaster'/'startSlave', if the master/slave+-- distinction does not suit your application. startMaster :: Backend -> ([NodeId] -> Process ()) -> IO () startMaster backend proc = do   node <- newLocalNode backend