@@ -20,7 +20,6 @@ import io.github.freya022.botcommands.api.core.utils.awaitShutdown
2020import io.github.freya022.botcommands.api.core.utils.loggerOf
2121import io.github.freya022.botcommands.internal.commands.application.ApplicationCommandsContextImpl
2222import io.github.freya022.botcommands.internal.commands.text.TextCommandsContextImpl
23- import io.github.freya022.botcommands.internal.core.service.SpringServiceContainer
2423import io.github.freya022.botcommands.internal.utils.takeIfFinite
2524import io.github.freya022.botcommands.internal.utils.unwrap
2625import io.github.oshai.kotlinlogging.KotlinLogging
@@ -70,16 +69,6 @@ internal class BContextImpl internal constructor(
7069
7170 private val statusLock: ReentrantLock = ReentrantLock ()
7271 private val statusCondition: Condition = statusLock.newCondition()
73- private val shutdownHook: Thread ? = when {
74- // Spring has its own shutdown hook that will fire a shutdown event, we handle that
75- serviceContainer is SpringServiceContainer -> null
76- config.enableShutdownHook -> Thread (::shutdownNow)
77- else -> null
78- }
79-
80- init {
81- shutdownHook?.let { Runtime .getRuntime().addShutdownHook(it) }
82- }
8372
8473 override fun dispatchException (message : String , t : Throwable ? , extraContext : Map <String , Any ?>) {
8574 if (config.disableExceptionsInDMs) return // Don't send DM exceptions in dev mode
@@ -166,8 +155,8 @@ internal class BContextImpl internal constructor(
166155
167156 override fun shutdown () {
168157 if (status == Status .SHUTTING_DOWN || status == Status .SHUTDOWN ) return
169- removeShutdownHook()
170158
159+ // Shutdown hook will be removed by [[DefaultShutdownHook]] if we use the built-in DI
171160 runBlocking { setStatus(Status .SHUTTING_DOWN ) }
172161
173162 scheduleShutdownSignal(afterShutdownSignal = {
@@ -181,8 +170,8 @@ internal class BContextImpl internal constructor(
181170 override fun shutdownNow () {
182171 // Do not call shutdown(), more precisely do not call scheduleShutdownSignal() twice
183172 if (status == Status .SHUTTING_DOWN || status == Status .SHUTDOWN ) return
184- removeShutdownHook()
185173
174+ // Shutdown hook will be removed by [[DefaultShutdownHook]] if we use the built-in DI
186175 runBlocking { setStatus(Status .SHUTTING_DOWN ) }
187176
188177 scheduleShutdownSignal(afterShutdownSignal = {
@@ -272,16 +261,6 @@ internal class BContextImpl internal constructor(
272261 return true
273262 }
274263
275- private fun removeShutdownHook () {
276- if (shutdownHook == null ) return
277-
278- try {
279- Runtime .getRuntime().removeShutdownHook(shutdownHook)
280- } catch (_: IllegalStateException ) {
281-
282- }
283- }
284-
285264 private fun shutdownJDA (now : Boolean ) {
286265 val jda = jdaOrNull ? : return logger.debug { " Ignoring JDA shutdown as there is no JDA instance registered" }
287266
0 commit comments