Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Node = Node {
- nodeHost :: HostName
- nodePort :: Int
- connection :: Maybe (MVar Pool)
- nodeServices :: Service
- newtype Cloud a = Cloud {}
- runCloud :: Cloud a -> TransIO a
- tlsHooks :: IORef (SData -> ByteString -> IO (), SData -> IO ByteString, Socket -> ByteString -> TransIO (), String -> Socket -> ByteString -> TransIO ())
- sendTLSData :: SData -> ByteString -> IO ()
- local :: Loggable a => TransIO a -> Cloud a
- runCloudIO :: Typeable a => Cloud a -> IO (Maybe a)
- runCloudIO' :: Typeable a => Cloud a -> IO (Maybe a)
- onAll :: TransIO a -> Cloud a
- lazy :: TransIO a -> Cloud a
- loggedc :: Loggable a => Cloud a -> Cloud a
- loggedc' :: Loggable a => Cloud a -> Cloud a
- lliftIO :: Loggable a => IO a -> Cloud a
- localIO :: Loggable a => IO a -> Cloud a
- fullStop :: TransIO stop
- beamTo :: Node -> Cloud ()
- forkTo :: Node -> Cloud ()
- callTo :: Loggable a => Node -> Cloud a -> Cloud a
- callTo' :: (Show a, Read a, Typeable a) => Node -> Cloud a -> Cloud a
- atRemote :: Loggable a => Cloud a -> Cloud a
- runAt :: Loggable a => Node -> Cloud a -> Cloud a
- single :: TransIO a -> TransIO a
- unique :: a -> TransIO ()
- wormhole :: Loggable a => Node -> Cloud a -> Cloud a
- type JSString = String
- pack :: a -> a
- teleport :: Cloud ()
- copyData :: (Typeable * b, Read b, Show b) => b -> Cloud b
- putMailbox :: Typeable a => a -> TransIO ()
- putMailbox' :: (Typeable b, Ord b, Typeable a) => b -> a -> TransIO ()
- newMailbox :: MailboxId -> TransIO ()
- errorMailBox :: a
- getMailbox :: Typeable a => TransIO a
- getMailbox' :: (Typeable b, Ord b, Typeable a) => b -> TransIO a
- cleanMailbox :: Typeable a => a -> TransIO ()
- cleanMailbox' :: Typeable a => Int -> a -> TransIO ()
- clustered :: Loggable a => Cloud a -> Cloud a
- mclustered :: (Monoid a, Loggable a) => Cloud a -> Cloud a
- callNodes :: (Typeable * a, Typeable * a1, Read a, Read a1, Show a, Show a1) => (Cloud a1 -> Cloud a -> Cloud a) -> Cloud a -> Cloud a1 -> Cloud a
- callNodes' :: (Typeable * a1, Typeable * a, Read a1, Read a, Show a1, Show a) => [Node] -> (Cloud a1 -> Cloud a -> Cloud a) -> Cloud a -> Cloud a1 -> Cloud a
- sendRaw :: MonadIO m => Connection -> ByteString -> m ()
- data NodeMSG
- msend :: MonadIO m => Connection -> StreamData NodeMSG -> m ()
- mread :: Loggable a => Connection -> TransIO (StreamData a)
- parallelReadHandler :: Loggable a => TransIO (StreamData a)
- getWebServerNode :: TransIO Node
- read' :: (Typeable * t, Read t) => String -> t
- mclose :: Connection -> IO ()
- mconnect :: Node -> TransIO Connection
- data ConnectionError = ConnectionError String Node
- connectTo' :: Int -> HostName -> PortID -> IO Socket
- type Blocked = MVar ()
- type BuffSize = Int
- data ConnectionData
- = Node2Node { }
- | TLSNode2Node {
- tlscontext :: SData
- | Node2Web { }
- | Self
- | Relay Connection Node
- data MailboxId = (Typeable a, Ord a) => MailboxId a TypeRep
- data Connection = Connection {}
- defConnection :: MonadIO m => m Connection
- setBuffSize :: Int -> TransIO ()
- getBuffSize :: TransIO BuffSize
- listen :: Node -> Cloud ()
- relay :: StreamData NodeMSG -> TransIO ()
- nat :: Node -> Node -> Node -> [Node] -> (Node, Node)
- listenNew :: PortNumber -> Connection -> TransIO (StreamData NodeMSG)
- rsetHost :: IORef Bool
- listenResponses :: Loggable a => TransIO (StreamData a)
- type IdClosure = Int
- newtype Closure = Closure IdClosure
- execLog :: StreamData NodeMSG -> TransIO ()
- type Pool = [Connection]
- type Package = String
- type Program = String
- type Service = [(Package, Program)]
- data ParseContext a = IsString a => ParseContext (IO a) a
- readFrom :: Connection -> IO ByteString
- toStrict :: ByteString -> ByteString
- makeWSStreamFromConn :: Connection -> IO Stream
- makeWebsocketConnection :: MonadIO m => Connection -> ByteString -> Headers -> m Connection
- servePages :: (t, ByteString, [(CI ByteString, b)]) -> TransIO ()
- api :: TransIO ByteString -> Cloud ()
- isWebSocketsReq :: [(CI ByteString, b)] -> Bool
- data HTTPMethod
- receiveHTTPHead :: TransIO (ByteString, ByteString, [(CI ByteString, ByteString)])
- dropSpaces :: TransIO ()
- dropChar :: TransIO ()
- endline :: Char -> Bool
- type PostParams = [(ByteString, String)]
- parsePostUrlEncoded :: TransIO PostParams
- getString :: TransIO ByteString
- tTakeWhile :: (Char -> Bool) -> TransIO ByteString
- tTakeWhile' :: (Char -> Bool) -> TransIO ByteString
- parse :: (ByteString -> (b, ByteString)) -> TransIO b
- withData :: (ByteString -> TransIO (a, ByteString)) -> TransIO a
- giveData :: TransIO ByteString
- isBrowserInstance :: Bool
- emptyPool :: MonadIO m => m (MVar Pool)
- createNodeServ :: HostName -> Int -> Service -> IO Node
- createNode :: HostName -> Int -> IO Node
- createWebNode :: IO Node
- nodeList :: TVar [Node]
- errorMyNode :: [Char] -> a
- getMyNode :: TransIO Node
- getNodes :: MonadIO m => m [Node]
- getEqualNodes :: TransIO [Node]
- matchNodes :: MonadIO m => ((Package, Program) -> Bool) -> m [[(Package, Program)]]
- addNodes :: [Node] -> TransIO ()
- fixNode :: MonadIO m => Node -> m Node
- setNodes :: MonadIO m => [Node] -> m ()
- shuffleNodes :: MonadIO m => m [Node]
- connect :: Node -> Node -> Cloud ()
- connect' :: Node -> Cloud ()
Documentation
runCloud :: Cloud a -> TransIO a Source #
Execute a distributed computation inside a TransIO computation.
All the computations in the TransIO monad that enclose the cloud computation must be logged
tlsHooks :: IORef (SData -> ByteString -> IO (), SData -> IO ByteString, Socket -> ByteString -> TransIO (), String -> Socket -> ByteString -> TransIO ()) Source #
sendTLSData :: SData -> ByteString -> IO () Source #
runCloudIO :: Typeable a => Cloud a -> IO (Maybe a) Source #
Run a distributed computation inside the IO monad. Enables asynchronous
console input (see keep
).
runCloudIO' :: Typeable a => Cloud a -> IO (Maybe a) Source #
Run a distributed computation inside the IO monad with no console input.
onAll :: TransIO a -> Cloud a Source #
alternative to local
It means that if the computation is translated to other node
this will be executed again if this has not been executed inside a local
computation.
onAll foo local foo' local $ do bar runCloud $ do onAll baz runAt node .... callTo node' .....
Here foo will be executed in node' but foo' bar and baz don't.
However foo bar and baz will e executed in node.
fullStop :: TransIO stop Source #
stop the current computation and does not execute any alternative computation
beamTo :: Node -> Cloud () Source #
continue the execution in a new node
all the previous actions from listen
to this statement must have been logged
forkTo :: Node -> Cloud () Source #
execute in the remote node a process with the same execution state
callTo :: Loggable a => Node -> Cloud a -> Cloud a Source #
open a wormhole to another node and executes an action on it. currently by default it keep open the connection to receive additional requests and responses (streaming)
callTo' :: (Show a, Read a, Typeable a) => Node -> Cloud a -> Cloud a Source #
A connectionless version of callTo for long running remote calls
atRemote :: Loggable a => Cloud a -> Cloud a Source #
Within an open connection to other node opened by wormhole
, it run the computation in the remote node and return
the result back to the original node.
single :: TransIO a -> TransIO a Source #
run a single thread with that action for each connection created. When the same action is re-executed within that connection, all the threads generated by the previous execution are killed
box <- foo r <- runAt node . local . single $ getMailbox box localIO $ print r
if foo return differnt mainbox indentifiers, the above code would print the messages of the last one. Without single, it would print the messages of all of them.
unique :: a -> TransIO () Source #
run an unique continuation for each connection. The first thread that execute unique
is
executed for that connection. The rest are ignored.
wormhole :: Loggable a => Node -> Cloud a -> Cloud a Source #
A wormhole opens a connection with another node anywhere in a computation.
teleport
uses this connection to translate the computation back and forth between the two nodes connected
copyData :: (Typeable * b, Read b, Show b) => b -> Cloud b Source #
copy a session data variable from the local to the remote node. If there is none set in the local node, The parameter is the default value. In this case, the default value is also set in the local node.
putMailbox :: Typeable a => a -> TransIO () Source #
write to the mailbox
Mailboxes are node-wide, for all processes that share the same connection data, that is, are under the
same listen
or connect
while EVars are only visible by the process that initialized it and his children.
Internally, the mailbox is in a well known EVar stored by listen
in the Connection
state.
putMailbox' :: (Typeable b, Ord b, Typeable a) => b -> a -> TransIO () Source #
write to a mailbox identified by an Integer besides the type
newMailbox :: MailboxId -> TransIO () Source #
errorMailBox :: a Source #
getMailbox :: Typeable a => TransIO a Source #
get messages from the mailbox that matches with the type expected.
The order of reading is defined by readTChan
This is reactive. it means that each new message trigger the execution of the continuation
each message wake up all the getMailbox
computations waiting for it.
getMailbox' :: (Typeable b, Ord b, Typeable a) => b -> TransIO a Source #
read from a mailbox identified by a number besides the type
cleanMailbox :: Typeable a => a -> TransIO () Source #
delete all subscriptions for that mailbox expecting this kind of data
cleanMailbox' :: Typeable a => Int -> a -> TransIO () Source #
clean a mailbox identified by an Int and the type
clustered :: Loggable a => Cloud a -> Cloud a Source #
execute a Transient action in each of the nodes connected.
The response of each node is received by the invoking node and processed by the rest of the procedure. By default, each response is processed in a new thread. To restrict the number of threads use the thread control primitives.
this snippet receive a message from each of the simulated nodes:
main = keep $ do let nodes= map createLocalNode [2000..2005] addNodes nodes (foldl (<|>) empty $ map listen nodes) <|> return () r <- clustered $ do Connection (Just(PortNumber port, _, _, _)) _ <- getSData return $ "hi from " ++ show port++ "\n" liftIO $ putStrLn r where createLocalNode n= createNode "localhost" (PortNumber n)
callNodes :: (Typeable * a, Typeable * a1, Read a, Read a1, Show a, Show a1) => (Cloud a1 -> Cloud a -> Cloud a) -> Cloud a -> Cloud a1 -> Cloud a Source #
callNodes' :: (Typeable * a1, Typeable * a, Read a1, Read a, Show a1, Show a) => [Node] -> (Cloud a1 -> Cloud a -> Cloud a) -> Cloud a -> Cloud a1 -> Cloud a Source #
sendRaw :: MonadIO m => Connection -> ByteString -> m () Source #
msend :: MonadIO m => Connection -> StreamData NodeMSG -> m () Source #
mread :: Loggable a => Connection -> TransIO (StreamData a) Source #
parallelReadHandler :: Loggable a => TransIO (StreamData a) Source #
mclose :: Connection -> IO () Source #
data ConnectionError Source #
data ConnectionData Source #
data Connection Source #
defConnection :: MonadIO m => m Connection Source #
setBuffSize :: Int -> TransIO () Source #
listenNew :: PortNumber -> Connection -> TransIO (StreamData NodeMSG) Source #
listenResponses :: Loggable a => TransIO (StreamData a) Source #
type Pool = [Connection] Source #
data ParseContext a Source #
IsString a => ParseContext (IO a) a |
readFrom :: Connection -> IO ByteString Source #
toStrict :: ByteString -> ByteString Source #
makeWebsocketConnection :: MonadIO m => Connection -> ByteString -> Headers -> m Connection Source #
servePages :: (t, ByteString, [(CI ByteString, b)]) -> TransIO () Source #
isWebSocketsReq :: [(CI ByteString, b)] -> Bool Source #
receiveHTTPHead :: TransIO (ByteString, ByteString, [(CI ByteString, ByteString)]) Source #
dropSpaces :: TransIO () Source #
type PostParams = [(ByteString, String)] Source #
tTakeWhile :: (Char -> Bool) -> TransIO ByteString Source #
tTakeWhile' :: (Char -> Bool) -> TransIO ByteString Source #
parse :: (ByteString -> (b, ByteString)) -> TransIO b Source #
withData :: (ByteString -> TransIO (a, ByteString)) -> TransIO a Source #
bring the data of a parse context as a lazy byteString to a parser and actualize the parse context with the result
giveData :: TransIO ByteString Source #
bring the data of the parse context as a lazy byteString
isBrowserInstance :: Bool Source #
Returns True
if we are running in the browser.
createNodeServ :: HostName -> Int -> Service -> IO Node Source #
Create a node from a hostname (or IP address), port number and a list of services.
createWebNode :: IO Node Source #
errorMyNode :: [Char] -> a Source #
getMyNode :: TransIO Node Source #
Return the local node i.e. the node where this computation is running.
getEqualNodes :: TransIO [Node] Source #
shuffleNodes :: MonadIO m => m [Node] Source #
Shuffle the list of cluster nodes and return the shuffled list.
connect :: Node -> Node -> Cloud () Source #
Add a node (first parameter) to the cluster using a node that is already part of the cluster (second parameter). The added node starts listening for incoming connections and the rest of the computation is executed on this newly added node.
connect' :: Node -> Cloud () Source #
Reconcile the list of nodes in the cluster using a remote node already part of the cluster. Reconciliation results in each node in the cluster having exactly the same list of nodes.