Skip to content

Commit

Permalink
Make server teardown the reverse of setup
Browse files Browse the repository at this point in the history
It is neater to stop announcement, deregister and close UPnP
before stopping the server so that discovering clients
can't try to connect to an already stopped server
though this is mostly just being picky because the human interaction
time scales dominate and shut down and deregister are nearly the same
time.
  • Loading branch information
fishface60 committed Dec 27, 2024
1 parent 0aa48ed commit 15cc9f3
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/main/java/net/rptools/maptool/server/MapToolServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,21 +335,6 @@ public void stop() {
return;
}

server.close();
for (var connection : router.removeAll()) {
connection.removeDisconnectHandler(onConnectionDisconnected);
connection.close();
}

assetManagerMap.clear();

if (heartbeatThread != null) {
heartbeatThread.shutdown();
}
if (assetProducerThread != null) {
assetProducerThread.shutdown();
}

if (announcer != null) {
announcer.stop();
announcer = null;
Expand All @@ -369,6 +354,21 @@ public void stop() {
int port = config.getPort();
UPnPUtil.closePort(port);
}

server.close();
for (var connection : router.removeAll()) {
connection.removeDisconnectHandler(onConnectionDisconnected);
connection.close();
}

assetManagerMap.clear();

if (heartbeatThread != null) {
heartbeatThread.shutdown();
}
if (assetProducerThread != null) {
assetProducerThread.shutdown();
}
}

public void start() throws IOException {
Expand Down

0 comments on commit 15cc9f3

Please sign in to comment.