+/EE360P

distributed systems

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

vijaygarg1init99f4f39

master
662 B26 linesraw
1package clocks;
2public class DirectClock {
3    public int[] clock;
4    int myId;
5    public DirectClock(int numProc, int id) {
6        myId = id;
7        clock = new int[numProc];
8        for (int i = 0; i < numProc; i++) clock[i] = 0;
9        clock[myId] = 1;
10    }
11    public int getValue(int i) {
12        return clock[i];
13    }
14    public void tick() {
15        clock[myId]++;
16    }
17    public void sendAction() {
18        // sentValue = clock[myId];
19        tick();
20    }
21    public void receiveAction(int sender, int sentValue) {
22        clock[sender] = Math.max(clock[sender], sentValue);
23        clock[myId] = Math.max(clock[myId], sentValue) + 1;
24    }
25}
26