-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.java
More file actions
49 lines (30 loc) · 813 Bytes
/
Clock.java
File metadata and controls
49 lines (30 loc) · 813 Bytes
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
public class Clock {
public int clock;
public int duration=1;
public Clock(int duration){
this.duration = duration;
clock = 0;
}
public Clock(){
clock=0;
}
public int getClock(){
return clock;
}
public void increment(){
clock+=duration;
}
public void event(Message message){
increment();
if (message.getClock()+duration>clock){
clock = message.getClock()+duration;
}
}
public static void main(String[] args) {
Clock clock = new Clock();
Message msg = new Message(2,3,4,"REQUEST");
clock.event(msg);
// clock.msgEvent(msg);
System.out.println(clock.clock+","+ msg.src+","+msg.dest+","+msg.messageType);
}
}