-
Notifications
You must be signed in to change notification settings - Fork 28
/
README.labs.txt
64 lines (40 loc) · 2.67 KB
/
README.labs.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Labs
====
There are 2 labs: a chat and a replicated hashmap.
Both labs should be created under src/org/lab, e.g. src/org/lab/ChatDemo.java.
To work on a demo, it is recommended to use an IDE. The sources are in ./lib, e.g. ./lib/jgroups-x.y.z.Final-sources.jar.
To compile, simply run 'ant' in the root directory (workshop).
To run a demo (e.g. ChatDemo): bin/run.sh org.lab.ChatDemo <args>.
ChatDemo
--------
This demo reads a line of input from stdin and sends it to all cluster nodes. Use Util.readLine(System.in) to read input.
The chat should print when new members join the cluster, or members leave or crash.
It should also print received chat messages to stdout.
The configuration file to be used should be config.xml (which is on the classpath, in ./conf/config.xml).
A chat node can be run with: bin/run.sh org.lab.ChatDemo -props config.xml -name <name>
ReplicatedStockServer
---------------------
A hashmap of stocks (strings) and their current values (doubles), replicated across a cluster. Any change to a stock
should be via a remote procedure call to all cluster nodes (using RpcDispatcher).
There's a non-replicated StockServer sample program (containing the basic structire and event loop).
This can be copied and renamed to ReplicatedStockServer.
There should be methods _setStock(String name, double val) and _removeStock(String name) which update or remove stocks
respectively. These are called via RpcDispatcher.
A node has an event loop which looks like this:
[1] Show stocks [2] Get quote [3] Set quote [4] Remove quote [x] Exit
[1] Displays all stocks in the local hashmap.
[2] Gets a value for a given stock (also local)
[3] Sets a value for a stock. This triggers an RpcDispatcher.callRemoteMethods() call, which calls _setStock() in all
cluster nodes. On invocation of _setStock(), each cluster node adds the shipped data into its hashmap.
[4] Removes a stock from all hashmaps of all cluster nodes. Also an RPC calling _removeStock();
We'll create a JChannel, then an RpcDispatcher over it, and finally call JChannel.connect(clustername).
The, JChannel.getState() needs to be called, to transfer state (the contents of the local hashmap) to the newly
joined node. This looks roughly as follows:
channel=new JChannel("config.xml);
disp=new RpcDispatcher(channel, this, this, this);
channel.connect("stocks");
disp.start();
channel.getState(null, 30000); // fetches the state from the coordinator
Methods getState() and setState() of ReceiverAdapter need to be overwritten to implement the state transfer. Also,
pbcast.STATE needs to be on the stack (config.xml already contains it).
The server can be run with bin/run.sh org.lab.ReplicatedStockServer -props config.xml.