From db7e21e343cd8d2fa3161e1487888f43df9aeb8c Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 14 Jun 2019 21:25:22 +0100 Subject: [PATCH] close connections in parallel, more shutdown fixes --- core/src/main/groovy/com/muwire/core/Core.groovy | 4 ++++ .../main/groovy/com/muwire/core/connection/Connection.groovy | 2 +- .../muwire/core/connection/UltrapeerConnectionManager.groovy | 4 ++-- .../groovy/com/muwire/core/download/DownloadManager.groovy | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 25b3c9f0..26aacef4 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -234,9 +234,13 @@ public class Core { } public void shutdown() { + log.info("shutting down connection manager") connectionManager.shutdown() + log.info("shutting down download manageer") downloadManager.shutdown() + log.info("shutting down connection acceeptor") connectionAcceptor.stop() + log.info("shutting down connection establisher") connectionEstablisher.stop() } diff --git a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy index 64963c99..426b8aec 100644 --- a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy @@ -76,9 +76,9 @@ abstract class Connection implements Closeable { return } log.info("closing $name") - endpoint.close() reader.interrupt() writer.interrupt() + endpoint.close() eventBus.publish(new DisconnectionEvent(destination: endpoint.destination)) } diff --git a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy index 2d51598e..a6da9245 100644 --- a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy @@ -104,8 +104,8 @@ class UltrapeerConnectionManager extends ConnectionManager { @Override void shutdown() { - peerConnections.each {k,v -> v.close() } - leafConnections.each {k,v -> v.close() } + peerConnections.values().stream().parallel().forEach({v -> v.close()}) + leafConnections.values().stream().parallel().forEach({v -> v.close()}) peerConnections.clear() leafConnections.clear() } diff --git a/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy b/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy index d6286a5e..db84f7c5 100644 --- a/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy +++ b/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy @@ -138,5 +138,6 @@ public class DownloadManager { public void shutdown() { downloaders.each { it.stop() } + Downloader.executorService.shutdownNow() } }