| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Pinch.Server
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.
Constructors
| ThriftServer | |
Fields
| |
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.
Constructors
| CallHandler :: (Pinchable c, Tag c ~ TStruct, Pinchable r, Tag r ~ TStruct) => (Context -> c -> IO r) -> Handler | Handle normal call requests. Must return a result. |
| OnewayHandler :: (Pinchable c, Tag c ~ TStruct) => (Context -> c -> IO ()) -> Handler | Handle oneway requests. Cannot return any result. |
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.
Constructors
| ThriftError Text |
Instances
| Eq ThriftError Source # | |
Defined in Pinch.Internal.Exception | |
| Show ThriftError Source # | |
Defined in Pinch.Internal.Exception Methods showsPrec :: Int -> ThriftError -> ShowS # show :: ThriftError -> String # showList :: [ThriftError] -> ShowS # | |
| Exception ThriftError Source # | |
Defined in Pinch.Internal.Exception Methods toException :: ThriftError -> SomeException # fromException :: SomeException -> Maybe ThriftError # displayException :: ThriftError -> String # | |
A bi-directional channel to read/write Thrift messages.
Constructors
| Channel | |
Fields
| |
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 #
Constructors
| ServiceName Text |
Instances
| Eq ServiceName Source # | |
Defined in Pinch.Internal.RPC | |
| IsString ServiceName Source # | |
Defined in Pinch.Internal.RPC Methods fromString :: String -> ServiceName # | |
| Hashable ServiceName Source # | |
Defined in Pinch.Internal.RPC | |
| ContextItem ServiceName Source # | |
Defined in Pinch.Server | |
Arguments
| :: 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 ThriftServers.
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.