Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- initNode :: Loggable a => Cloud a -> TransIO a
- initNodeDef :: Loggable a => String -> Int -> Cloud a -> TransIO a
- initNodeServ :: Loggable a => Service -> String -> Int -> Cloud a -> TransIO a
- inputNodes :: Cloud empty
- simpleWebApp :: (Typeable a, Loggable a) => Integer -> Cloud a -> IO ()
- initWebApp :: Loggable a => Node -> Cloud a -> TransIO a
- onServer :: Cloud a -> Cloud a
- onBrowser :: Cloud a -> Cloud a
- atServer :: Loggable a => Cloud a -> Cloud a
- atBrowser :: Loggable a => Cloud a -> Cloud a
- runTestNodes :: [Int] -> Cloud ()
- showURL :: Cloud ()
Documentation
initNode :: Loggable a => Cloud a -> TransIO a Source #
ask in the console for the port number and initializes a node in the port specified
It needs the application to be initialized with keep
to get input from the user.
the port can be entered in the command line with "program -p start/PORT"
A node is also a web server that send to the browser the program if it has been
compiled to JavaScript with ghcjs. initNode
also initializes the web nodes.
This sequence compiles to JScript and executes the program with a node in the port 8080
ghc program.hs ghcjs program.hs -o static/out ./program -p start/myhost/8080
initNode
, when the application has been loaded and executed in the browser, will perform a wormhole
to his server node.
So the application run within this wormhole.
Since the code is executed both in server node and browser node, to avoid confusion and in order
to execute in a single logical thread, use onServer
for code that you need to execute only in the server
node, and onBrowser
for code that you need in the browser, although server code could call the browser
and vice-versa.
To invoke from browser to server and vice-versa, use atRemote
.
To translate the code from the browser to the server node, use teleport
.
inputNodes :: Cloud empty Source #
ask for nodes to be added to the list of known nodes. it also ask to connect to the node to get his list of known nodes. It returns empty. to input a node, enter "add" then the host and the port, the service description (if any) and "y" or "n" to either connect to that node and synchronize their lists of nodes or not.
A typical sequence of initiation of an application that includes initNode
and inputNodes
is:
program -p start/host/8000/add/host2/8001/n/add/host3/8005/y
"starthost8000" is read by initNode
. The rest is initiated by inputNodes
in this case two nodes are added.
the first of the two is not connected to synchronize their list of nodes. The second does.
simpleWebApp :: (Typeable a, Loggable a) => Integer -> Cloud a -> IO () Source #
executes the application in the server and the Web browser.
the browser must point to http://hostname:port where port is the first parameter.
It creates a wormhole to the server.
The code of the program after simpleWebApp
run in the browser unless teleport
translates the execution to the server.
To run something in the server and get the result back to the browser, use atRemote
This last also works in the other side; If the application was teleported to the server, atRemote
will
execute his parameter in the browser.
It is necesary to compile the application with ghcjs:
ghcjs program.js ghcjs program.hs -o static/out
./program
initWebApp :: Loggable a => Node -> Cloud a -> TransIO a Source #
use this instead of simpleWebApp when you have to do some initializations in the server prior to the initialization of the web server
onServer :: Cloud a -> Cloud a Source #
only executes the computaion if it is in the server, but the computation can call the browser. Otherwise return empty
onBrowser :: Cloud a -> Cloud a Source #
only execute if the the program is executing in the browser. The code inside can contain calls to the server. Otherwise return empty (so it stop the computation and may execute alternative computations).
atServer :: Loggable a => Cloud a -> Cloud a Source #
If the computation is running in the browser, translates i to the server and return back. If it is already in the server, just execute it
atBrowser :: Loggable a => Cloud a -> Cloud a Source #
If the computation is running in the server, translates i to the browser and return back. If it is already in the browser, just execute it