Skip to content

Commit 25dcfb8

Browse files
committed
remove class OpenGames
1 parent df589a3 commit 25dcfb8

File tree

4 files changed

+31
-78
lines changed

4 files changed

+31
-78
lines changed
Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.bernd;
22

33
import com.bernd.model.Game;
4-
import com.bernd.model.OpenGame;
54
import com.bernd.model.StatusMap;
65
import com.bernd.util.Sender;
76
import java.util.List;
@@ -12,35 +11,32 @@
1211
@Component
1312
public class CleanupController {
1413

15-
private final Sender sender;
16-
private final StatusMap statusMap;
17-
private final OpenGames openGames;
18-
private final Games games;
14+
private final Sender sender;
15+
private final StatusMap statusMap;
16+
private final Games games;
1917

20-
CleanupController(
21-
Sender sender,
22-
StatusMap statusMap,
23-
OpenGames openGames,
24-
Games games) {
25-
this.sender = sender;
26-
this.statusMap = statusMap;
27-
this.openGames = openGames;
28-
this.games = games;
29-
}
30-
31-
@Scheduled(fixedDelay = 40 * 1000)
32-
public void runScheduled() {
33-
Map<String, List<String>> updatedRooms = statusMap.removeInactiveUsers();
34-
for (Map.Entry<String, List<String>> e : updatedRooms.entrySet()) {
35-
String room = e.getKey();
36-
List<String> users = e.getValue();
37-
sender.sendUsers(room, users);
18+
CleanupController(
19+
Sender sender,
20+
StatusMap statusMap,
21+
Games games) {
22+
this.sender = sender;
23+
this.statusMap = statusMap;
24+
this.games = games;
3825
}
39-
List<Game> games = this.games.games();
40-
for (Game game : games) {
41-
if (updatedRooms.getOrDefault(game.id(), List.of()).isEmpty()) {
42-
this.games.remove(game.id());
43-
}
26+
27+
@Scheduled(fixedDelay = 40 * 1000)
28+
public void runScheduled() {
29+
Map<String, List<String>> updatedRooms = statusMap.removeInactiveUsers();
30+
for (Map.Entry<String, List<String>> e : updatedRooms.entrySet()) {
31+
String room = e.getKey();
32+
List<String> users = e.getValue();
33+
sender.sendUsers(room, users);
34+
}
35+
List<Game> games = this.games.games();
36+
for (Game game : games) {
37+
if (updatedRooms.getOrDefault(game.id(), List.of()).isEmpty()) {
38+
this.games.remove(game.id());
39+
}
40+
}
4441
}
45-
}
4642
}

src/main/java/com/bernd/OpenGames.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/main/java/com/bernd/model/StatusMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public UserStatus setRoom(String user, String room) {
1919
if (current == null) {
2020
return UserStatus.create(room);
2121
} else {
22-
return current.touch();
22+
return current.toBuilder().room(room).touch().build();
2323
}
2424
});
2525
}

src/main/java/com/bernd/model/UserStatus.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ public static UserStatus create(String room) {
1717
null);
1818
}
1919

20-
public UserStatus touch() {
21-
return toBuilder().lastSeen(System.currentTimeMillis()).build();
22-
}
23-
2420
public UserStatus removeOpenGame() {
2521
if (openGame == null) {
2622
return this;
@@ -66,6 +62,11 @@ public Builder room(String room) {
6662
return this;
6763
}
6864

65+
public Builder touch() {
66+
this.lastSeen = System.currentTimeMillis();
67+
return this;
68+
}
69+
6970
public Builder lastSeen(long lastSeen) {
7071
this.lastSeen = lastSeen;
7172
return this;

0 commit comments

Comments
 (0)