From 0bd930ef6a330333960edd81021baade8f4e6a91 Mon Sep 17 00:00:00 2001 From: JeppeOvervad Date: Thu, 28 Sep 2023 13:02:50 +0200 Subject: [PATCH 1/2] SocketNetwork constructor with timeout. --- .../framework/network/socket/SocketNetwork.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/dk/alexandra/fresco/framework/network/socket/SocketNetwork.java b/core/src/main/java/dk/alexandra/fresco/framework/network/socket/SocketNetwork.java index 43745da4b..72ce7fc7e 100644 --- a/core/src/main/java/dk/alexandra/fresco/framework/network/socket/SocketNetwork.java +++ b/core/src/main/java/dk/alexandra/fresco/framework/network/socket/SocketNetwork.java @@ -102,7 +102,17 @@ public SocketNetwork(NetworkConfiguration conf, Map socketMap) * @param conf the configuration to load the network from. */ public SocketNetwork(NetworkConfiguration conf) { - this(conf, new Connector(conf, Duration.of(1, ChronoUnit.MINUTES)).getSocketMap()); + this(conf, Duration.of(1, ChronoUnit.MINUTES)); + } + + /** + * Construct a socket network with a specific timeout. + * + * @param conf the configuration to load the network from. + * @param timeout duration to wait until timeout when connecting the network. + */ + public SocketNetwork(NetworkConfiguration conf, Duration timeout) { + this(conf, new Connector(conf, timeout).getSocketMap()); } /** From 0050fe64ce6e7a67046bc41f3ca8efc246bce563 Mon Sep 17 00:00:00 2001 From: JeppeOvervad Date: Thu, 28 Sep 2023 13:04:27 +0200 Subject: [PATCH 2/2] New polling strategy --- .../dk/alexandra/fresco/framework/network/socket/Connector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/dk/alexandra/fresco/framework/network/socket/Connector.java b/core/src/main/java/dk/alexandra/fresco/framework/network/socket/Connector.java index bb30b1056..c5de598b0 100644 --- a/core/src/main/java/dk/alexandra/fresco/framework/network/socket/Connector.java +++ b/core/src/main/java/dk/alexandra/fresco/framework/network/socket/Connector.java @@ -137,7 +137,7 @@ private Map connectClient(final NetworkConfiguration conf) } catch (ConnectException e) { // A ConnectionException is expected if the opposing side is not listening for our // connection attempt yet. We ignore this and try again. - Thread.sleep(1L << ++attempts); + Thread.sleep(Math.min(1 << attempts++, 5_000)); // This should probably not busy-wait for each party } }