@@ -259,17 +259,18 @@ startMxAgent node = do
259259 mv <- MVar.newEmptyMVar
260260 pid <- fork $ mxAgentController fork mv
261261 (tracer', wqRef, mxNew') <- MVar.takeMVar mv
262− return $ node { localEventBus = (MxEventBus pid wqRef mxNew')
263− , localTracer = tracer'
264− }
262+ return node { localEventBus = (MxEventBus pid tracer' wqRef mxNew') }
265263
266264startDefaultTracer :: LocalNode -> IO ()
267265startDefaultTracer node' = do
268− let (Tracer pid _) = localTracer node'
269− runProcess node' $ register "trace.controller" pid
270− pid' <- forkProcess node' defaultTracer
271− enableTrace (localTracer node') pid'
272− runProcess node' $ register "tracer.initial" pid'
266+ let t = localEventBus node'
267+ case t of
268+ MxEventBus _ (Tracer pid _) _ _ -> do
269+ runProcess node' $ register "trace.controller" pid
270+ pid' <- forkProcess node' defaultTracer
271+ enableTrace (localEventBus node') pid'
272+ runProcess node' $ register "tracer.initial" pid'
273+ _ -> return ()
273274
274275-- | Start and register the service processes on a node
275276startServiceProcesses :: LocalNode -> IO ()
@@ -360,7 +361,7 @@ forkProcess node proc = modifyMVar (localState node) startProcess
360361 return (tid', lproc)
361362
362363 -- see note [tracer/forkProcess races]
363− mxNotify node (MxSpawned pid)
364+ trace node (MxSpawned pid)
364365
365366 if lpidCounter lpid == maxBound
366367 then do
@@ -442,7 +443,7 @@ handleIncomingMessages node = go initConnectionState
442443 NT.ConnectionOpened cid rel theirAddr ->
443444 if rel == NT.ReliableOrdered
444445 then
445− mxNotify node (MxConnected cid theirAddr)
446+ trace node (MxConnected cid theirAddr)
446447 >> go (
447448 (incomingAt cid ^= Just (theirAddr, Uninit))
448449 . (incomingFrom theirAddr ^: Set.insert cid)
@@ -458,7 +459,7 @@ handleIncomingMessages node = go initConnectionState
458459 -- it from the NC state? (and same for channels, below)
459460 let msg = payloadToMessage payload
460461 enqueue queue msg -- 'enqueue' is strict
461− mxNotify node (MxReceived pid msg)
462+ trace node (MxReceived pid msg)
462463 go st
463464 Just (_, ToChan (TypedChannel chan')) -> do
464465 mChan <- deRefWeak chan'
@@ -502,13 +503,12 @@ handleIncomingMessages node = go initConnectionState
502503 else invalidRequest cid st
503504 Nothing ->
504505 invalidRequest cid st
505− NT.ConnectionClosed cid -> do
506− putStrLn "connection closed..."
506+ NT.ConnectionClosed cid ->
507507 case st ^. incomingAt cid of
508508 Nothing ->
509509 invalidRequest cid st
510510 Just (src, _) -> do
511− mxNotify node (MxDisconnected cid src)
511+ trace node (MxDisconnected cid src)
512512 go ( (incomingAt cid ^= Nothing)
513513 . (incomingFrom src ^: Set.delete cid)
514514 $ st
@@ -604,21 +604,25 @@ instance Show ProcessKillException where
604604
605605traceNotifyDied :: LocalNode -> Identifier -> DiedReason -> NC ()
606606traceNotifyDied node ident reason =
607− -- TODO: SendPortDied notifications
608− case ident of
609− (NodeIdentifier nid) -> liftIO $ mxNotify node (MxNodeDied nid reason)
610− (ProcessIdentifier pid) -> liftIO $ mxNotify node (MxProcessDied pid reason)
611− _ -> return ()
607+ -- TODO: sendPortDied notifications
608+ liftIO $ withLocalTracer node $ \t ->
609+ case ident of
610+ (NodeIdentifier nid) -> traceEvent t (MxNodeDied nid reason)
611+ (ProcessIdentifier pid) -> traceEvent t (MxProcessDied pid reason)
612+ _ -> return ()
612613
613614traceEventFmtIO :: LocalNode
614615 -> String
615616 -> [TraceArg]
616617 -> IO ()
617−traceEventFmtIO LocalNode{..} fmt args = traceLogFmt localTracer fmt args
618+traceEventFmtIO node fmt args =
619+ withLocalTracer node $ \t -> traceLogFmt t fmt args
620+
621+trace :: LocalNode -> MxEvent -> IO ()
622+trace node ev = withLocalTracer node $ \t -> traceEvent t ev
618623
619−mxNotify :: LocalNode -> MxEvent -> IO ()
620−mxNotify LocalNode{..} ev =
621− Mx.publishEvent localEventBus $ unsafeCreateUnencodedMessage ev
624+withLocalTracer :: LocalNode -> (MxEventBus -> IO ()) -> IO ()
625+withLocalTracer node act = act (localEventBus node)
622626
623627--------------------------------------------------------------------------------
624628-- Core functionality --
@@ -817,8 +821,8 @@ ncEffectRegister from label atnode mPid reregistration = do
817821 do modify' $ registeredHereFor label ^= mPid
818822 updateRemote node currentVal mPid
819823 case mPid of
820− (Just p) -> liftIO $ mxNotify node (MxRegistered p label)
821− Nothing -> liftIO $ mxNotify node (MxUnRegistered (fromJust currentVal) label)
824+ (Just p) -> liftIO $ trace node (MxRegistered p label)
825+ Nothing -> liftIO $ trace node (MxUnRegistered (fromJust currentVal) label)
822826 liftIO $ sendMessage node
823827 (NodeIdentifier (localNodeId node))
824828 (ProcessIdentifier from)
@@ -886,7 +890,7 @@ ncEffectLocalSend :: LocalNode -> ProcessId -> Message -> NC ()
886890ncEffectLocalSend node to msg =
887891 liftIO $ withLocalProc node to $ \p -> do
888892 enqueue (processQueue p) msg
889− mxNotify node (MxReceived to msg)
893+ trace node (MxReceived to msg)
890894
891895-- [Issue #DP-20]
892896ncEffectLocalPortSend :: SendPortId -> Message -> NC ()