import com.google.common.eventbus.*
import net.pterodactylus.sone.core.event.*
import net.pterodactylus.sone.freenet.plugin.*
+import net.pterodactylus.sone.utils.*
import java.util.concurrent.atomic.*
+import javax.inject.*
/**
* [Runnable] that is scheduled via an [Executor][java.util.concurrent.Executor],
* checks whether the web of trust plugin can be communicated with, sends
* events if its status changes and reschedules itself.
*/
-class WebOfTrustPinger(private val eventBus: EventBus, private val webOfTrustReacher: () -> Unit, private val reschedule: () -> Unit) : Runnable {
+class WebOfTrustPinger @Inject constructor(
+ private val eventBus: EventBus,
+ @Named("webOfTrustReacher") private val webOfTrustReacher: Runnable,
+ @Named("webOfTrustReschedule") private val reschedule: Runnable) : Runnable {
private val lastState = AtomicBoolean(false)
private val eventBus = EventBus()
private val webOfTrustReachable = AtomicBoolean()
- private val webOfTrustReacher: () -> Unit = { webOfTrustReachable.get().onFalse { throw PluginException() } }
+ private val webOfTrustReacher = Runnable { webOfTrustReachable.get().onFalse { throw PluginException() } }
private val rescheduled = AtomicBoolean()
- private val reschedule: () -> Unit = { rescheduled.set(true) }
+ private val reschedule = Runnable { rescheduled.set(true) }
private val pinger = WebOfTrustPinger(eventBus, webOfTrustReacher, reschedule)
@Test