1. 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.
2. 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.
3. 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
.
4. 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
5. Tips
You can use the $
as syntactic sugar for .get
.
For instance, you can write eric$name
in place of eric.getname
above.