简体   繁体   English

是否可以在不使用事件的情况下设置计时器 - 在 Akka 演员内部? (打字阿卡)

[英]Is it possible to set up a timer not using events - inside an Akka actor? (typed Akka)

The documentation is not too clear on setting up a timer inside an actor.关于在 actor 内设置计时器的文档不太清楚。 This is the closest information on this I could find: Scheduling messages to self .这是我能找到的最接近的信息: Scheduling messages to self However it's not clear from there if we can create an internal timer inside the actor that would just trigger some actor's method every 5 seconds for example (eg checking actor's state and reacting on its change), without receiving and sending events.然而,从那里我们还不清楚我们是否可以在actor 内部创建一个内部计时器,例如每5 秒触发一次actor 的方法(例如检查actor 的状态并对其变化做出反应),而不接收和发送事件。

If such timer is possible to set up, how reliable would it be?如果可以设置这样的计时器,它的可靠性如何? (eg if it can fail while the actor would continue functioning otherwise) (例如,如果它可能失败而演员将继续运作,否则)

Also if such timer is possible to set up, there supposed to be a possibility of stopping and (re-) starting the timer by the triggered method or another actor's method?此外,如果可以设置这样的计时器,那么应​​该有可能通过触发方法或其他参与者的方法停止和(重新)启动计时器吗?

If by如果由

trigger some actor's method every 5 seconds for example (eg checking actor's state and reacting on its change), without receiving and sending events例如,每 5 秒触发一些 actor 的方法(例如检查 actor 的状态并对其变化做出反应),而不接收和发送事件

you mean "schedule a method within the actor to be called without sending a message to the actor", then the answer is no.您的意思是“在不向演员发送消息的情况下在要调用的演员中安排一个方法”,那么答案是否定的。

Methods in an actor should only ever be executed in direct response to a message sent to the actor (or during the spawning of an actor, but that's arguably effectively a message).演员中的方法应该只在直接响应发送给演员的消息时执行(或在演员产生期间,但这可以说是有效的消息)。 To do otherwise is to throw out (at least) nearly every guarantee the actor model can make.否则就是放弃(至少)几乎所有演员模型可以做出的保证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM