1. Hello, All
Write an Emerald program that writes the message
Hello, All
at each active node in the network.
Let the Emerald-file be called helloall.m
, and compile it as
helloall.x
.
To start up several nodes on your local machine, open a couple
terminals. In the first, type emx -R
. In the second, third, etc.
type emx -Rlocalhost
. In the last one, type emx -Rlocalhost
helloall.x
.
The string “localhost” is the hostname of the Emerald server to connect the node to.
Hint: A Node
object has a method getStdOut
, which allows you to
issue writes on the node's standard output stream.
2. Echo
Write an Emerald program that echo's the received on stdin to all active nodes. Let the program end, if it has received the keyword “exit” on stdin.
Let the Emerald-file be called echo.m
, and compile it as echo.x
.
Hint: You can read a string from stdin using stdin.getstring
,
however, that might come with a trailing line break due to the user
pressing Enter. For the purposes of this exercise, you may assume that
the user always does so. Hence, you might appreciate the following
auxiliary functions:
function stripLast [ i : String ] -> [ o : String ]
o <- i.getSlice[ 0, i.length - 1 ]
end stripLast
function readline -> [ o : String ]
o <- self.stripLast [ stdin.getstring ]
end readline
What happens if some of the nodes become unreachable? Would your
program crash? Test this. Try and mitigate for this using the
unavailable
construction.
3. The Moving Man
Create a program where an object visits each node and collects their
Node identification. “Node identification” here consists of a
concatenation of the node Name
and IncarnationTime
(both
properties of a Node
object).
Let the Emerald-file be called movingman.m
, and compile it as
movingman.x
.
Hint: Begin with a moving man that doesn't actually move. The
NodeList
yielded by the activenodes
property of the current node,
is indeed already a list of Node
objects.
Again, what happens if some of the nodes become unreachable? Would
your program crash? Test this. Try and mitigate for this using the
unavailable
construction.
4. Watchdog
Watchdog should check the Emerald nodes if they have gone down or is up again. Create a program where there are more machines that are up, and crash some of them to see if you get notified which node crashed (printout a node id as above).
Let the Emerald-file be called watchdog.m
, and compile it as
watchdog.x
.
5. Keywords
After completing these exercises, you should be familiar with the following keywords. If not, read up on them in the language report.
Node
NodeList
fix
unfix
refix
unavailable
delay
Time
6. Tips
You can use the $
as syntactic sugar for .get
.
For instance, you can write eric$name
in place of eric.getname
above.