-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Cloud Haskell Extras -- -- Supporting library, providing common types and utilities used by the -- various components that make up the distributed-process-platform -- package. @package distributed-process-extras @version 0.1.0 -- | If you don't know exactly what this module is for and precisely how to -- use the types within, you should move on, quickly! module Control.Distributed.Process.Extras.Internal.Unsafe data PCopy a -- | Wrap any Typeable datum in a PCopy. We hide the -- constructor to discourage arbitrary uses of the type, since -- PCopy is a specialised and potentially dangerous construct. pCopy :: Typeable a => a -> PCopy a -- | Matches on PCopy m and returns the m within. This -- potentially allows us to bypass serialization (and the type -- constraints it enforces) for local message passing (i.e., with -- UnencodedMessage data), since PCopy is just a shim. matchP :: Typeable m => Match (Maybe m) -- | Matches on a TypedChannel (PCopy a). matchChanP :: Typeable m => ReceivePort (PCopy m) -> Match m -- | Given a raw Message, attempt to unwrap a Typeable -- datum from an enclosing PCopy wrapper. pUnwrap :: Typeable m => Message -> Process (Maybe m) -- | A generic input channel that can be read from in the same fashion as a -- typed channel (i.e., ReceivePort). To read from an input -- stream in isolation, see readInputStream. To compose an -- InputStream with reads on a process' mailbox (and/or typed -- channels), see matchInputStream. data InputStream a Null :: InputStream a -- | Create a new InputStream. newInputStream :: Typeable a => Either (ReceivePort a) (STM a) -> InputStream a -- | Constructs a Match for a given InputChannel. matchInputStream :: InputStream a -> Match a -- | Read from an InputStream. This is a blocking operation. readInputStream :: Serializable a => InputStream a -> Process a data InvalidBinaryShim InvalidBinaryShim :: InvalidBinaryShim instance Typeable InvalidBinaryShim instance Typeable PCopy instance Typeable InputStream instance Typeable NullInputStream instance Show InvalidBinaryShim instance Eq InvalidBinaryShim instance Generic (PCopy a) instance Generic NullInputStream instance Show NullInputStream instance Eq NullInputStream instance Datatype D1PCopy instance Constructor C1_0PCopy instance Datatype D1NullInputStream instance Constructor C1_0NullInputStream instance NFData NullInputStream instance Binary NullInputStream instance Typeable a => Binary (PCopy a) instance NFData a => NFData (PCopy a) module Control.Distributed.Process.Extras.Internal.Queue.PriorityQ newtype PriorityQ k a PriorityQ :: PQueue k a -> PriorityQ k a q :: PriorityQ k a -> PQueue k a empty :: Ord k => PriorityQ k v isEmpty :: Ord k => PriorityQ k v -> Bool singleton :: Ord k => k -> a -> PriorityQ k a enqueue :: Ord k => k -> v -> PriorityQ k v -> PriorityQ k v dequeue :: Ord k => PriorityQ k v -> Maybe (v, PriorityQ k v) peek :: Ord k => PriorityQ k v -> Maybe v -- | A simple FIFO queue implementation backed by Data.Sequence. module Control.Distributed.Process.Extras.Internal.Queue.SeqQ data SeqQ a empty :: SeqQ a isEmpty :: SeqQ a -> Bool singleton :: a -> SeqQ a enqueue :: SeqQ a -> a -> SeqQ a dequeue :: SeqQ a -> Maybe (a, SeqQ a) peek :: SeqQ a -> Maybe a instance Show a => Show (SeqQ a) instance Eq a => Eq (SeqQ a) module Control.Distributed.Process.Extras.Internal.Containers.MultiMap -- | Opaque type of MultiMaps. data MultiMap k v -- | Class of things that can be inserted in a map or a set (of mapped -- values), for which instances of Eq and Hashable must -- be present. class (Eq a, Hashable a) => Insertable a empty :: MultiMap k v insert :: (Insertable k, Insertable v) => k -> v -> MultiMap k v -> MultiMap k v member :: Insertable k => k -> MultiMap k a -> Bool lookup :: Insertable k => k -> MultiMap k v -> Maybe [v] filter :: Insertable k => (v -> Bool) -> MultiMap k v -> MultiMap k v filterWithKey :: Insertable k => (k -> v -> Bool) -> MultiMap k v -> MultiMap k v toList :: MultiMap k v -> [(k, v)] instance Foldable (MultiMap k) instance (Eq a, Hashable a) => Insertable a module Control.Concurrent.Utils data Lock class Exclusive a new :: Exclusive a => IO a acquire :: (Exclusive a, MonadIO m) => a -> m () release :: (Exclusive a, MonadIO m) => a -> m () class Synchronised e m where synchronized = synchronised synchronised :: (Synchronised e m, Exclusive e, Monad m) => e -> m b -> m b synchronized :: (Synchronised e m, Exclusive e, Monad m) => e -> m b -> m b withLock :: Exclusive e => e -> IO a -> IO a instance Synchronised Lock Process instance Synchronised Lock IO instance Exclusive Lock -- | Types used throughout the Extras package module Control.Distributed.Process.Extras.Internal.Types -- | Tags provide uniqueness for messages, so that they can be matched with -- their response. type Tag = Int -- | Generates unique Tag for messages and response pairs. Each -- process that depends, directly or indirectly, on the call mechanisms -- in Control.Distributed.Process.Global.Call should have at most -- one TagPool on which to draw unique message tags. type TagPool = MVar Tag -- | Create a new per-process source of unique message identifiers. newTagPool :: Process TagPool -- | Extract a new identifier from a TagPool. getTag :: TagPool -> Process Tag -- | Class of things to which a Process can link itself. class Linkable a linkTo :: Linkable a => a -> Process () -- | Class of things that can be killed (or instructed to exit). class Killable a killProc :: Killable a => a -> String -> Process () exitProc :: (Killable a, Serializable m) => a -> m -> Process () -- | Class of things that can be resolved to a ProcessId. class Resolvable a resolve :: Resolvable a => a -> Process (Maybe ProcessId) -- | Provides a unified API for addressing processes. class Routable a where unresolvableMessage = baseAddressableErrorMessage sendTo :: (Routable a, Serializable m) => a -> m -> Process () unsafeSendTo :: (Routable a, NFSerializable m) => a -> m -> Process () unresolvableMessage :: Routable a => a -> String class (Resolvable a, Routable a) => Addressable a sendToRecipient :: Serializable m => Recipient -> m -> Process () -- | A simple means of mapping to a receiver. data Recipient Pid :: !ProcessId -> Recipient Registered :: !String -> Recipient RemoteRegistered :: !String -> !NodeId -> Recipient -- | Used internally in whereisOrStart. Sent as (RegisterSelf,ProcessId). data RegisterSelf RegisterSelf :: RegisterSelf -- | A synchronous version of whereis, this relies on call to -- perform the relevant monitoring of the remote node. whereisRemote :: NodeId -> String -> Process (Maybe ProcessId) -- | resolve the Resolvable or die with specified msg plus details of what -- didn't resolve resolveOrDie :: (Routable a, Resolvable a) => a -> String -> Process ProcessId -- | Wait cancellation message. data CancelWait CancelWait :: CancelWait -- | Simple representation of a channel. type Channel a = (SendPort a, ReceivePort a) -- | A ubiquitous shutdown signal that can be used to maintain a -- consistent shutdown/stop protocol for any process that wishes to -- handle it. data Shutdown Shutdown :: Shutdown -- | Provides a reason for process termination. data ExitReason -- | indicates normal exit ExitNormal :: ExitReason -- | normal response to a Shutdown ExitShutdown :: ExitReason -- | abnormal (error) shutdown ExitOther :: !String -> ExitReason -- | Given when a server is unobtainable. data ServerDisconnected ServerDisconnected :: !DiedReason -> ServerDisconnected -- | Introduces a class that brings NFData into scope along with -- Serializable, such that we can force evaluation. Intended for use with -- the UnsafePrimitives module (which wraps -- Control.Distributed.Process.UnsafePrimitives), and guarantees -- evaluatedness in terms of NFData. Please note that we -- cannot guarantee that an NFData instance will behave -- the same way as a Binary one with regards evaluation, so it -- is still possible to introduce unexpected behaviour by using -- unsafe primitives in this way. class (NFData a, Serializable a) => NFSerializable a __remoteTable :: RemoteTable -> RemoteTable instance [overlap ok] (Resolvable a, Routable a) => Addressable a instance [overlap ok] Routable (Message -> Process ()) instance [overlap ok] Routable (NodeId, String) instance [overlap ok] Resolvable (NodeId, String) instance [overlap ok] Routable String instance [overlap ok] Resolvable String instance [overlap ok] Routable ProcessId instance [overlap ok] Resolvable ProcessId instance [overlap ok] Routable Recipient instance [overlap ok] Resolvable Recipient instance [overlap ok] Resolvable a => Routable a instance [overlap ok] Resolvable r => Killable r instance [overlap ok] Killable ProcessId instance [overlap ok] Typeable CancelWait instance [overlap ok] Typeable RegisterSelf instance [overlap ok] Typeable Shutdown instance [overlap ok] Typeable ExitReason instance [overlap ok] Typeable Recipient instance [overlap ok] Typeable ServerDisconnected instance [overlap ok] Eq CancelWait instance [overlap ok] Show CancelWait instance [overlap ok] Generic CancelWait instance [overlap ok] Generic RegisterSelf instance [overlap ok] Generic Shutdown instance [overlap ok] Show Shutdown instance [overlap ok] Eq Shutdown instance [overlap ok] Generic ExitReason instance [overlap ok] Eq ExitReason instance [overlap ok] Show ExitReason instance [overlap ok] Generic Recipient instance [overlap ok] Show Recipient instance [overlap ok] Eq Recipient instance [overlap ok] Generic ServerDisconnected instance Datatype D1CancelWait instance Constructor C1_0CancelWait instance Datatype D1RegisterSelf instance Constructor C1_0RegisterSelf instance Datatype D1Shutdown instance Constructor C1_0Shutdown instance Datatype D1ExitReason instance Constructor C1_0ExitReason instance Constructor C1_1ExitReason instance Constructor C1_2ExitReason instance Datatype D1Recipient instance Constructor C1_0Recipient instance Constructor C1_1Recipient instance Constructor C1_2Recipient instance Datatype D1ServerDisconnected instance Constructor C1_0ServerDisconnected instance [overlap ok] NFData ServerDisconnected instance [overlap ok] Binary ServerDisconnected instance [overlap ok] Binary Recipient instance [overlap ok] NFData ExitReason instance [overlap ok] Binary ExitReason instance [overlap ok] NFData Shutdown instance [overlap ok] Binary Shutdown instance [overlap ok] NFData RegisterSelf instance [overlap ok] Binary RegisterSelf instance [overlap ok] NFData CancelWait instance [overlap ok] Binary CancelWait instance [overlap ok] (NFData a, Serializable a) => NFSerializable a -- | Maintainers : Jeff Epstein, Tim Watson Stability : experimental -- Portability : non-portable (requires concurrency) -- -- This module provides a set of additional primitives that add -- functionality to the basic Cloud Haskell APIs. module Control.Distributed.Process.Extras.Internal.Primitives class (Resolvable a, Routable a) => Addressable a -- | Provides a unified API for addressing processes. class Routable a where unresolvableMessage = baseAddressableErrorMessage sendTo :: (Routable a, Serializable m) => a -> m -> Process () unsafeSendTo :: (Routable a, NFSerializable m) => a -> m -> Process () unresolvableMessage :: Routable a => a -> String -- | Class of things that can be resolved to a ProcessId. class Resolvable a resolve :: Resolvable a => a -> Process (Maybe ProcessId) -- | Class of things to which a Process can link itself. class Linkable a linkTo :: Linkable a => a -> Process () -- | Class of things that can be killed (or instructed to exit). class Killable a killProc :: Killable a => a -> String -> Process () exitProc :: (Killable a, Serializable m) => a -> m -> Process () -- | Spawn a new (local) process. This variant takes an initialisation -- action and a secondary expression from the result of the -- initialisation to Process (). The spawn operation -- synchronises on the completion of the before action, such -- that the calling process is guaranteed to only see the newly spawned -- ProcessId once the initialisation has successfully completed. spawnSignalled :: Process a -> (a -> Process ()) -> Process ProcessId -- | Node local version of spawnLink. Note that this is just the -- sequential composition of spawn and link. (The -- Unified semantics that underlies Cloud Haskell does not even -- support a synchronous link operation) spawnLinkLocal :: Process () -> Process ProcessId -- | Like spawnLinkLocal, but monitors the spawned process. spawnMonitorLocal :: Process () -> Process (ProcessId, MonitorRef) -- | CH's link primitive, unlike Erlang's, will trigger when the -- target process dies for any reason. This function has semantics like -- Erlang's: it will trigger ProcessLinkException only when the -- target dies abnormally. linkOnFailure :: ProcessId -> Process () -- | A synchronous version of whereis, this relies on call to -- perform the relevant monitoring of the remote node. whereisRemote :: NodeId -> String -> Process (Maybe ProcessId) -- | Returns the pid of the process that has been registered under the -- given name. This refers to a local, per-node registration, not -- global registration. If that name is unregistered, a process -- is started. This is a handy way to start per-node named servers. whereisOrStart :: String -> Process () -> Process ProcessId -- | A remote equivalent of whereisOrStart. It deals with the node -- registry on the given node, and the process, if it needs to be -- started, will run on that node. If the node is inaccessible, Nothing -- will be returned. whereisOrStartRemote :: NodeId -> String -> Closure (Process ()) -> Process (Maybe ProcessId) -- | An alternative to matchIf that allows both predicate and action -- to be expressed in one parameter. matchCond :: Serializable a => (a -> Maybe (Process b)) -> Match b -- | Safe (i.e., monitored) waiting on an expected response/message. awaitResponse :: Addressable a => a -> [Match (Either ExitReason b)] -> Process (Either ExitReason b) -- | Apply the supplied expression n times times :: Int -> Process () -> Process () -- | Monitor any Resolvable object. monitor :: Resolvable a => a -> Process (Maybe MonitorRef) awaitExit :: Resolvable a => a -> Process () isProcessAlive :: ProcessId -> Process Bool -- | Like forever but sans space leak forever' :: Monad m => m a -> m b deliver :: (Addressable a, Serializable m) => m -> a -> Process () __remoteTable :: RemoteTable -> RemoteTable -- | This module provides facilities for working with time delays and -- timeouts. The type Timeout and the timeout family of -- functions provide mechanisms for working with -- threadDelay-like behaviour that operates on microsecond -- values. -- -- The TimeInterval and TimeUnit related functions provide -- an abstraction for working with various time intervals, whilst the -- Delay type provides a corrolary to timeout that works -- with these. module Control.Distributed.Process.Extras.Time -- | given a number, produces a TimeInterval of microseconds microSeconds :: Int -> TimeInterval -- | given a number, produces a TimeInterval of milliseconds milliSeconds :: Int -> TimeInterval -- | given a number, produces a TimeInterval of seconds seconds :: Int -> TimeInterval -- | given a number, produces a TimeInterval of minutes minutes :: Int -> TimeInterval -- | given a number, produces a TimeInterval of hours hours :: Int -> TimeInterval -- | converts the supplied TimeInterval to microseconds asTimeout :: TimeInterval -> Int -- | Convenience for making timeouts; e.g., -- --
-- receiveTimeout (after 3 Seconds) [ match (\"ok" -> return ()) ] --after :: Int -> TimeUnit -> Int -- | Convenience for making TimeInterval; e.g., -- --
-- let ti = within 5 Seconds in ..... --within :: Int -> TimeUnit -> TimeInterval -- | converts the supplied TimeUnit to microseconds timeToMicros :: TimeUnit -> Int -> Int -- | A time interval. data TimeInterval -- | Defines the time unit for a Timeout value data TimeUnit Days :: TimeUnit Hours :: TimeUnit Minutes :: TimeUnit Seconds :: TimeUnit Millis :: TimeUnit Micros :: TimeUnit -- | Represents either a delay of TimeInterval, an infinite wait or -- no delay (i.e., non-blocking). data Delay Delay :: TimeInterval -> Delay Infinity :: Delay NoDelay :: Delay -- | given a TimeInterval, provide an equivalent -- NominalDiffTim timeIntervalToDiffTime :: TimeInterval -> NominalDiffTime -- | given a NominalDiffTim, provide an equivalent -- TimeInterval@ diffTimeToTimeInterval :: NominalDiffTime -> TimeInterval -- | given a NominalDiffTim, provide an equivalent Delay@ diffTimeToDelay :: NominalDiffTime -> Delay -- | given a Delay, provide an equivalent NominalDiffTim delayToDiffTime :: Delay -> NominalDiffTime -- | Create a NominalDiffTime from a number of microseconds. microsecondsToNominalDiffTime :: Integer -> NominalDiffTime -- | Represents a timeout in terms of microseconds, where -- Nothing stands for infinity and Just 0, no-delay. type Timeout = Maybe Int -- | Send to a process when a timeout expires. data TimeoutNotification TimeoutNotification :: Tag -> TimeoutNotification -- | Sends the calling process TimeoutNotification tag after -- time microseconds timeout :: Int -> Tag -> ProcessId -> Process () -- | Constructs an inifinite Timeout. infiniteWait :: Timeout -- | Constructs a no-wait Timeout noWait :: Timeout instance Typeable TimeUnit instance Typeable TimeInterval instance Typeable Delay instance Typeable TimeoutNotification instance Generic TimeUnit instance Eq TimeUnit instance Show TimeUnit instance Generic TimeInterval instance Eq TimeInterval instance Show TimeInterval instance Generic Delay instance Eq Delay instance Show Delay instance Datatype D1TimeUnit instance Constructor C1_0TimeUnit instance Constructor C1_1TimeUnit instance Constructor C1_2TimeUnit instance Constructor C1_3TimeUnit instance Constructor C1_4TimeUnit instance Constructor C1_5TimeUnit instance Datatype D1TimeInterval instance Constructor C1_0TimeInterval instance Datatype D1Delay instance Constructor C1_0Delay instance Constructor C1_1Delay instance Constructor C1_2Delay instance Num Delay instance Num TimeInterval instance Binary TimeoutNotification instance NFData Delay instance Binary Delay instance NFData TimeInterval instance Binary TimeInterval instance NFData TimeUnit instance Binary TimeUnit -- |