-
Notifications
You must be signed in to change notification settings - Fork 104
/
DistribUtils.hs
41 lines (35 loc) · 1.32 KB
/
DistribUtils.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{-# LANGUAGE TemplateHaskell #-}
module DistribUtils ( distribMain ) where
import Control.Distributed.Process
import Control.Distributed.Process.Closure
import Control.Distributed.Process.Node (initRemoteTable)
import Control.Distributed.Process.Backend.SimpleLocalnet
import Control.Distributed.Static hiding (initRemoteTable)
import System.Environment
import Network.Socket hiding (shutdown)
import Language.Haskell.TH
distribMain :: ([NodeId] -> Process ()) -> (RemoteTable -> RemoteTable) -> IO ()
distribMain master frtable = do
args <- getArgs
let rtable = frtable initRemoteTable
case args of
[] -> do
backend <- initializeBackend defaultHost defaultPort rtable
startMaster backend master
[ "master" ] -> do
backend <- initializeBackend defaultHost defaultPort rtable
startMaster backend master
[ "master", port ] -> do
backend <- initializeBackend defaultHost port rtable
startMaster backend master
[ "slave" ] -> do
backend <- initializeBackend defaultHost defaultPort rtable
startSlave backend
[ "slave", port ] -> do
backend <- initializeBackend defaultHost port rtable
startSlave backend
[ "slave", host, port ] -> do
backend <- initializeBackend host port rtable
startSlave backend
defaultHost = "localhost"
defaultPort = "44444"