pinch-0.5.2.0: An alternative implementation of Thrift for Haskell.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Pinch.Server

Synopsis

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.

data Handler where Source #

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.

data Request out where Source #

A single request to a thrift server.

Constructors

RCall :: !Message -> Request Message 
ROneway :: !Message -> Request () 

Instances

Instances details
Show (Request out) Source # 
Instance details

Defined in Pinch.Server

Methods

showsPrec :: Int -> Request out -> ShowS #

show :: Request out -> String #

showList :: [Request out] -> ShowS #

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 

data Channel Source #

A bi-directional channel to read/write Thrift messages.

createChannel :: Connection c => c -> (c -> IO Transport) -> Protocol -> IO Channel Source #

Creates a channel using the same transport/protocol for both directions.

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.

data Context Source #

Allows passing context information to a ThriftServer. The context is indexed by type.

Instances

Instances details
Monoid Context Source # 
Instance details

Defined in Pinch.Server

Semigroup Context Source # 
Instance details

Defined in Pinch.Server

class Typeable a => ContextItem a Source #

Instances

Instances details
ContextItem ServiceName Source # 
Instance details

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

Instances details
IsString ServiceName Source # 
Instance details

Defined in Pinch.Internal.RPC

Eq ServiceName Source # 
Instance details

Defined in Pinch.Internal.RPC

Hashable ServiceName Source # 
Instance details

Defined in Pinch.Internal.RPC

ContextItem ServiceName Source # 
Instance details

Defined in Pinch.Server

onError Source #

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.