From a6ecf6fa30412531559fdf0ad7550e02a0fd7fd2 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Sun, 6 Jun 2021 17:43:29 +0200 Subject: [PATCH] refactor: deleted MessageRelay class --- .../server/lobbymanager/MessageRelay.java | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/MessageRelay.java diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/MessageRelay.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/MessageRelay.java deleted file mode 100644 index f533872..0000000 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/MessageRelay.java +++ /dev/null @@ -1,70 +0,0 @@ -package uulm.teamname.marvelous.server.lobbymanager; - -import org.java_websocket.WebSocket; -import org.tinylog.Logger; -import uulm.teamname.marvelous.gamelibrary.Tuple; -import uulm.teamname.marvelous.gamelibrary.events.Event; - -import java.util.HashMap; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; - -/** - * Relay for the messages field. It basically relays {@link Event} Events and - * {@link uulm.teamname.marvelous.gamelibrary.requests.Request} Requests to - * the participants or lobbies that they are supposed to be sent to. - */ -public class MessageRelay { - - public static MessageRelay instance; - - - private final BlockingQueue> eventsToSend; - - private MessageRelay() { - this.eventsToSend = new LinkedBlockingQueue<>(); - } - - public static MessageRelay getInstance() { - if (instance == null) { - instance = new MessageRelay(); - } - return instance; - } - - public void relayMessage (WebSocket conn, LobbyConnection targetLobby) { - // TODO: Parse JSON - // TODO: send to target lobby - } - - public void sendMessage (LobbyConnection origin, Participant recipient, Event[] events) { - if (!origin.contains(recipient)) { - Logger.warn("Lobby sent message to not-in-lobby recipient '{}'", recipient.name); - } else { - eventsToSend.add(Tuple.of(recipient, events)); - } - } - - /** - * Broadcasts events to all {@link Participant Participants} of a {@link LobbyConnection}. - * @param origin is the {@link LobbyConnection} that the {@link Event Events} are broadcasted from - * @param events are the {@link Event Events} to be broadcasted - */ - public void broadcastEvents (LobbyConnection origin, Event[] events) { - eventsToSend.add(Tuple.of(origin.getPlayer1(), events)); - eventsToSend.add(Tuple.of(origin.getPlayer2(), events)); - origin.getSpectators() - .forEach(spectator -> eventsToSend.add(Tuple.of(spectator, events))); - } - - /** - * Terminates a given {@link LobbyConnection}. This is a End-of-Lifecycle method for - * {@link LobbyConnection LobbyConnections}, and they may not be reused again. - * @param origin is the LobbyConnection to be terminated - */ - public void terminate (LobbyConnection origin) { - // TODO: implement - } - - -}