courier-0.1.1.5: A message-passing library for simplifying network applications

Copyright(c) Phil Hargett 2015
LicenseMIT (see LICENSE file)
Maintainerphil@haphazardhouse.net
Stabilityexperimental
Portabilitynon-portable (uses STM)
Safe HaskellNone
LanguageHaskell98

Network.RPC.Typed

Description

 
Synopsis

Documentation

call :: (Serialize a, Serialize b) => CallSite -> Name -> Method -> a -> IO b #

Call a method with the provided arguments on the recipient with the given name.

The caller will wait until a matching response is received.

callWithTimeout :: (Serialize a, Serialize r) => CallSite -> Name -> Method -> Int -> a -> IO (Maybe r) #

Call a method with the provided arguments on the recipient with the given name. A request will be made through the CallSite's Endpoint, and then the caller will wait until a matching response is received. If a response is received within the provided timeout (measured in microseconds), then return the value wrapped in Just; otherwise, if the timeout expires before the call returns, then return 'Nothing.

gcallWithTimeout :: (Serialize a, Serialize r) => CallSite -> [Name] -> Method -> Int -> a -> IO (Map Name (Maybe r)) #

Group call or RPC but with a timeout: call a method with the provided arguments on all the recipients with the given names. A request will be made through the CallSite's Endpoint, and then the caller will wait until all matching responses are received or the timeout occurs. The returned Map has a key for every Name that was a target of the call, and the value of that key will be Nothing if no response was received before the timeout, or Just value if a response was received.

hear :: (Serialize a, Serialize r) => Endpoint -> Name -> Method -> IO (a, Reply r) #

Wait for a single incoming request to invoke the indicated Method on the specified Endpoint. Return both the method arguments and a Reply function useful for sending the reply. A good pattern for using hear will pattern match the result to a tuple of the form (args,reply), then use the args as needed to compute a result, and then finally send the result back to the client by simply passing the result to reply: reply result.

The invoker of hear must supply the Name they have bound to the Endpoint, as this helps the original requestor of the RPC differentiate responses when the RPC was a group call.

hearTimeout :: (Serialize a, Serialize r) => Endpoint -> Name -> Method -> Int -> IO (Maybe (a, Reply r)) #

Same as hear, except return Nothing if no request received within the specified timeout (measured in microseconds), or return a Just instance containing both the method arguments and a Reply function useful for sending the reply.

handle :: (Serialize a, Serialize r) => Endpoint -> Name -> Method -> (a -> IO r) -> IO HandleSite #

Handle all RPCs to invoke the indicated Method on the specified Endpoint, until hangup is called on the returned HandleSite.

typedMethodSelector :: Serialize a => Method -> Message -> Maybe (Name, RequestId, a) #

A method selector that only matches if the message deserializes into a type that matches arguments to a call.

data HandleSite #

A HandleSite is a just reference to the actual handler of a specific method. Mostly for invoking hangup on the handler, once it is no longer needed.

Constructors

HandleSite Name (Async ()) 

type Reply b = b -> IO () #

A Reply is a one-shot function for sending a response to an incoming request.

data CallSite #

A call site is a location for making RPCs: it includes an endpoint and a name by which recipients can return the call

data Response #

Encapsulates the completion side of a call: every invocation of call produces a Request that is sent to the destination Endpoint, where the hearing side will generate a Response after completing the request'

Instances
Eq Response # 
Instance details

Defined in Network.RPC

Show Response # 
Instance details

Defined in Network.RPC

Serialize Response # 
Instance details

Defined in Network.RPC

data Request #

Encapsulates the initiating side of a call: every invocation of call produces a Request that is sent to the destination Endpoint, where the hearing side will generate a Response after completing the request'

Instances
Eq Request # 
Instance details

Defined in Network.RPC

Methods

(==) :: Request -> Request -> Bool #

(/=) :: Request -> Request -> Bool #

Show Request # 
Instance details

Defined in Network.RPC

Serialize Request # 
Instance details

Defined in Network.RPC

data RequestId #

A unique identifier for a Request

Instances
Eq RequestId # 
Instance details

Defined in Network.RPC

Show RequestId # 
Instance details

Defined in Network.RPC

Generic RequestId # 
Instance details

Defined in Network.RPC

Associated Types

type Rep RequestId :: Type -> Type #

Serialize RequestId # 
Instance details

Defined in Network.RPC

type Rep RequestId # 
Instance details

Defined in Network.RPC

type Rep RequestId = D1 (MetaData "RequestId" "Network.RPC" "courier-0.1.1.5-HgY7wCNSk457UDjq74WNtD" True) (C1 (MetaCons "RequestId" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Word32, Word32, Word32, Word32))))

type Method = String #

An identifier for what method to invoke on the receiving Endpoint. If hear has been invoked on the Endpoint with a matching identifier, then calls will be delivered to that invocation of hear.

mkRequestId :: IO RequestId #

Create a new identifier for Requests

newCallSite :: Endpoint -> Name -> CallSite #

Create a new CallSite using the indicated Endpoint for sending RPCs and using the specified Name for receiving responses.

gcall :: CallSite -> [Name] -> Method -> Message -> IO (Map Name Message) #

Group call or RPC: call a method with the provided arguments on all the recipients with the given names. A request will be made through the CallSite's Endpoint, and then the caller will wait until all matching responses are received.

anyCall :: CallSite -> [Name] -> Method -> Message -> IO (Message, Name) #

Invoke the same method on multiple Names, and wait indefinitely until the first response from any Name, returning the value and the Name which responded.

methodSelector :: Method -> Message -> Maybe (Name, RequestId, Message) #

A simple function that, given a Method, returns a filter suitable for use with selectMessage. The typical use case will involve partial application: methodSelector method passed as an argument to selectMessage.

hearAll :: Endpoint -> Name -> IO (Method, Message, Reply Message) #

A variant of hear, except it listens for any incoming RPC request on the specified Endpoint.

hearAllTimeout :: Endpoint -> Name -> Int -> IO (Maybe (Method, Message, Reply Message)) #

A variant of hearTimeout, except it listens for any incoming RPC request on the specified Endpoint

handleAll :: Endpoint -> Name -> (Method -> Message -> IO Message) -> IO HandleSite #

Handle all RPCs on the specified Endpoint until hangup is called on the returned HandleSite

hangup :: HandleSite -> IO () #

Stop handling incoming RPCs for the indicated HandleSite.