Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype ThriftServer = ThriftServer {
- unThriftServer :: forall a. Context -> Request a -> IO a
- createServer :: (Text -> Maybe Handler) -> ThriftServer
- data Handler where
- data Request out where
- runConnection :: Context -> ThriftServer -> Channel -> IO ()
- data ThriftError = ThriftError Text
- data Channel = Channel {}
- createChannel :: Connection c => c -> (c -> IO Transport) -> Protocol -> IO Channel
- createChannel1 :: (Transport, Protocol) -> (Transport, Protocol) -> Channel
- data Context
- class Typeable a => ContextItem a
- addToContext :: forall i. ContextItem i => i -> Context -> Context
- lookupInContext :: forall i. ContextItem i => Context -> Maybe i
- multiplex :: [(ServiceName, ThriftServer)] -> ThriftServer
- newtype ServiceName = ServiceName Text
- onError :: Exception e => (e -> Maybe a) -> (a -> IO Message) -> (a -> IO ()) -> ThriftServer -> ThriftServer
- mapRequestMessage :: (Message -> Message) -> Request o -> Request o
- getRequestMessage :: Request o -> Message
- mkApplicationExceptionReply :: Message -> ApplicationException -> Message
Thrift Server creation
newtype ThriftServer Source #
A Thrift
server. Takes the context and the request as input and may produces a reply message.
ThriftServer | |
|
createServer :: (Text -> Maybe Handler) -> ThriftServer Source #
Creates a new thrift server processing requests with the function f
.
By default, if processing a oneway call fails a haskell exception is thrown which will likely
terminate the guilty connection. You may use the onError
combinator to handle this case
more gracefully.
Create a handler for a request type.
Running a Thrift Server
runConnection :: Context -> ThriftServer -> Channel -> IO () Source #
Run a Thrift server for a single connection.
data ThriftError Source #
An error occured while processing a thrift call. Signals errors like premature EOF, Thrift protocol parsing failures etc.
Instances
Eq ThriftError Source # | |
Defined in Pinch.Internal.Exception (==) :: ThriftError -> ThriftError -> Bool # (/=) :: ThriftError -> ThriftError -> Bool # | |
Show ThriftError Source # | |
Defined in Pinch.Internal.Exception showsPrec :: Int -> ThriftError -> ShowS # show :: ThriftError -> String # showList :: [ThriftError] -> ShowS # | |
Exception ThriftError Source # | |
Defined in Pinch.Internal.Exception |
A bi-directional channel to read/write Thrift messages.
Channel | |
|
createChannel :: Connection c => c -> (c -> IO Transport) -> Protocol -> IO Channel Source #
Creates a channel using the same transport/protocol for both directions.
createChannel1 :: (Transport, Protocol) -> (Transport, Protocol) -> Channel Source #
Creates a channel.
Thrift Server context
The context can be used to pass data from the environment to the thrift server functions. For example, you could pass the remote host name to the server to use it for logging purposes.
Allows passing context information to a ThriftServer
.
The context is indexed by type.
class Typeable a => ContextItem a Source #
Instances
ContextItem ServiceName Source # | |
Defined in Pinch.Server |
addToContext :: forall i. ContextItem i => i -> Context -> Context Source #
Adds a new item to the context. If an item with the same type is already part of the context, it will be overwritten.
lookupInContext :: forall i. ContextItem i => Context -> Maybe i Source #
Lookup a value in the context.
Middlewares
multiplex :: [(ServiceName, ThriftServer)] -> ThriftServer Source #
Multiplex multiple services into a single ThriftServer
.
The service name is added to the Context
and may be retrieved using `lookupInContext @ServiceName ctx`.
newtype ServiceName Source #
Instances
Eq ServiceName Source # | |
Defined in Pinch.Internal.RPC (==) :: ServiceName -> ServiceName -> Bool # (/=) :: ServiceName -> ServiceName -> Bool # | |
IsString ServiceName Source # | |
Defined in Pinch.Internal.RPC fromString :: String -> ServiceName # | |
Hashable ServiceName Source # | |
Defined in Pinch.Internal.RPC hashWithSalt :: Int -> ServiceName -> Int # hash :: ServiceName -> Int # | |
ContextItem ServiceName Source # | |
Defined in Pinch.Server |
:: Exception e | |
=> (e -> Maybe a) | Select exceptions to handle. |
-> (a -> IO Message) | Error handler for normal method calls. |
-> (a -> IO ()) | Error handler for oneway calls. |
-> ThriftServer | |
-> ThriftServer |
Add error handlers to a ThriftServer
. Exceptions are caught and not re-thrown, but you may do
so by calling ioThrow
yourself.
Helper functions
Functions mostly useful for defining custom ThriftServer
s.
mapRequestMessage :: (Message -> Message) -> Request o -> Request o Source #
Map the message contained in the request.
getRequestMessage :: Request o -> Message Source #
Extract the message contained in the request.
mkApplicationExceptionReply :: Message -> ApplicationException -> Message Source #
Builds an exception reply given the corresponding request message.