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 Jan 19, 2025
1 parent 536346c commit 0a4f316
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 @@ -348,21 +348,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 @@ -382,6 +367,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 0a4f316

Please sign in to comment.