1module Control.Distributed.Process.Internal.Messaging
6 , closeImplicitReconnections
10import Data.Accessor ((^.), (^=))
11import Data.Binary (Binary, encode)
12import qualified Data.Map as Map (partitionWithKey, elems)
13import qualified Data.ByteString.Lazy as BSL (toChunks)
14import qualified Data.ByteString as BSS (ByteString)
15import Control.Distributed.Process.Internal.StrictMVar (withMVar, modifyMVar_)
16import Control.Concurrent.Chan (writeChan)
17import Control.Monad (unless)
18import qualified Network.Transport as NT
23 , Reliability(ReliableOrdered)
26import Control.Distributed.Process.Internal.Types
27 ( LocalNode(localState, localEndPoint, localCtrlChan)
30 , localConnectionBetween
37 , DiedReason(DiedDisconnect)
38 , ImplicitReconnect(WithImplicitReconnect)
40 , ProcessId(processNodeId)
41 , SendPortId(sendPortProcessId)
42 , Identifier(NodeIdentifier, ProcessIdentifier, SendPortIdentifier)
44import Control.Distributed.Process.Serializable (Serializable)
46--------------------------------------------------------------------------------
48--------------------------------------------------------------------------------
50sendPayload :: LocalNode
56sendPayload node from to implicitReconnect payload = do
57 mConn <- connBetween node from to implicitReconnect
58 didSend <- case mConn of
60 didSend <- NT.send conn payload
62 Left _err -> return False
63 Right () -> return True
64 Nothing -> return False
66 writeChan (localCtrlChan node) NCMsg
68 , ctrlMsgSignal = Died to DiedDisconnect
78sendBinary node from to implicitReconnect
79 = sendPayload node from to implicitReconnect . BSL.toChunks . encode
81sendMessage :: Serializable a
88sendMessage node from to implicitReconnect =
89 sendPayload node from to implicitReconnect . messageToPayload . createMessage
91setupConnBetween :: LocalNode
95 -> IO (Maybe NT.Connection)
96setupConnBetween node from to implicitReconnect = do
97 mConn <- NT.connect endPoint
98 (nodeAddress . nodeOf $ to)
100 NT.defaultConnectHints
103 didSend <- NT.send conn (BSL.toChunks . encode $ to)
108 modifyMVar_ nodeState $ return .
109 (localConnectionBetween from to ^= Just (conn, implicitReconnect))
114 endPoint = localEndPoint node
115 nodeState = localState node
117connBetween :: LocalNode
121 -> IO (Maybe NT.Connection)
122connBetween node from to implicitReconnect = do
123 mConn <- withMVar nodeState $ return . (^. localConnectionBetween from to)
128 setupConnBetween node from to implicitReconnect
130 nodeState = localState node
132disconnect :: LocalNode -> Identifier -> Identifier -> IO ()
133disconnect node from to =
134 modifyMVar_ (localState node) $ \st ->
135 case st ^. localConnectionBetween from to of
140 return (localConnectionBetween from to ^= Nothing $ st)
142closeImplicitReconnections :: LocalNode -> Identifier -> IO ()
143closeImplicitReconnections node to =
144 modifyMVar_ (localState node) $ \st -> do
145 let shouldClose (_, to') (_, WithImplicitReconnect) = to `impliesDeathOf` to'
146 shouldClose _ _ = False
147 let (affected, unaffected) = Map.partitionWithKey shouldClose (st ^. localConnections)
148 mapM_ (NT.close . fst) (Map.elems affected)
149 return (localConnections ^= unaffected $ st)
151-- | @a `impliesDeathOf` b@ is true if the death of @a@ (for instance, a node)
152-- implies the death of @b@ (for instance, a process on that node)
153impliesDeathOf :: Identifier
156NodeIdentifier nid `impliesDeathOf` NodeIdentifier nid' =
158NodeIdentifier nid `impliesDeathOf` ProcessIdentifier pid =
159 processNodeId pid == nid
160NodeIdentifier nid `impliesDeathOf` SendPortIdentifier cid =
161 processNodeId (sendPortProcessId cid) == nid
162ProcessIdentifier pid `impliesDeathOf` ProcessIdentifier pid' =
164ProcessIdentifier pid `impliesDeathOf` SendPortIdentifier cid =
165 sendPortProcessId cid == pid
166SendPortIdentifier cid `impliesDeathOf` SendPortIdentifier cid' =
168_ `impliesDeathOf` _ =
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list