如何发现Scala远程演员死亡? [英] How to discover that a Scala remote actor is died?

查看:89
本文介绍了如何发现Scala远程演员死亡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Scala中,可以通过设置trapExit标志并使用第二个actor作为参数调用link()方法,在另一个(远程)actor终止时通知actor。在这种情况下,当远程参与者通过调用exit()结束其工作时,第一个参与者将收到退出消息来通知。

In Scala, an actor can be notified when another (remote) actor terminates by setting the trapExit flag and invoking the link() method with the second actor as parameter. In this case when the remote actor ends its job by calling exit() the first one is notified by receiving an Exit message.

但是,当远程actor以不太正常的方式终止时(例如,运行它的VM崩溃),会发生什么?换句话说,本地角色如何发现远程角色不再可用?当然,我希望(如果可能的话)可以通过类似于出口1的消息来通知本地参与者,但这似乎不可行。我想念什么吗?我应该连续轮询远程参与者的状态(在这种情况下,我不知道哪种方法是最好的方法)还是有一个更聪明的解决方案?

But what happens when the remote actor terminates in a less graceful way (e.g. the VM where it is running crashes)? In other words, how the local actor can discover that the remote one is no longer available? Of course I would prefer (if possible) that the local actor could be notified by a message similar to the Exit one, but it seems not feasible. Am I missing something? Should I continuously polling the state of the remote actor (and in this case I don't know which is the best way to do that) or is there a smarter solution?

推荐答案



但是,当远程actor以不太正常的方式终止时(例如,正在运行的VM崩溃),会发生什么情况

But what happens when the remote actor terminates in a less graceful way (e.g. the VM where it is running crashes)


Actor代理保持活动状态,接受消息(并丢失它们),并等待您使用重新启动JVM远程演员。监视JVM崩溃(以及其他在基础结构级别发生的故障)远远超出了Scala的职责。最好的选择是通过JMX进行监视。

Actor proxy stays alive accepting messages (and loosing them), and waiting for you to restart the JVM with remote actor. Watching for JVM crashes (and other failures happening on the infrastructure level) is far beyond Scala responsibilities. Good choice for that could be monitoring through JMX.



换句话说,本地参与者如何发现

In other words, how the local actor can discover that the remote one is no longer available?


您可以定义一个超时间隔(例如5000毫秒) 。如果远程actor在此时间间隔内未回复,则表示您有迹象表明远程actor发生了意外情况,您可以询问其状态或将其视为已死亡。

You may define a timeout interval (say 5000 millis). If remote actor doesn't reply during this interval, it's a sign for you that something unexpected is happening to remote actor, and you may either ask it about its state or just treat it as dead.



我应该连续轮询远程参与者的状态(在这种情况下,我不知道哪种方法是最好的方法)或有没有更聪明的解决方案?

Should I continuously polling the state of the remote actor (and in this case I don't know which is the best way to do that) or is there a smarter solution?


您可以在其中放置一种轮询负载均衡器/调度程序一组角色的前端,将仅使用那些仍在运行并准备处理消息的角色(对于远程角色可能突然出现/消失在代理后面的情况,这是有意义的)-> Scala actor可以同时处理多条消息吗?

You may put a kind of a polling load balancer/dispatcher in front of a group of actors, that will use only those actors that are alive and ready to process messages (which makes sense in case of remote actors that may suddenly appear/disappear behind the proxy) -> Can Scala actors process multiple messages simultaneously?

这篇关于如何发现Scala远程演员死亡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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