actor

AKKA Inbox收件箱

三世轮回 提交于 2019-11-29 09:44:27
起因 得到ActorRef就可以给actor发送消息,但无法接收多回复,也不知道actor是否停止 Inbox收件箱出现就是解决这两个问题 示例 package akka.demo.actor import akka.actor.* import java.time.Duration /** ** created by tankx ** 2019/9/12 与actor 通信模式ask或tell 无法支持接收多回复和观察其它actor的生命周期,所以inbox应用而生 **/ fun main() { val system = ActorSystem.create("box-sys") val helloActor = system.actorOf(HelloActor.props("tom")) helloActor.tell("hi", ActorRef.noSender()) val box = Inbox.create(system) box.send(helloActor, "how are you!") box.watch(helloActor)//监控actor 的生命周期,当actor stop, receive会接收到Terminated消息 helloActor.tell(PoisonPill.getInstance(), ActorRef.noSender()

AKKA Actor创建

喜夏-厌秋 提交于 2019-11-29 09:42:48
Actor 类定义 Actor 类需要继承 AbstractActor 类 实现 createReceive 方法,绑定各类actor收到不同类型消息对应处理不同业务逻辑 默认提供了 ReceiveBuilder 类辅助创建 Receive 对actorOf的调用返回ActorRef的实例。这是 Actor 实例的句柄,也是与之交互的 唯一 方法。 ActorRef是不可变的,并且与它所表示的 Actor 有一对一的关系。ActorRef也是可序列化的, 序列化通过网络发送它,并在远程主机上使用它,并且它仍然在网络上表示原始节点上的同一个 Actor。 Actor的层级关系 Actor的层级关系类似树模式 谁创建谁管理原则: ActorSystem 创建就由ActorSystem负责监控管理(重启,异常,恢复等) Actor中创建另外的Actor,则创建者看做为父级,负责监控管理它创建出来的actor Props Props 创建 Actor 的配置选项,推荐在actor类提供一个通用的props方法来创建 注意: 1,同一个akka集群中创建的actor 实例 name不能重复,不然会报InvalidActorNameException异常 2,ActorSytem同一个集群,各节点的ActorSytem name必须相同 3,不允许自行new创建actor实例 如果直接new

TPL Dataflow, how to forward items to only one specific target block among many linked target blocks?

自作多情 提交于 2019-11-29 09:09:39
I am looking for a TPL data flow block solution which can hold more than a single item, which can link to multiple target blocks, but which has the ability to forward an item to only a specific target block that passes a filter/predicate. At no time should an item be delivered to multiple target blocks at the same time, always only to the one which matches the filter or the item can be discarded. I am not fond of BroadCastBlock because, if I understand correctly, it does not guarantee delivery (or does it?) and the filtering is done on the target block side, meaning BroadCastBlock essentially

UE4蓝图教程(2)

谁都会走 提交于 2019-11-29 08:26:08
蓝图 蓝图是虚幻4中的可视化脚本系统,是一种快速开发游戏原型的方法。无需逐行编写代码,您可以直观的做所有事情:拖放节点,将它们的属性设置在UI中,并拖动连接线来连接。除了成为一个快速的原型开发工具之外,蓝图还使得非编程人员可以很快速地上手编写脚本。 注 : 博主水平有限,如有疑问,请参见 原英文教程 在本教程中,您将用蓝图: 1 设置一个从上向下看的摄像机 2 创建一个由玩家控制的具有基本动作actor 3 设置玩家输入 4 创建一个物品,当玩家碰到它时消失。 开始 下载 starter project 并解压它。打开项目文件夹并打开BananaCollector.uproject。 注意:如果你收到提示,说这个项目是用旧版本的虚幻4创建的,没关系(引擎经常更新)。您可以选择打开副本,也可以选择在合适的位置进行版本转换。 如果一切正常,你会看到下面的场景。这是玩家移动并收集物品的地方。 我已经将项目文件夹分类了以便于查找文件,正如您所看到的: 如果你愿意,你可以使用红色区域的按钮来显示或隐藏Content面板。 创建玩家 在内容浏览器中,找到Blueprints 文件夹。单击Add New按钮并选择Blueprint class。 因为你想让actor 能够接收到玩家的输入,所以Pawn 类是合适的。从弹出窗口中选择Pawn ,并将其命名为BP_Player。 注意

消息通知

这一生的挚爱 提交于 2019-11-29 05:04:40
未读消息列表页开发 models.py @python_2_unicode_compatible class NotificationQuerySet(models.query.QuerySet): def unread(self): return self.filter(unread=True).select_related('actor', 'recipient') def read(self): return self.filter(unread=False).select_related('actor', 'recipient') def mark_all_as_read(self, recipient=None): """标为已读,可以传入接收者参数""" qs = self.unread() if recipient: qs = qs.filter(recipient=recipient) return qs.update(unread=False) def mark_all_as_unread(self, recipient=None): """标为未读,可以传入接收者参数""" qs = self.read() if recipient: qs = qs.filter(recipient=recipient) return qs.update(unread=True

Is it bad practice to send an actor a message from something which is not an actor?

扶醉桌前 提交于 2019-11-29 04:03:29
Suppose I have some class which has a property actor_ of type Actor . Is there a problem with me doing def someMethod() = { actor_ ! "HELLO" } Or should sending a message always be done from another actor; e.g. def someMethod() = { Actor.actor { actor_ ! "HELLO" } } It depends. When you send a message to an actor from non-actor code, an ActorProxy is automatically created and stored in a thread local. This creates a potential memory leak, albeit a very small one, because the ActorProxy won't be GC'd until the thread is GC'd. The ActorProxy essentially enables the non-actor thread to in many

Alternatives to using “var” for state with actors?

自作多情 提交于 2019-11-28 22:53:21
问题 I have found myself using vars fairly often with akka actors to maintain state. For example, if I my actor needs to maintain a list of items, I might do something like: class ListActor extends Actor{ var xs : List[Int] = List() def receive = { case x : Int => xs = x :: xs } } Using the mutable variable seems to go against the spirit of Scala. Alternatively I have used this: class ListActor2 extends Actor{ import context._ def collect_ints(accu : List[Int]) : Receive = { case x : Int => become

How to designate a thread pool for actors

a 夏天 提交于 2019-11-28 21:34:30
I have an existing java/scala application using a global thread pool. I would like to start using actors in the project but would like everything in the app using the same pool. I know I can set the maximum number of threads that actors use but would prefer sharing the thread pool. Is this necessary/reasonable, and is it possible to designate the actor's thread pool? If it is not possible/recommended, are there any rules of thumb when integrating actors in apps that are already using threads? Thanks. I believe you can do something like this: trait MyActor extends Actor { val pool = ... // git

Scala remote actors

故事扮演 提交于 2019-11-28 20:37:26
Are there any guides or tutorials which explain the possibility to use scala actors remotely? All I have found until now is one example (without comments) but that's hardly enough. I have written an article with an example app to explain the use of Remote Actors a bit some time ago. Well, it has no comments inside the code (maybe you even meant that article), but there are explanations below the code. Just be careful to send messages that are serializable (case classes and case objects are!) and be sure the opposite side can create the class. Watch out for custom ClassLoaders or missing JARs

Blocking calls in Akka Actors

白昼怎懂夜的黑 提交于 2019-11-28 17:08:15
问题 As a newbie, I am trying to understand how actors work. And, from the documentation, I think I understand that actors are objects which gets executed in sync mode and also that actor execution can contain blocking/sync method calls, e.g. db requests But, what I don't understand is that if you write an actor that has some blocking invocations inside (like a blocking query execution), it will mess up the whole thread pool (in the sense that cpu utilization will go down, etc.), right ? I mean,