简体   繁体   English

在Akka中发送控制消息

[英]Control message sending in Akka

I am using Akka actors to simulate a real world situation. 我正在使用Akka演员来模拟现实世界的情况。 It depends on time, so I need a way to introduce an idea of a simulated time. 这取决于时间,因此我需要一种方法来介绍模拟时间。 For example, where 1s real time = 1ms simulated time. 例如,其中1s 实时 = 1ms 模拟时间。 Normally messages arrive in the order they are sent (at least with the default dispatcher and locally). 通常,消息按其发送顺序到达(至少使用默认调度程序和本地)。 However, I need them to arrive in order based on the simulated time. 但是,我需要它们根据模拟的时间顺序到达。

A message that is in the far-future could be sent before one in the near-future, as it incorporates a simulated time delay. 由于具有模拟的时间延迟,因此可以将远距离消息发送到近距离消息之前。 The messages come with a sent field, providing the simulated time when the message was sent. 消息带有已sent字段,提供了发送消息时的模拟时间。

For instance, could I block messages that should arrive in the future? 例如,我可以阻止应该在将来到达的消息吗? By keeping a waiting list in the actor and release the messages as the appropriate simulated time arrives? 通过在参与者中保留一个等待列表并在适当的模拟时间到来时释放消息?

Any other methods you would suggest? 您会建议其他方法吗?

Search the net for "discrete-event simulation". 在网上搜索“离散事件模拟”。 Generally, real time has no relation to simulated time like "1s real time = 1ms simulated". 通常,实时与模拟时间无关,例如“ 1s实时= 1ms模拟”。 Instead, simulated time is modelled with a priority queue, where priority is considered as simulated time. 相反,模拟时间是使用优先级队列建模的,其中优先级被视为模拟时间。 Each message, beside the destination address, has time value denoting the simulated time when it must arrive. 每个消息在目标地址旁边都有时间值,该值表示必须到达时的模拟时间。 All messages first are routed to the priority queue, then the simulator changes the reading of simulated clock to the nearest present in the queue, with no relation to the real time. 首先将所有消息路由到优先级队列,然后模拟器将模拟时钟的读数更改为队列中最接近的值,与实时无关。 All messages scheduled for that time are routed to destination, are processed, causing new messages to be routed to the priority queue, and then the clock is moved to the next time referenced in messages. 安排在该时间的所有消息都路由到目标,进行处理,使新消息路由到优先级队列,然后时钟移至消息中引用的下一个时间。

Since the interface of the message sending includes the value of simulated time, it differs from the Akka interface, so you cannot use Akka directly for your task. 由于消息发送的界面包含模拟时间的值,因此它不同于Akka界面,因此您不能直接将Akka用于任务。 Look at List of discrete event simulation software to choose appropriate library. 查看离散事件模拟软件列表以选择适当的库。

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

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