- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我构建了一个定期查询 API 的 Akka actor,如下所示:
val cancellable =
system.scheduler.schedule(0 milliseconds,
5 seconds,
actor,
QueryController(1))
Actor 本质上是:
object UpdateStatistics {
/**
* Query the controller for the given switch Id
*
* @param dpId Switch's Id
*/
case class QueryController(dpId: Int)
case object Stop
def props: Props = Props[UpdateStatistics]
}
class UpdateStatistics extends Actor with akka.actor.ActorLogging {
import UpdateStatistics._
def receive = {
case QueryController(id) =>
import context.dispatcher
log.info(s"Receiving request to query controller")
Future { FlowCollector.getSwitchFlows(1) } onComplete {
f => self ! f.get
}
case Stop =>
log.info(s"Shuting down")
context stop self
case json: JValue =>
log.info("Getting json response, computing features...")
val features = FeatureExtractor.getFeatures(json)
log.debug(s"Features: $features")
sender ! features
case x =>
log.warning("Received unknown message: {}", x)
}
}
我想做的是从 UpdateStatistics
actor 中获取 json:Jvalue
消息。阅读Akka docs我认为这可能有用:
implicit val i = inbox()
i.select() {
case x => println(s"Valor Devuelto $x")
}
println(i receive(2.second))
但我不知道如何修改 UpdateStatistics
actor 以便将结果发送到上面的收件箱。
我在文档中读到的另一个选项是 event streams .
但我认为这不是正确的方法。
有没有办法实现我想做的事情?或者我是否需要使用第二个 Actor
来向其发送 JSON
响应?
最佳答案
您可能正在寻找 AKKA 中的ask
模式。这将允许您向发送者返回一个值。
import akka.pattern.ask
import akka.util.duration._
implicit val timeout = Timeout(5 seconds)
val future = actor ? QueryController(1)
val result = Await.result(future, timeout.duration).asInstanceOf[JValue]
println(result)
要实现此目的,您需要将响应发送给原始发送者
,而不是自己
。另外,您应该注意将来在处理消息时关闭 sender
的危险。
关于scala - 从 Akka Actor 处获取消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42204361/
我有一个数据框: title | cast ------------------------------ movie1 | cast1,cast2,cast3 movie2
据我所知,Actor 模型是一种关于并发的理论。 Erlang 和 Scala 都实现了这个理论模型,但它们的实现都不完全符合 Actor 模型。 从计算机科学家的角度来看,Erlang、Scala
我是 akka 流的新手。我将 kafka 用作源(使用 ReactiveKafka 库)并通过流对数据进行一些处理并使用订阅者 (EsHandler) 作为接收器。 现在我需要处理错误并通过错误处理
考虑以下代码示例(版本 1)。此处父 actor (ActorA) 向子 actor (ActorB) 发送消息,然后停止自身。由于父 actor 的自停止,在高负载下,子 actor 甚至在从邮箱中
我有以下 Scala 代码: package dummy import javax.servlet.http.{HttpServlet, HttpServletRequest => H
如何描述“数据流编程”和“ Actor 模型”之间的区别?据我了解,它们并非无关,但又不相同。 DF 是否是一个更广泛的概念,其要点是与控制流模型的区别,而 Actor 模型是更详细的和理论上有根基的
GPars 中的 Actor 有自己的消息队列(邮箱)。假设一个参与者有 15 条待处理的消息,然后系统突然宕机(比如由于电源故障)。这 15 条消息会发生什么。当系统再次启动并运行时,消息队列会自动
我刚刚开始使用 AKKA,并且有一个关于非参与者代码如何与参与者代码对话的基本问题。 非参与者代码如何调用参与者并获得响应?我试过使用 Patterns.ask 从非 Actor 调用 Actor ,
这个问题在这里已经有了答案: 关闭 9 年前。 Possible Duplicate: Casting vs using the ‘as’ keyword in the CLR 我最近了解到一种不同
我在设置边界矩形位置时遇到麻烦,这就是我问这个的原因。当我设置 Actor 类型的对象的边界矩形位置时,看来我传递给 [setBounds(x,y,with,height)] 2 的坐标相对于 Act
我是 Actor 模型的新手。任何人都可以解释 Actor 模型中 Actor 的生命周期吗?我一直在文档中寻找答案,但找不到任何令人满意的内容。 我对 Actor 完成后做什么很感兴趣onRecei
例如,我有两个 Actor ——一个父 Actor 和一个子 Actor 。当 parent 收到一条消息时,它会产生与消息中指定的一样多的子actor。如何测试此功能?有没有办法模拟上下文或其他方法
我目前在 Futures 编程,我对 Actor 很好奇。我想听听有经验的声音: Actor 相对于 future 有什么优势? 我什么时候应该使用一种而不是另一种? 据我所知, Actor 持有状态
Actor 模型框架(例如 Orleans )和复杂事件处理 (CEP)(例如 Apache Storm )之间有什么区别? 其中每种方法都适用(或者一种方法比另一种方法更适用)的使用示例肯定会有所帮
你们中的任何人都可以帮助我理解传入的基本消息吗scala 使用 Actor 模型? 我正在尝试编写一个包含 3 个 Actor 的简单程序。 Actor “BossActor”创建了 2 个 Acto
Akka 1.1.3 文档指出“become 方法对于许多不同的事情都很有用,但它的一个特别好的例子是它用于实现有限状态机 (FSM) 的示例”。在运行时热交换 Akka actor 的实现还有哪些其
我正在尝试使用参与者实现消息处理管道。管道的步骤包括读取、过滤、扩充以及最后存储到数据库中等功能。类似于此:http://sujitpal.blogspot.nl/2013/12/akka-conte
可以使用 actor.send() 或 actor.offer() 向 Actor 发送消息一旦我的 Actor 从其 channel 收到消息,我想返回响应。我该怎么做呢?我没有看到任何明显的内置方
你们中的任何人都可以帮助我理解传入的基本消息吗scala 使用 Actor 模型? 我正在尝试编写一个包含 3 个 Actor 的简单程序。 Actor “BossActor”创建了 2 个 Acto
我目前正在尝试保存特殊 Actors所以如果加载旧 map ,我可以再次将它们放在 map 上。因此我想将它们放入 HashMap> monsterAtMap 中并从那里删除它们Stages .所以我
我是一名优秀的程序员,十分优秀!