Safe Haskell | None |
---|
Non monadic low level support stuff for the MFlow application server.
(See MFlow.Form for the higher level interfaces)
it implements an scheduler of queued Processable
messages that are served according with
the source identification and the verb invoked.
The scheduler executed the appropriate workflow (using the workflow package).
The workflow may send additional messages to the source, identified by a Token
. The computation state is optionally logged and recovered.
The message communication is trough polimorphic, monoidal queues. There is no asumption about message codification, so instantiations of this scheduler for different infrastructures is possible, including non-Web based ones as long as they support or emulate cookies.
MFlow.Hack is an instantiation for the Hack interface in a Web context.
MFlow.Wai is a instantiation for the WAI interface.
MFlow.Forms implements a monadic type safe interface with composabe widgets and a higher comunication interface.
MFlow.Forms.XHtml is an instantiation for the Text.XHtml format
MFlow.Forms.HSP is an instantiation for the Haskell Server Pages format
In order to manage resources, there are primitives that kill the process and its state after a timeout.
All these details are hidden in the monad of MFlow.Forms that provides an higher level interface.
Fragment based streaming sendFragment
sendEndFragment
are provided only at this level.
stateless
and transient
server processeses are also possible. stateless
are request-response
with no intermediate messaging dialog. transient
processes have no persistent
state, so they restart anew after a timeout or a crash.
- type Params = [(String, String)]
- type Workflow m = WF Stat m
- data HttpData
- class Processable a where
- class ToHttpData a where
- toHttpData :: a -> HttpData
- data Token = Token {}
- type ProcList = WorkflowList IO Token ()
- flushRec :: Token -> IO ()
- receive :: Typeable a => Token -> IO a
- receiveReq :: Token -> IO Req
- receiveReqTimeout :: Int -> Integer -> Token -> IO Req
- send :: ToHttpData a => Token -> a -> IO ()
- sendFlush :: ToHttpData a => Token -> a -> IO ()
- sendFragment :: ToHttpData a => Token -> a -> IO ()
- sendEndFragment :: ToHttpData a => Token -> a -> IO ()
- addMessageFlows :: [([Char], Token -> Workflow IO ())] -> IO ()
- getMessageFlows :: IO (Map String (Token -> Workflow IO ()))
- transient :: (Token -> IO ()) -> Token -> Workflow IO ()
- stateless :: ToHttpData b => (Params -> IO b) -> Token -> Workflow IO ()
- anonymous :: [Char]
- noScript :: [Char]
- hlog :: Handle
- setNotFoundResponse :: MonadIO m => (ByteString -> ByteString) -> m ()
- getNotFoundResponse :: ByteString -> ByteString
- btag :: String -> Attribs -> ByteString -> ByteString
- bhtml :: Attribs -> ByteString -> ByteString
- bbody :: Attribs -> ByteString -> ByteString
- type Attribs = [(String, String)]
- addTokenToList :: Token -> IO ()
- deleteTokenInList :: Token -> IO ()
- msgScheduler :: (Typeable a, Processable a) => a -> IO (HttpData, ThreadId)
Documentation
type Workflow m = WF Stat m
class Processable a whereSource
class ToHttpData a whereSource
toHttpData :: a -> HttpDataSource
a Token identifies a flow that handle messages. The scheduler compose a Token with every Processable
message that arrives and send the mesage to the appropriate flow.
type ProcList = WorkflowList IO Token ()Source
List of (wfname, workflow) pairs, to be scheduled depending on the message's pwfname
low level comunication primitives. Use ask
instead
receiveReq :: Token -> IO ReqSource
send :: ToHttpData a => Token -> a -> IO ()Source
send a complete response
sendFlush :: ToHttpData a => Token -> a -> IO ()Source
sendFragment :: ToHttpData a => Token -> a -> IO ()Source
send a response fragment. Useful for streaming. the last packet must sent trough send
sendEndFragment :: ToHttpData a => Token -> a -> IO ()Source
Flow configuration
addMessageFlows :: [([Char], Token -> Workflow IO ())] -> IO ()Source
add a list of flows to be scheduled. Each entry in the list is a pair (path, flow)
transient :: (Token -> IO ()) -> Token -> Workflow IO ()Source
Executes a monadic computation that send and receive messages, but does not store its state in permanent storage. The process once stopped, will restart anew
stateless :: ToHttpData b => (Params -> IO b) -> Token -> Workflow IO ()Source
executes a simple monadic computation that receive the params and return a response
It is used with addMessageFlows
hackMessageFlow
or waiMessageFlow
setNotFoundResponse :: MonadIO m => (ByteString -> ByteString) -> m ()Source
set the 404 not found response
ByteString tags
very basic but efficient tag formatting
btag :: String -> Attribs -> ByteString -> ByteStringSource
Writes a XML tag in a ByteString. It is the most basic form of formatting. For more sophisticated formatting , use MFlow.Forms.XHtml or MFlow.Forms.HSP.
bhtml :: Attribs -> ByteString -> ByteStringSource
bhtml ats v= btag "html" ats v
bbody :: Attribs -> ByteString -> ByteStringSource
bbody ats v= btag "body" ats v
internal use
addTokenToList :: Token -> IO ()Source
deleteTokenInList :: Token -> IO ()Source
msgScheduler :: (Typeable a, Processable a) => a -> IO (HttpData, ThreadId)Source
The scheduler creates a Token with every Processable
message that arrives and send the mesage to the appropriate flow, get the response
and return it.