close connections on shutdown

This commit is contained in:
Zlatin Balevsky
2019-06-01 13:04:22 +01:00
parent 2db3276b07
commit 1255ac936b
6 changed files with 44 additions and 2 deletions

View File

@@ -197,6 +197,10 @@ public class Core {
hostCache.waitForLoad() hostCache.waitForLoad()
} }
public void shutdown() {
connectionManager.shutdown()
}
static main(args) { static main(args) {
def home = System.getProperty("user.home") + File.separator + ".MuWire" def home = System.getProperty("user.home") + File.separator + ".MuWire"
home = new File(home) home = new File(home)

View File

@@ -82,7 +82,6 @@ abstract class Connection implements Closeable {
read() read()
} }
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
close()
} catch (Exception e) { } catch (Exception e) {
log.log(Level.WARNING,"unhandled exception in reader",e) log.log(Level.WARNING,"unhandled exception in reader",e)
} finally { } finally {

View File

@@ -59,6 +59,8 @@ abstract class ConnectionManager {
abstract void onDisconnectionEvent(DisconnectionEvent e) abstract void onDisconnectionEvent(DisconnectionEvent e)
abstract void shutdown()
protected void sendPings() { protected void sendPings() {
final long now = System.currentTimeMillis() final long now = System.currentTimeMillis()
getConnections().each { getConnections().each {

View File

@@ -71,4 +71,8 @@ class LeafConnectionManager extends ConnectionManager {
log.severe("removed destination not present in connection manager ${e.destination.toBase32()}") log.severe("removed destination not present in connection manager ${e.destination.toBase32()}")
} }
@Override
void shutdown() {
}
} }

View File

@@ -101,6 +101,14 @@ class UltrapeerConnectionManager extends ConnectionManager {
log.severe("Removed connection not present in either leaf or peer map ${e.destination.toBase32()}") log.severe("Removed connection not present in either leaf or peer map ${e.destination.toBase32()}")
} }
@Override
void shutdown() {
peerConnections.each {k,v -> v.close() }
leafConnections.each {k,v -> v.close() }
peerConnections.clear()
leafConnections.clear()
}
void forwardQueryToLeafs(QueryEvent e) { void forwardQueryToLeafs(QueryEvent e) {
} }

View File

@@ -0,0 +1,25 @@
import javax.annotation.Nonnull
import javax.inject.Inject
import org.codehaus.griffon.runtime.core.AbstractLifecycleHandler
import com.muwire.core.Core
import griffon.core.GriffonApplication
import groovy.util.logging.Log
@Log
class Shutdown extends AbstractLifecycleHandler {
@Inject
Shutdown(@Nonnull GriffonApplication application) {
super(application)
}
@Override
void execute() {
log.info("shutting down")
Core core = application.context.get("core")
core.shutdown()
}
}