mirror of https://github.com/zlatinb/muwire
add shutdown hook to shutdown core on SIGTERM
parent
4e2a530a13
commit
948b6292fe
|
@ -1,6 +1,7 @@
|
||||||
package com.muwire.core
|
package com.muwire.core
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
import com.muwire.core.connection.ConnectionAcceptor
|
import com.muwire.core.connection.ConnectionAcceptor
|
||||||
import com.muwire.core.connection.ConnectionEstablisher
|
import com.muwire.core.connection.ConnectionEstablisher
|
||||||
|
@ -74,6 +75,8 @@ public class Core {
|
||||||
private final DirectoryWatcher directoryWatcher
|
private final DirectoryWatcher directoryWatcher
|
||||||
final FileManager fileManager
|
final FileManager fileManager
|
||||||
|
|
||||||
|
private final AtomicBoolean shutdown = new AtomicBoolean()
|
||||||
|
|
||||||
public Core(MuWireSettings props, File home, String myVersion) {
|
public Core(MuWireSettings props, File home, String myVersion) {
|
||||||
this.home = home
|
this.home = home
|
||||||
this.muOptions = props
|
this.muOptions = props
|
||||||
|
@ -241,6 +244,10 @@ public class Core {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
if (!shutdown.compareAndSet(false, true)) {
|
||||||
|
log.info("already shutting down")
|
||||||
|
return
|
||||||
|
}
|
||||||
log.info("shutting down download manageer")
|
log.info("shutting down download manageer")
|
||||||
downloadManager.shutdown()
|
downloadManager.shutdown()
|
||||||
log.info("shutting down connection acceeptor")
|
log.info("shutting down connection acceeptor")
|
||||||
|
|
|
@ -98,6 +98,9 @@ class Ready extends AbstractLifecycleHandler {
|
||||||
"Can't connect to I2P router", JOptionPane.WARNING_MESSAGE)
|
"Can't connect to I2P router", JOptionPane.WARNING_MESSAGE)
|
||||||
System.exit(0)
|
System.exit(0)
|
||||||
}
|
}
|
||||||
|
Runtime.getRuntime().addShutdownHook({
|
||||||
|
core.shutdown()
|
||||||
|
})
|
||||||
core.startServices()
|
core.startServices()
|
||||||
application.context.put("muwire-settings", props)
|
application.context.put("muwire-settings", props)
|
||||||
application.context.put("core",core)
|
application.context.put("core",core)
|
||||||
|
|
Loading…
Reference in New Issue