如何从Akka系统之外的线程调用akka调度程序?
我有一个actor会实例化一些java类,这些类具有在自己的线程上运行的回调。我想从这些回调中安排执行:
伪代码:
class GPIOActor extends Actor with PubSubActor {
class DebouncerListener(pin: Pin) extends GpioPinListenerDigital {
override def stateChangeEvent(event: GpioPinDigitalStateChangeEvent) {
if (notAlreadyWaitingForBounceToFinish)
context.system.scheduler.scheduleOnce(debouncePollPeriod, new Runnable() {
def run(): Unit = {
if (stillBouncing) {
context.system.scheduler.scheduleOnce(debouncePollPeriod, this)(context.dispatcher)
} else self ! PinStateChangeEvent(pin.getValue)
}
}
})(context.dispatcher)
}
val myPin = GPIOPinListener(RapiPin)
myPin.registerCallback(new DebouncerListener(myPin))
(...)
def receive: Receive = {
case PinStateChangeEvent(newValue) => notifySubscribers(newValue)
}
}