+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

vijaygarg1init7910ba6

master
1.4 KiB41 linesraw
1package snapshot;
2import java.util.*;
3import dist.*;
4public class RecvCamera  extends MyProcess implements Camera {
5    Color myColor = Color.white;
6    boolean closed[];   
7    LinkedList chan[] = null;
8    int n = neighbors.size();
9    public RecvCamera(MsgHandler initComm) {
10        super(initComm);
11        closed = new boolean[n]; Arrays.fill(closed, false);
12        chan = new LinkedList[n];
13        for (int i =0; i < n; i++) 
14                chan[i] = new LinkedList();        
15    }
16    public synchronized void globalState() {
17        myColor = Color.red;
18        ((CamUser) app).localState(); // record local State;
19        sendMsg(neighbors,"marker", myId);  // send Markers
20    }
21    public synchronized void handleMsg(Msg m, int src, String tag) {
22    	int nid = neighbors.indexOf(src);
23        if (tag.equals("marker")) {
24            if (myColor == Color.white) globalState();
25            closed[nid] = true;
26            if (isDone())
27                for (int i = 0; i < n; i++)
28                         System.out.println(chan[i].toString());
29        } else { // application message
30            if ((myColor == Color.red) && (!closed[nid]))
31                chan[nid].add(m);
32            app.handleMsg(m, src, tag); // give it to app
33        }
34    }
35    boolean isDone() {
36        if (myColor == Color.white) return false;
37        for (int i = 0; i < n; i++)
38            if (!closed[i]) return false;
39        return true;
40    }
41}