{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
module Control.Distributed.Process.ManagedProcess.Server.Gen
(
reply
, replyWith
, noReply
, continue
, timeoutAfter
, hibernate
, stop
, reject
, rejectWith
, become
, haltNoReply
, lift
, Gen.recvLoop
, Gen.precvLoop
, Gen.currentTimeout
, Gen.systemTimeout
, Gen.drainTimeout
, Gen.processState
, Gen.processDefinition
, Gen.processFilters
, Gen.processUnhandledMsgPolicy
, Gen.processQueue
, Gen.gets
, Gen.getAndModifyState
, Gen.modifyState
, Gen.setUserTimeout
, Gen.setProcessState
, GenProcess
, Gen.peek
, Gen.push
, Gen.enqueue
, Gen.dequeue
, Gen.addUserTimer
, Gen.removeUserTimer
, Gen.eval
, Gen.act
, Gen.runAfter
, Gen.evalAfter
) where
import Control.Distributed.Process.Extras
( ExitReason
)
import Control.Distributed.Process.Extras.Time
( TimeInterval
, Delay
)
import Control.Distributed.Process.ManagedProcess.Internal.Types
( lift
, ProcessAction(..)
, GenProcess
, ProcessReply(..)
, ProcessDefinition
)
import qualified Control.Distributed.Process.ManagedProcess.Internal.GenProcess as Gen
( recvLoop
, precvLoop
, currentTimeout
, systemTimeout
, drainTimeout
, processState
, processDefinition
, processFilters
, processUnhandledMsgPolicy
, processQueue
, gets
, getAndModifyState
, modifyState
, setUserTimeout
, setProcessState
, GenProcess
, peek
, push
, enqueue
, dequeue
, addUserTimer
, removeUserTimer
, eval
, act
, runAfter
, evalAfter
)
import Control.Distributed.Process.ManagedProcess.Internal.GenProcess
( processState
)
import qualified Control.Distributed.Process.ManagedProcess.Server as Server
( replyWith
, continue
)
import Control.Distributed.Process.Serializable (Serializable)
reject :: forall r s . String -> GenProcess s (ProcessReply r s)
reject rs = processState >>= \st -> lift $ Server.continue st >>= return . ProcessReject rs
rejectWith :: forall r m s . (Show r) => r -> GenProcess s (ProcessReply m s)
rejectWith rs = reject (show rs)
reply :: forall r s . (Serializable r) => r -> GenProcess s (ProcessReply r s)
reply r = processState >>= \s -> lift $ Server.continue s >>= Server.replyWith r
replyWith :: forall r s . (Serializable r)
=> r
-> ProcessAction s
-> GenProcess s (ProcessReply r s)
replyWith r s = return $ ProcessReply r s
noReply :: (Serializable r) => ProcessAction s -> GenProcess s (ProcessReply r s)
noReply = return . NoReply
haltNoReply :: forall s r . Serializable r => ExitReason -> GenProcess s (ProcessReply r s)
haltNoReply r = stop r >>= noReply
continue :: GenProcess s (ProcessAction s)
continue = processState >>= return . ProcessContinue
timeoutAfter :: Delay -> GenProcess s (ProcessAction s)
timeoutAfter d = processState >>= \s -> return $ ProcessTimeout d s
hibernate :: TimeInterval -> GenProcess s (ProcessAction s)
hibernate d = processState >>= \s -> return $ ProcessHibernate d s
become :: forall s . ProcessDefinition s -> GenProcess s (ProcessAction s)
become def = processState >>= \st -> return $ ProcessBecome def st
stop :: ExitReason -> GenProcess s (ProcessAction s)
stop r = return $ ProcessStop r