close connections on shutdown
This commit is contained in:
@@ -196,6 +196,10 @@ public class Core {
|
||||
connectionEstablisher.start()
|
||||
hostCache.waitForLoad()
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
connectionManager.shutdown()
|
||||
}
|
||||
|
||||
static main(args) {
|
||||
def home = System.getProperty("user.home") + File.separator + ".MuWire"
|
||||
|
@@ -82,7 +82,6 @@ abstract class Connection implements Closeable {
|
||||
read()
|
||||
}
|
||||
} catch (SocketTimeoutException e) {
|
||||
close()
|
||||
} catch (Exception e) {
|
||||
log.log(Level.WARNING,"unhandled exception in reader",e)
|
||||
} finally {
|
||||
|
@@ -58,6 +58,8 @@ abstract class ConnectionManager {
|
||||
abstract void onConnectionEvent(ConnectionEvent e)
|
||||
|
||||
abstract void onDisconnectionEvent(DisconnectionEvent e)
|
||||
|
||||
abstract void shutdown()
|
||||
|
||||
protected void sendPings() {
|
||||
final long now = System.currentTimeMillis()
|
||||
|
@@ -71,4 +71,8 @@ class LeafConnectionManager extends ConnectionManager {
|
||||
log.severe("removed destination not present in connection manager ${e.destination.toBase32()}")
|
||||
}
|
||||
|
||||
@Override
|
||||
void shutdown() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ class UltrapeerConnectionManager extends ConnectionManager {
|
||||
|
||||
final Map<Destination, PeerConnection> peerConnections = new ConcurrentHashMap()
|
||||
final Map<Destination, LeafConnection> leafConnections = new ConcurrentHashMap()
|
||||
|
||||
|
||||
UltrapeerConnectionManager() {}
|
||||
|
||||
public UltrapeerConnectionManager(EventBus eventBus, Persona me, int maxPeers, int maxLeafs,
|
||||
@@ -100,6 +100,14 @@ class UltrapeerConnectionManager extends ConnectionManager {
|
||||
if (removed == null)
|
||||
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) {
|
||||
|
||||
|
25
gui/griffon-app/lifecycle/Shutdown.groovy
Normal file
25
gui/griffon-app/lifecycle/Shutdown.groovy
Normal 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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user