|
1 | 1 | package com.bernd; |
2 | 2 |
|
3 | 3 | import com.bernd.model.Game; |
4 | | -import com.bernd.model.OpenGame; |
5 | 4 | import com.bernd.model.StatusMap; |
6 | 5 | import com.bernd.util.Sender; |
7 | 6 | import java.util.List; |
|
12 | 11 | @Component |
13 | 12 | public class CleanupController { |
14 | 13 |
|
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; |
19 | 17 |
|
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; |
38 | 25 | } |
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 | + } |
44 | 41 | } |
45 | | - } |
46 | 42 | } |
0 commit comments