@@ -259,17 +259,18 @@ startMxAgent node = do
259 mv <- MVar.newEmptyMVar
259 mv <- MVar.newEmptyMVar
260 pid <- fork $ mxAgentController fork mv
260 pid <- fork $ mxAgentController fork mv
261 (tracer', wqRef, mxNew') <- MVar.takeMVar mv
261 (tracer', wqRef, mxNew') <- MVar.takeMVar mv
262− return $ node { localEventBus = (MxEventBus pid wqRef mxNew')
262+ return node { localEventBus = (MxEventBus pid tracer' wqRef mxNew') }
263− , localTracer = tracer'
266startDefaultTracer :: LocalNode -> IO ()
264startDefaultTracer :: LocalNode -> IO ()
267startDefaultTracer node' = do
265startDefaultTracer node' = do
268− let (Tracer pid _) = localTracer node'
266+ let t = localEventBus node'
268+ MxEventBus _ (Tracer pid _) _ _ -> do
269− runProcess node' $ register "trace.controller" pid
269+ runProcess node' $ register "trace.controller" pid
270− pid' <- forkProcess node' defaultTracer
270+ pid' <- forkProcess node' defaultTracer
271− enableTrace (localTracer node') pid'
271+ enableTrace (localEventBus node') pid'
272− runProcess node' $ register "tracer.initial" pid'
272+ runProcess node' $ register "tracer.initial" pid'
274-- | Start and register the service processes on a node
275-- | Start and register the service processes on a node
275startServiceProcesses :: LocalNode -> IO ()
276startServiceProcesses :: LocalNode -> IO ()
@@ -360,7 +361,7 @@ forkProcess node proc = modifyMVar (localState node) startProcess
360 return (tid', lproc)
361 return (tid', lproc)
362 -- see note [tracer/forkProcess races]
363 -- see note [tracer/forkProcess races]
363− mxNotify node (MxSpawned pid)
364+ trace node (MxSpawned pid)
365 if lpidCounter lpid == maxBound
366 if lpidCounter lpid == maxBound
@@ -442,7 +443,7 @@ handleIncomingMessages node = go initConnectionState
442 NT.ConnectionOpened cid rel theirAddr ->
443 NT.ConnectionOpened cid rel theirAddr ->
443 if rel == NT.ReliableOrdered
444 if rel == NT.ReliableOrdered
445− mxNotify node (MxConnected cid theirAddr)
446+ trace node (MxConnected cid theirAddr)
447 (incomingAt cid ^= Just (theirAddr, Uninit))
448 (incomingAt cid ^= Just (theirAddr, Uninit))
448 . (incomingFrom theirAddr ^: Set.insert cid)
449 . (incomingFrom theirAddr ^: Set.insert cid)
@@ -458,7 +459,7 @@ handleIncomingMessages node = go initConnectionState
458 -- it from the NC state? (and same for channels, below)
459 -- it from the NC state? (and same for channels, below)
459 let msg = payloadToMessage payload
460 let msg = payloadToMessage payload
460 enqueue queue msg -- 'enqueue' is strict
461 enqueue queue msg -- 'enqueue' is strict
461− mxNotify node (MxReceived pid msg)
462+ trace node (MxReceived pid msg)
463 Just (_, ToChan (TypedChannel chan')) -> do
464 Just (_, ToChan (TypedChannel chan')) -> do
464 mChan <- deRefWeak chan'
465 mChan <- deRefWeak chan'
@@ -502,13 +503,12 @@ handleIncomingMessages node = go initConnectionState
502 else invalidRequest cid st
503 else invalidRequest cid st
503 Nothing ->
504 Nothing ->
504 invalidRequest cid st
505 invalidRequest cid st
505− NT.ConnectionClosed cid -> do
506+ NT.ConnectionClosed cid ->
506− putStrLn "connection closed..."
507 case st ^. incomingAt cid of
507 case st ^. incomingAt cid of
508 Nothing ->
508 Nothing ->
509 invalidRequest cid st
509 invalidRequest cid st
510 Just (src, _) -> do
510 Just (src, _) -> do
511− mxNotify node (MxDisconnected cid src)
511+ trace node (MxDisconnected cid src)
512 go ( (incomingAt cid ^= Nothing)
512 go ( (incomingAt cid ^= Nothing)
513 . (incomingFrom src ^: Set.delete cid)
513 . (incomingFrom src ^: Set.delete cid)
@@ -604,21 +604,25 @@ instance Show ProcessKillException where
605traceNotifyDied :: LocalNode -> Identifier -> DiedReason -> NC ()
605traceNotifyDied :: LocalNode -> Identifier -> DiedReason -> NC ()
606traceNotifyDied node ident reason =
606traceNotifyDied node ident reason =
607− -- TODO: SendPortDied notifications
607+ -- TODO: sendPortDied notifications
608+ liftIO $ withLocalTracer node $ \t ->
608− case ident of
609+ case ident of
609− (NodeIdentifier nid) -> liftIO $ mxNotify node (MxNodeDied nid reason)
610+ (NodeIdentifier nid) -> traceEvent t (MxNodeDied nid reason)
610− (ProcessIdentifier pid) -> liftIO $ mxNotify node (MxProcessDied pid reason)
611+ (ProcessIdentifier pid) -> traceEvent t (MxProcessDied pid reason)
611− _ -> return ()
612+ _ -> return ()
613traceEventFmtIO :: LocalNode
614traceEventFmtIO :: LocalNode
614 -> String
615 -> String
615 -> [TraceArg]
616 -> [TraceArg]
617−traceEventFmtIO LocalNode{..} fmt args = traceLogFmt localTracer fmt args
618+traceEventFmtIO node fmt args =
619+ withLocalTracer node $ \t -> traceLogFmt t fmt args
621+trace :: LocalNode -> MxEvent -> IO ()
622+trace node ev = withLocalTracer node $ \t -> traceEvent t ev
619−mxNotify :: LocalNode -> MxEvent -> IO ()
624+withLocalTracer :: LocalNode -> (MxEventBus -> IO ()) -> IO ()
620−mxNotify LocalNode{..} ev =
625+withLocalTracer node act = act (localEventBus node)
621− Mx.publishEvent localEventBus $ unsafeCreateUnencodedMessage ev
623--------------------------------------------------------------------------------
627--------------------------------------------------------------------------------
624-- Core functionality --
628-- Core functionality --
@@ -817,8 +821,8 @@ ncEffectRegister from label atnode mPid reregistration = do
817 do modify' $ registeredHereFor label ^= mPid
821 do modify' $ registeredHereFor label ^= mPid
818 updateRemote node currentVal mPid
822 updateRemote node currentVal mPid
819 case mPid of
823 case mPid of
820− (Just p) -> liftIO $ mxNotify node (MxRegistered p label)
824+ (Just p) -> liftIO $ trace node (MxRegistered p label)
821− Nothing -> liftIO $ mxNotify node (MxUnRegistered (fromJust currentVal) label)
825+ Nothing -> liftIO $ trace node (MxUnRegistered (fromJust currentVal) label)
822 liftIO $ sendMessage node
826 liftIO $ sendMessage node
823 (NodeIdentifier (localNodeId node))
827 (NodeIdentifier (localNodeId node))
824 (ProcessIdentifier from)
828 (ProcessIdentifier from)
@@ -886,7 +890,7 @@ ncEffectLocalSend :: LocalNode -> ProcessId -> Message -> NC ()
886ncEffectLocalSend node to msg =
890ncEffectLocalSend node to msg =
887 liftIO $ withLocalProc node to $ \p -> do
891 liftIO $ withLocalProc node to $ \p -> do
888 enqueue (processQueue p) msg
892 enqueue (processQueue p) msg
889− mxNotify node (MxReceived to msg)
893+ trace node (MxReceived to msg)
891-- [Issue #DP-20]
895-- [Issue #DP-20]
892ncEffectLocalPortSend :: SendPortId -> Message -> NC ()
896ncEffectLocalPortSend :: SendPortId -> Message -> NC ()