git.iko.soy/distributed-process
on 28beaa2 help sign in
75 lines 2.9 kB history raw
1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE StandaloneDeriving #-}
4{-# LANGUAGE ExistentialQuantification #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE PatternGuards #-}
7{-# LANGUAGE RecordWildCards #-}
8{-# LANGUAGE FlexibleInstances #-}
9{-# LANGUAGE UndecidableInstances #-}
11-----------------------------------------------------------------------------
12-- |
13-- Module : Control.Distributed.Process.Management
14-- Copyright : (c) Well-Typed / Tim Watson
15-- License : BSD3 (see the file LICENSE)
16--
17-- Maintainer : Tim Watson <watson.timothy@gmail.com>
18-- Stability : experimental
19-- Portability : non-portable (requires concurrency)
20--
21-- /Management Extensions/ for Cloud Haskell.
22--
23-- This module provides a standard API for monitoring and/or responding to
24-- system events in a Cloud Haskell node.
25--
26-- [Architecture Overview]
27--
28-- /Management Extensions/ can be used by infrastructure or application code
29-- to provide access to runtime instrumentation data, expose control planes
30-- and/or provide remote access to external clients.
31--
32-- The management infrastructure is broken down into three components, which
33-- roughly correspond to the modules it exposes:
34--
35-- 1. @Agent@ - registration and management of /Management Agents/
36-- 2. @Instrumentation@ - provides an API for publishing /instrumentation data/
37-- 3. @Remote@ - provides an API for remote management and administration
38--
39--
40--
41-----------------------------------------------------------------------------
42module Control.Distributed.Process.Management where
44import Control.Applicative ((<$>))
45import Control.Distributed.Process.Internal.Types
46 ( Process
47 , ProcessId
48 , Message
49 , LocalProcess(..)
50 , LocalNode(..)
51 , MxEventBus(..)
52 , unsafeCreateUnencodedMessage
53 )
54import Control.Distributed.Process.Management.Bus (publishEvent)
55import Control.Distributed.Process.Serializable (Serializable)
56import Control.Monad.IO.Class (liftIO)
57import Control.Monad.Reader (ask)
59-- | Publishes an arbitrary @Serializable@ message to the management event bus.
60-- Note that /no attempt is made to force the argument/, therefore it is very
61-- important that you do not pass unevaluated thunks that might crash the
62-- receiving process via this API, since /all/ registered agents will gain
63-- access to the data structure once it is broadcast by the agent controller.
64mxNotify :: (Serializable a) => a -> Process ()
65mxNotify msg = do
66 bus <- localEventBus . processNode <$> ask
67 liftIO $ publishEvent bus $ unsafeCreateUnencodedMessage msg
69mxAgent :: (Message -> Process ()) -> Process ProcessId
70mxAgent handler = do
71 node <- processNode <$> ask
72 pid <- liftIO $ mxNew (localEventBus node) handler
73 -- registerAgent pid
74 return pid