Safe Haskell | Safe-Infered |
---|
Simple backend based on the TCP transport which offers node discovery based on UDP multicast. This is a zero-configuration backend designed to get you going with Cloud Haskell quickly without imposing any structure on your application.
To simplify getting started we provide special support for master and
slave nodes (see startSlave
and startMaster
). Use of these functions
is completely optional; you can use the local backend without making use
of the predefined master and slave nodes.
- Minimal example
import System.Environment (getArgs) import Control.Distributed.Process import Control.Distributed.Process.Node (initRemoteTable) import Control.Distributed.Process.Backend.Local master :: Backend -> [NodeId] -> Process () master backend slaves = do -- Do something interesting with the slaves liftIO . putStrLn $ "Slaves: " ++ show slaves -- Terminate the slaves when the master terminates (this is optional) terminateAllSlaves backend main :: IO () main = do args <- getArgs case args of ["master", host, port] -> do backend <- initializeBackend host port initRemoteTable startMaster backend (master backend) ["slave", host, port] -> do backend <- initializeBackend host port initRemoteTable startSlave backend
- data Backend = Backend {
- newLocalNode :: IO LocalNode
- findPeers :: Int -> IO [NodeId]
- redirectLogsHere :: Process ()
- initializeBackend :: HostName -> ServiceName -> RemoteTable -> IO Backend
- startSlave :: Backend -> IO ()
- terminateSlave :: NodeId -> Process ()
- findSlaves :: Backend -> Process [NodeId]
- terminateAllSlaves :: Backend -> Process ()
- startMaster :: Backend -> ([NodeId] -> Process ()) -> IO ()
Initialization
Local backend
Backend | |
|
initializeBackend :: HostName -> ServiceName -> RemoteTable -> IO BackendSource
Initialize the backend
Slave nodes
startSlave :: Backend -> IO ()Source
Calling slave
sets up a new local node and then waits. You start
processes on the slave by calling spawn
from other nodes.
This function does not return. The only way to exit the slave is to CTRL-C the process or call terminateSlave from another node.
terminateSlave :: NodeId -> Process ()Source
Terminate the slave at the given node ID
findSlaves :: Backend -> Process [NodeId]Source
Find slave nodes
terminateAllSlaves :: Backend -> Process ()Source
Terminate all slaves
Master nodes
startMaster :: Backend -> ([NodeId] -> Process ()) -> IO ()Source
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.
Terminates when the specified process terminates. If you want to terminate
the slaves when the master terminates, you should manually call
terminateAllSlaves
.