From 47562abd9b9be05511954ebad829bb268057fd03 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 12 Dec 2019 20:54:06 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=A8=20Add=20ticker=20shutdown=20wrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/main/SonePlugin.java | 3 +++ src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt | 1 + src/main/kotlin/net/pterodactylus/sone/main/TickerShutdown.kt | 3 ++- src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt | 5 +++++ src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt | 6 ++++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index ef9f05a..d3dd3bd 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -208,6 +208,9 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr /* we need to request this to install all notification handlers. */ injector.getInstance(NotificationHandler.class); + /* and this is required to shutdown all tickers. */ + injector.getInstance(TickerShutdown.class); + /* start core! */ core.start(); diff --git a/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt b/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt index 5a66015..749de0d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt +++ b/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt @@ -60,6 +60,7 @@ open class SoneModule(private val sonePlugin: SonePlugin, private val eventBus: loaders?.let { bind(Loaders::class.java).toInstance(it) } bind(MetricRegistry::class.java).`in`(Singleton::class.java) bind(WebOfTrustConnector::class.java).to(PluginWebOfTrustConnector::class.java).`in`(Singleton::class.java) + bind(TickerShutdown::class.java).`in`(Singleton::class.java) bindListener(Matchers.any(), object : TypeListener { override fun hear(typeLiteral: TypeLiteral, typeEncounter: TypeEncounter) { diff --git a/src/main/kotlin/net/pterodactylus/sone/main/TickerShutdown.kt b/src/main/kotlin/net/pterodactylus/sone/main/TickerShutdown.kt index 71764ec..5f96050 100644 --- a/src/main/kotlin/net/pterodactylus/sone/main/TickerShutdown.kt +++ b/src/main/kotlin/net/pterodactylus/sone/main/TickerShutdown.kt @@ -20,12 +20,13 @@ package net.pterodactylus.sone.main import com.google.common.eventbus.* import net.pterodactylus.sone.core.event.* import java.util.concurrent.* +import javax.inject.* /** * Wrapper around all [tickers][ScheduledExecutorService] used in Sone, * ensuring proper shutdown. */ -class TickerShutdown(private val notificationTicker: ScheduledExecutorService) { +class TickerShutdown @Inject constructor(@Named("notification") private val notificationTicker: ScheduledExecutorService) { @Subscribe fun shutdown(shutdown: Shutdown) { diff --git a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt index 9fe5dbb..28481ad 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt @@ -222,4 +222,9 @@ class SoneModuleTest { injector.verifySingletonInstance(named("notification")) } + @Test + fun `ticker shutdown is created as singleton`() { + injector.verifySingletonInstance() + } + } diff --git a/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt index b846522..e658fe2 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt @@ -100,6 +100,12 @@ class SonePluginTest { assertThat(getInjected(NotificationHandler::class.java), notNullValue()) } + @Test + fun `ticker shutdown is being requested`() { + sonePlugin.runPlugin(pluginRespirator) + assertThat(getInjected(TickerShutdown::class.java), notNullValue()) + } + private class FirstStartListener(private val firstStartReceived: AtomicBoolean) { @Subscribe fun firstStart(firstStart: FirstStart) { -- 2.7.4