类型安全的Scala演员 [英] Type safe Scala actors

查看:74
本文介绍了类型安全的Scala演员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以指定actor可以接受哪种类型的消息,如果任何东西试图将其发送给其他类型,则会给出编译错误?

Is there any way to specify what type of message an actor can accept and give a compile error if anything tries to send it some other type?

推荐答案

不确定是否能回答您的问题,但希望它能给您一些想法。也许您正在搜索类似类型化演员之类的东西。来自 Akka 项目:

Not sure whether it answers your question, but I hope it will give you some ideas. Maybe you are searching for something like Typed Actors from Akka project:


通过类型演员来实现类型演员。它通过AspectWerkz使用AOP将常规POJO转换为具有Actor模型语义的异步非阻塞Actor。例如。每个消息调度都变成一条消息,该消息被放入队列中,由Typed Actor依次逐一处理。

The Typed Actors are implemented through Typed Actors. It uses AOP through AspectWerkz to turn regular POJOs into asynchronous non-blocking Actors with semantics of the Actor Model. E.g. each message dispatch is turned into a message that is put on a queue to be processed by the Typed Actor sequentially one by one.

您定义接口和实现,然后将其注册为参与者。 Akka将为仍在使用幕后角色模型的界面创建代理。而且您仍然可以使用以下消息传递样式:

So you define interface and implementation and then register them as actor. Akka will create proxy for your interface that still use actor model under the hood. And you still able to use following message passing styles:


  • 即弃即用

  • 请求-reply

  • 请求-将来答复

这篇关于类型安全的Scala演员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆