/* 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();
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 <I> hear(typeLiteral: TypeLiteral<I>, typeEncounter: TypeEncounter<I>) {
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) {
injector.verifySingletonInstance<ScheduledExecutorService>(named("notification"))
}
+ @Test
+ fun `ticker shutdown is created as singleton`() {
+ injector.verifySingletonInstance<TickerShutdown>()
+ }
+
}
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) {