blob: 817efc3346ce0009e69c226bc2bf2c4d12b0cd34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package moe.nea.firmament.events.subscription
import java.util.ServiceLoader
import kotlin.streams.asSequence
import moe.nea.firmament.Firmament
interface SubscriptionList {
fun provideSubscriptions(addSubscription: (Subscription<*>) -> Unit)
companion object {
val allLists by lazy {
ServiceLoader.load(SubscriptionList::class.java)
.stream()
.asSequence()
.mapNotNull {
kotlin.runCatching { it.get() }
.getOrElse { ex ->
Firmament.logger.error("Could not load subscriptions from ${it.type()}", ex)
null
}
}
.toList()
}
init {
require(allLists.isNotEmpty())
}
}
}
|