Skip to content

Commit 613fe49

Browse files
author
Matvey Kazakov
committed
Changed clock.xml protocol in order to support new version of PCMS2
1 parent 85093f8 commit 613fe49

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Openfire/src/main/java/ru/ifmo/neerc/service/ClockService.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,21 @@ public class ClockService extends Thread {
2626
private long timeStarted;
2727
private final Collection<ClockListener> listeners = new ArrayList<ClockListener>();
2828
private Clock clock = new Clock();
29-
29+
30+
private static enum ClockStatus {
31+
BEFORE(1), PAUSED(3), RUNNING(2), OVER(4);
32+
private final int id;
33+
34+
private ClockStatus(int id) {
35+
this.id = id;
36+
}
37+
38+
public int getId() {
39+
return id;
40+
}
41+
42+
}
43+
3044
public ClockService() {
3145
}
3246

@@ -43,7 +57,7 @@ public void run() {
4357

4458
}
4559
}
46-
60+
4761
private void checkUpdate() throws Exception {
4862
clockFile = new File(JiveGlobals.getProperty("neerc.clock", defaultFileName));
4963
long modified = clockFile.lastModified();
@@ -66,15 +80,15 @@ private void checkUpdate() throws Exception {
6680
Element root = document.getRootElement();
6781
long time = Long.parseLong(root.attributeValue("time"));
6882
long total = Long.parseLong(root.attributeValue("length"));
69-
int status = Integer.parseInt(root.attributeValue("status"));
83+
int status = ClockStatus.valueOf(root.attributeValue("status")).getId();
7084

7185
long newTimeStarted = System.currentTimeMillis() - time;
7286
if (clock.getStatus() != 2 || status != 2 || newTimeStarted < timeStarted || newTimeStarted > timeStarted + 60000) {
7387
timeStarted = newTimeStarted;
7488
} else {
7589
time = System.currentTimeMillis() - timeStarted;
7690
}
77-
91+
7892
clock.setTime(time);
7993
clock.setTotal(total);
8094
clock.setStatus(status);
@@ -95,4 +109,4 @@ private void notifyListeners() {
95109
}
96110
}
97111

98-
}
112+
}

0 commit comments

Comments
 (0)