distributed-process-client-server-0.1.3.1: The Cloud Haskell Application Platform

Copyright(c) Tim Watson 2012 - 2013
LicenseBSD3 (see the file LICENSE)
MaintainerTim Watson <watson.timothy@gmail.com>
Stabilityexperimental
Portabilitynon-portable (requires concurrency)
Safe HaskellNone
LanguageHaskell98

Control.Distributed.Process.ManagedProcess.Server.Restricted

Contents

Description

A safe variant of the Server Portion of the Managed Process API. Most of these operations have the same names as similar operations in the impure Server module (re-exported by the primary API in ManagedProcess). To remove the ambiguity, some combination of either qualification and/or the hiding clause will be required.

Restricted Server Callbacks

The idea behind this module is to provide safe callbacks, i.e., server code that is free from side effects. This safety is enforced by the type system via the RestrictedProcess monad. A StateT interface is provided for code running in the RestrictedProcess monad, so that server side state can be managed safely without resorting to IO (or code running in the Process monad).

Synopsis

Exported Types

data RestrictedProcess s a Source

Restricted (i.e., pure, free from side effects) execution environment for callcastinfo handlers to execute in.

data Result a Source

The result of a call handler's execution.

Constructors

Reply a

reply with the given term

Timeout Delay a

reply with the given term and enter timeout

Hibernate TimeInterval a

reply with the given term and hibernate

Stop ExitReason

stop the process with the given reason

data RestrictedAction Source

The result of a safe cast handler's execution.

Constructors

RestrictedContinue

continue executing

RestrictedTimeout Delay

timeout if no messages are received

RestrictedHibernate TimeInterval

hibernate (i.e., sleep)

RestrictedStop ExitReason

stop/terminate the server process

Creating call/cast protocol handlers

handleCall :: forall s a b. (Serializable a, Serializable b) => (a -> RestrictedProcess s (Result b)) -> Dispatcher s Source

A version of "Control.Distributed.Process.ManagedProcess.Server.handleCall" that takes a handler which executes in RestrictedProcess.

handleCallIf :: forall s a b. (Serializable a, Serializable b) => Condition s a -> (a -> RestrictedProcess s (Result b)) -> Dispatcher s Source

A version of "Control.Distributed.Process.ManagedProcess.Server.handleCallIf" that takes a handler which executes in RestrictedProcess.

handleCast :: forall s a. Serializable a => (a -> RestrictedProcess s RestrictedAction) -> Dispatcher s Source

A version of "Control.Distributed.Process.ManagedProcess.Server.handleCast" that takes a handler which executes in RestrictedProcess.

handleCastIf Source

Arguments

:: Serializable a 
=> Condition s a

predicate that must be satisfied for the handler to run

-> (a -> RestrictedProcess s RestrictedAction)

an action yielding function over the process state and input message

-> Dispatcher s 

A version of "Control.Distributed.Process.ManagedProcess.Server.handleCastIf" that takes a handler which executes in RestrictedProcess.

handleInfo :: forall s a. Serializable a => (a -> RestrictedProcess s RestrictedAction) -> DeferredDispatcher s Source

A version of "Control.Distributed.Process.ManagedProcess.Server.handleInfo" that takes a handler which executes in RestrictedProcess.

handleExit :: forall s a. Serializable a => (a -> RestrictedProcess s RestrictedAction) -> ExitSignalDispatcher s Source

Handling Process State

putState :: s -> RestrictedProcess s () Source

Put a new process state state

getState :: RestrictedProcess s s Source

Get the current process state

modifyState :: (s -> s) -> RestrictedProcess s () Source

Apply the given expression to the current process state

Handling responses/transitions

reply :: forall s r. Serializable r => r -> RestrictedProcess s (Result r) Source

Instructs the process to send a reply and continue running.

noReply :: forall s r. Serializable r => Result r -> RestrictedProcess s (Result r) Source

Continue without giving a reply to the caller - equivalent to continue, but usable in a callback passed to the handleCall family of functions.

haltNoReply :: forall s r. Serializable r => ExitReason -> RestrictedProcess s (Result r) Source

Halt process execution during a call handler, without paying any attention to the expected return type.

continue :: forall s. RestrictedProcess s RestrictedAction Source

Instructs the process to continue running and receiving messages.

timeoutAfter :: forall s. Delay -> RestrictedProcess s RestrictedAction Source

Instructs the process loop to wait for incoming messages until Delay is exceeded. If no messages are handled during this period, the timeout handler will be called. Note that this alters the process timeout permanently such that the given Delay will remain in use until changed.

hibernate :: forall s. TimeInterval -> RestrictedProcess s RestrictedAction Source

Instructs the process to hibernate for the given TimeInterval. Note that no messages will be removed from the mailbox until after hibernation has ceased. This is equivalent to evaluating liftIO . threadDelay.

stop :: forall s. ExitReason -> RestrictedProcess s RestrictedAction Source

Instructs the process to terminate, giving the supplied reason. If a valid shutdownHandler is installed, it will be called with the ExitReason returned from this call, along with the process state.

Utilities

say :: String -> RestrictedProcess s () Source

Log a trace message using the underlying Process's say