🚧 Add DI configuration for notification ticker
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 12 Dec 2019 18:41:16 +0000 (19:41 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 12 Dec 2019 18:41:16 +0000 (19:41 +0100)
src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt
src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt

index 8a3b0c2..5a66015 100644 (file)
@@ -16,7 +16,11 @@ import net.pterodactylus.util.config.ConfigurationException
 import net.pterodactylus.util.logging.*
 import net.pterodactylus.util.version.Version
 import java.io.*
+import java.util.concurrent.*
+import java.util.concurrent.Executors.*
 import java.util.logging.*
+import javax.inject.*
+import javax.inject.Singleton
 
 open class SoneModule(private val sonePlugin: SonePlugin, private val eventBus: EventBus) : AbstractModule() {
 
@@ -67,6 +71,12 @@ open class SoneModule(private val sonePlugin: SonePlugin, private val eventBus:
                })
        }
 
+       @Provides
+       @Singleton
+       @Named("notification")
+       fun getNotificationTicker(): ScheduledExecutorService =
+                       newSingleThreadScheduledExecutor()
+
        private val logger: Logger = Logging.getLogger(javaClass)
 
 }
index 7f6b8d0..9fe5dbb 100644 (file)
@@ -20,6 +20,7 @@ import org.hamcrest.MatcherAssert.*
 import org.hamcrest.Matchers.*
 import org.mockito.Mockito.*
 import java.io.*
+import java.util.concurrent.*
 import java.util.concurrent.atomic.*
 import kotlin.test.*
 
@@ -216,4 +217,9 @@ class SoneModuleTest {
                injector.verifySingletonInstance<WebOfTrustConnector>()
        }
 
+       @Test
+       fun `notification ticker is created as singleton`() {
+               injector.verifySingletonInstance<ScheduledExecutorService>(named("notification"))
+       }
+
 }