Managing your Actor Systems
今天偶然得机会,找到一篇不错得文章,现在分享给大家。
原文:http://www.kotancode.com/2013/02/15/managing-your-actor-systems/
If you’ve have any experience with Akka, then you know that the Actor System represents a hierarchy of managed actors. This hierarchy is a supervisoryhierarchy and allows for actor supervision much the way Erlang has supported process supervision for … I dunno, since the dinosaur age for sure.
Recently I’ve been writing some code for a non-blocking socket server that has all of its business logic encapsulated within an Akka Actor System. An actor system is a very heavy weight thing and most people recommend that you only keep one of these things around per process. You might feel tempted to create multiple systems to segment different purposes within your application but all of the information I’ve found discourages this practice. I haven’t had enough real-world experience to vouch for this but, people who are way smarter than I am say to only use one actor system per process, so that’s what I’ll do.
I had some trouble when it came time to reference my actor system. I had a companion object of an actor and, unfortunately, an actor’s companion object can’t see the context object that regular actor classes can see. In other words, my method couldn’t refer to the system via context.system, which is the recommended way for actors to refer to the system to which they belong.
So, I thought I would be clever and create a new instance of ActorSystem but re-use the same name that I used the last time. I thought maybe it would seek out and find the existing actor system and just create a new lightweight reference to it. This is wrong. Here’s the proof, create two vals:
|
1
2
|
val system = ActorSystem("foo")val system2 = ActorSystem("foo") |
Now, create an actor within system via system.actorOf and maintain a reference to it. If the two actor systems are identical, then you should be able to obtain a reference to that actor with system.actorFor using system2 and it’ll be the same actor. This is not the case. Even though both systems have the same name, they are different instances, managing different actor hierarchies, with different state and potentially divergent configurations.
My solution, which may not be the best, is to do the following, in order of precedence:
- Refer to the actor system within an Actor class via context.system. This won’t work within actor companion objects, however.
- Refer to the actor system by getting it from a global object, e.g. ApplicationServer.system. This should only be done when #1 won’t work.
If someone else has a more clever way of managing and referring to the actor system, I’d love to hear it. So far, this is the only way I’ve been able to keep my code anywhere close to clean.
Managing your Actor Systems的更多相关文章
- (转)Akka学习笔记(二):Actor Systems
Akka学习笔记(二):Actor Systems 图中表示的是一个Actor System,它显示了在这个Actor System中最重要实体之间的关系. 什么是actor,是一个封装了状态和行为的 ...
- Akka - Basis for Distributed Computing
Some concepts as blow: Welcome to Akka, a set of open-source libraries for designing scalable, resil ...
- Hadoop构成
What Is Apache Hadoop? The Apache™ Hadoop® project develops open-source software for reliable, scala ...
- Welcome to Apache™ Hadoop®!
What Is Apache Hadoop? Getting Started Download Hadoop Who Uses Hadoop? News 15 October, 2013: relea ...
- akka 文章 博客
http://blog.csdn.net/wsscy2004/article/category/2430395 Actor生命周期理解 Actor生命周期理解 镇图:Actor内功心法图 Actor的 ...
- What Is Apache Hadoop
What Is Apache Hadoop? The Apache™ Hadoop® project develops open-source software for reliable, scala ...
- Sr Software Engineer - Big Data Team
Sr Software Engineer - Big Data Team About UberWe’re changing the way people think about transport ...
- Security Software Engineer
Security Software Engineer Are you excited to be part of the VR revolution and work on cutting edge ...
- akka模块
模块 Akka的模块化做得非常好,它为不同的功能提供了不同的Jar包. akka-actor-2.0.jar – 标准Actor, 有类型Actor,等等 akka-remote-2.0.jar – ...
随机推荐
- 饭卡------HDOJ杭电2546(还是01背包!!!!!!)
Problem Description 电子科大本部食堂的饭卡有一种非常诡异的设计,即在购买之前推断剩余金额. 假设购买一个商品之前,卡上的剩余金额大于或等于5元,就一定能够购买成功(即使购买后卡上剩 ...
- 深度学习大牛Yoshua Bengio
深度学习大牛Yoshua Bengio今天AAAI四小时深度学习教学讲座非常详尽,PPT有230页:http://t.cn/zQ4VRVx 如觉太长,可看他33页综述文:http://t.cn/zjk ...
- c#关于委托和事件
using System; using System.Collections.Generic; using System.Text; namespace Delegate { // 热水器 ...
- 【Oracle】number类型保留小数位
SQL> SELECT TO_CHAR(, '9990.00') A, TO_CHAR(5.8, '9990.00') B, TO_CHAR(., '9990.00') C FROM dual; ...
- iOS开发中NSDate时间戳的转换--
NSTimeInterval time =(NSTimeInterval )[model.day floatValue]; NSDate *date = [NSDate dateWithTimeInt ...
- Xcode 静态库调试策略
Xcode 静态库调试策略 (已经有现成的工程和静态库源码) ***** 为安全期间建议备份一下静态库 Step1: 下载最新的工程[工程中有所要测试的静态库和头文件需要删除]: Step2: ...
- ASP.NET MVC进阶之路:深入理解Controller激活机制并使用Ioc容器创建对象
本文标题说是"深入理解Controller"其实有点“标题党”的味道了.本篇只会探讨"Controller"的激活机制,也就是如何创建Controller的并调 ...
- java代码中获取进程process id(转)
另一方面,线程ID=进程ID+内部线程对象ID并不成立, 参考: blog.csdn.net/heyetina/article/details/6633901 如何在java代码中获取进 ...
- 怎样为ubuntu eclipse 添加 GBK字符集
以前没有发现,最近把自己的代码靠到同学电脑上运行报错,发现是字符集的问题,一般来说 eclipse默认的是GBK编码,而ubuntu上默认是没有GBK编码的,所以ubuntu eclipse 上自然就 ...
- word2vec 中的数学原理具体解释(三)背景知识
word2vec 是 Google 于 2013 年开源推出的一个用于获取 word vector 的工具包,它简单.高效,因此引起了非常多人的关注.因为 word2vec 的作者 Tomas M ...