Copyright | (c) Phil Hargett 2015 |
---|---|
License | MIT (see LICENSE file) |
Maintainer | phil@haphazardhouse.net |
Stability | experimental |
Portability | non-portable (requires STM) |
Safe Haskell | None |
Language | Haskell98 |
A Transport
abstracts the details of message delivery, and defines the interfaces
that specific Transport
implementations should provide in order to move messages
between Endpoint
s.
The definition of a transport is deliberately low-level in nature. Unless a specific transport describes itself as supporting features like guaranteed delivery, applications should NOT assume that message delivery is reliable.
For example, if a sender sends a message to a name that has not yet been bound, then immediately waits on the response for that message, then the application may hang, as the original message may have been dropped.
However, many application may find it easier to push features such as reliable message delivery into a custom transport, leaving the application only having to concern itself with the messages being delivered rather than how they arrive.
The main abstractions common to all transports:
Endpoint
s may not receive messages until eitherbind
has been called on an availableTransport
, or abindName
has been called on theEndpoint
. The latter is typically useful forEndpoint
s that originate connections but do not accept them directly.- A
Connection
defines a bi-directional pathway for messages to flow betweenEndpoint
s. The initiator of the connection is a client, and the destination for the connection is a server. ServerEndpoint
s may have to have calledbind
on theTransport
before being able to accept connections or receive messages; a client only has to have calledbindName
in order to receive responses from the server. - Client's proactively attempt to maintain
Connection
s to the server; in the event a server breaks the connection (other because of a crash or deliberate exit), the client will continue to restore the connection. Connection
s essentially define the topology over which messages will propagate betweenEndpoint
s.
- data Transport = Transport {}
- data TransportException
- data Dispatcher = Dispatcher {}
- dispatcher :: Mailboxes -> Endpoint -> IO Dispatcher
- type Mailboxes = TVar (Map Name (Mailbox Message))
- pullMessage :: Mailboxes -> Name -> STM Message
- dispatchMessage :: Mailboxes -> Name -> Message -> STM ()
- withTransport :: IO Transport -> (Transport -> IO a) -> IO a
- withEndpoint :: Transport -> Endpoint -> IO a -> IO a
- data Binding = Binding {
- bindingName :: Name
- unbind :: IO ()
- withBinding :: Transport -> Endpoint -> Name -> IO a -> IO a
- withBinding2 :: Transport -> (Endpoint, Name) -> (Endpoint, Name) -> IO a -> IO a
- withBinding3 :: Transport -> (Endpoint, Name) -> (Endpoint, Name) -> (Endpoint, Name) -> IO a -> IO a
- withBinding4 :: Transport -> (Endpoint, Name) -> (Endpoint, Name) -> (Endpoint, Name) -> (Endpoint, Name) -> IO a -> IO a
- data Connection = Connection {
- disconnect :: IO ()
- withConnection :: Transport -> Endpoint -> Name -> IO a -> IO a
- withConnection2 :: Transport -> Endpoint -> Name -> Name -> IO a -> IO a
- withConnection3 :: Transport -> Endpoint -> Name -> Name -> Name -> IO a -> IO a
- withConnection4 :: Transport -> Endpoint -> Name -> Name -> Name -> Name -> IO a -> IO a
- withConnections :: Transport -> Endpoint -> [Name] -> IO a -> IO a
- withCompleteNetwork :: Transport -> [Name] -> Endpoint -> Name -> IO a -> IO a
Transport
data TransportException Source #
An exception encountered by a Transport
.
data Dispatcher Source #
A Dispatcher
encapsulates a Transport
s interaction with an Endpoint
for outbound message flow.
dispatcher :: Mailboxes -> Endpoint -> IO Dispatcher Source #
Wraps in a continually repeating call to dispatchMessage
in a Dispatcher
so that dispatching
can be stopped when no longer needed.
dispatchMessage :: Mailboxes -> Name -> Message -> STM () Source #
A simple function to multiplex messages (each wrapped in an Envelope
) in the endpointOutbound
mailbox of an Endpoint
to one or more Mailboxes
by extract the messageDestination
from the Envelope
and
finding or creating a Mailbox
containing messages only for that destination. This is often useful for Transport
s,
who then only have to monitor a specific Mailbox
to know when there are messages to send to a particular destination.
withTransport :: IO Transport -> (Transport -> IO a) -> IO a Source #
Within the body of the function, ensures that Message
s are dispatched as necessary.
withEndpoint :: Transport -> Endpoint -> IO a -> IO a Source #
Within the body of the function, ensure that there is a Dispatcher
for the Endpoint
.
Binding | |
|
withBinding3 :: Transport -> (Endpoint, Name) -> (Endpoint, Name) -> (Endpoint, Name) -> IO a -> IO a Source #
withBinding4 :: Transport -> (Endpoint, Name) -> (Endpoint, Name) -> (Endpoint, Name) -> (Endpoint, Name) -> IO a -> IO a Source #
data Connection Source #
Connections are bi-directional pathways for exchanging Message
s with another Endpoint
that is bound to a specific Name
on a shared Transport
.
Connection | |
|
withConnection :: Transport -> Endpoint -> Name -> IO a -> IO a Source #
A helper for ensuring that a Connection
is maintained during execution of a function.
withConnection2 :: Transport -> Endpoint -> Name -> Name -> IO a -> IO a Source #
A helper for ensuring that 2 Connection
s are maintained during execution of a function.
withConnection3 :: Transport -> Endpoint -> Name -> Name -> Name -> IO a -> IO a Source #
A helper for ensuring that 3 Connection
s are maintained during execution of a function.