diff --git a/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/IpDetails.java b/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/IpDetails.java new file mode 100644 index 000000000..e54637793 --- /dev/null +++ b/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/IpDetails.java @@ -0,0 +1,13 @@ +package de.wuespace.telestion.services.connection; + +import com.fasterxml.jackson.annotation.JsonProperty; +import de.wuespace.telestion.api.message.JsonMessage; + +public record IpDetails(@JsonProperty + String ip, + @JsonProperty + int port) implements JsonMessage { + public IpDetails() { + this("0.0.0.0", 0); + } +} diff --git a/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/Tuple.java b/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/Tuple.java deleted file mode 100644 index 05e3d9f1f..000000000 --- a/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/Tuple.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.wuespace.telestion.services.connection; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * A simple implementation of a Value-Pair whose values are linked together without any key - value relationship. - * - * @param Type 1 - * @param Type 2 - * - * @param value1 Value of Type 1 - * @param value2 Value of Type 2 - * - * @author Cedric Boes - * @version 1.0 - */ -public record Tuple( - @JsonProperty T1 value1, - @JsonProperty T2 value2) { - - /** - * This is only for reflection of Config-Loading! - */ - @SuppressWarnings("unused") - private Tuple() { - this(null, null); - } - -} diff --git a/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpClient.java b/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpClient.java index b8bc2fded..2bb241ee5 100644 --- a/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpClient.java +++ b/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpClient.java @@ -4,7 +4,7 @@ import de.wuespace.telestion.api.config.Config; import de.wuespace.telestion.api.message.JsonMessage; import de.wuespace.telestion.services.connection.ConnectionData; -import de.wuespace.telestion.services.connection.Tuple; +import de.wuespace.telestion.services.connection.IpDetails; import io.reactivex.annotations.NonNull; import io.vertx.core.AbstractVerticle; import io.vertx.core.CompositeFuture; @@ -81,7 +81,7 @@ public TcpClient(Configuration config) { private void handleDispatchedMsg(TcpData tcpData) { var details = tcpData.details(); - var key = new Tuple<>(details.ip(), details.port()); + var key = new IpDetails(details.ip(), details.port()); // Checks if socket already exists. // If not, connects to Server and if successful sends data asynchronously. @@ -110,7 +110,7 @@ private void handleDispatchedMsg(TcpData tcpData) { logger.debug("Sending data to {}:{}", details.ip(), details.port()); activeClients - .get(new Tuple<>(details.ip(), details.port())) + .get(new IpDetails(details.ip(), details.port())) .write(Buffer.buffer(tcpData.data())); }); } @@ -123,7 +123,7 @@ private void handleDispatchedMsg(TcpData tcpData) { private void onConnected(NetSocket socket) { var ip = socket.remoteAddress().host(); var port = socket.remoteAddress().port(); - var key = new Tuple<>(ip, port); + var key = new IpDetails(ip, port); activeClients.put(key, socket); logger.info("Connection established ({}:{})", ip, port); @@ -161,7 +161,7 @@ private void handleMsg(ConnectionData data) { } private Configuration config; - private Map, NetSocket> activeClients; + private Map activeClients; private NetClient currentClient; private static final Logger logger = LoggerFactory.getLogger(TcpClient.class); diff --git a/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpDispatcher.java b/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpDispatcher.java index a1c65f3b7..8f8741a5b 100644 --- a/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpDispatcher.java +++ b/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpDispatcher.java @@ -4,8 +4,8 @@ import de.wuespace.telestion.api.config.Config; import de.wuespace.telestion.api.message.JsonMessage; import de.wuespace.telestion.services.connection.ConnectionData; +import de.wuespace.telestion.services.connection.IpDetails; import de.wuespace.telestion.services.connection.SenderData; -import de.wuespace.telestion.services.connection.Tuple; import io.vertx.core.AbstractVerticle; import io.vertx.core.Promise; @@ -59,7 +59,7 @@ public TcpDispatcher(Configuration config, TcpServer... servers) { private void handle(byte[] bytes, TcpDetails details) { for (var server : servers) { - if (server.isActiveCon(new Tuple<>(details.ip(), details.port()))) { + if (server.isActiveCon(new IpDetails(details.ip(), details.port()))) { vertx.eventBus().publish(server.getConfig().inAddress(), new TcpData(bytes, details).json()); } else { diff --git a/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpServer.java b/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpServer.java index f93ab93b4..706287982 100644 --- a/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpServer.java +++ b/modules/telestion-services/src/main/java/de/wuespace/telestion/services/connection/tcp/TcpServer.java @@ -4,7 +4,7 @@ import de.wuespace.telestion.api.config.Config; import de.wuespace.telestion.api.message.JsonMessage; import de.wuespace.telestion.services.connection.ConnectionData; -import de.wuespace.telestion.services.connection.Tuple; +import de.wuespace.telestion.services.connection.IpDetails; import io.reactivex.annotations.NonNull; import io.vertx.core.*; import io.vertx.core.buffer.Buffer; @@ -132,14 +132,14 @@ public Configuration getConfig() { } // Public for own Dispatcher implementations - public boolean isActiveCon(Tuple key) { + public boolean isActiveCon(IpDetails key) { return activeCons.containsKey(key); } private void onConnected(NetSocket netSocket) { var ip = netSocket.remoteAddress().hostAddress(); var port = netSocket.remoteAddress().port(); - var key = new Tuple<>(ip, port); + var key = new IpDetails(ip, port); logger.info("Connection established with {}:{}", ip, port); activeCons.put(key, netSocket); @@ -171,7 +171,7 @@ private void onConnected(NetSocket netSocket) { private void handleDispatchedMsg(TcpData data) { var details = data.details(); - var element = activeCons.get(new Tuple<>(details.ip(), details.port())); + var element = activeCons.get(new IpDetails(details.ip(), details.port())); // Might be useful to send this to the TCP-Client however the config must be varied for this (future update?) if (element == null) { @@ -203,7 +203,7 @@ private void handleMsg(ConnectionData data) { private Configuration config; private NetServer server; - private Map, NetSocket> activeCons; + private Map activeCons; private static final Logger logger = LoggerFactory.getLogger(TcpServer.class); }