標籤:

請問akka官方文檔的一句話如何翻譯?

Querying the Logical Actor HierarchySince the actor system forms a file-system like hierarchy, matching on paths is possible in the same way as supported by Unix shells: you may replace (parts of) path element names with wildcards (?*? and ???) to formulate a selection which may match zero or more actual actors. Because the result is not a single actor reference, it has a different type ActorSelection and does not support the full set of operations an ActorRef does. Selections may be formulated using the ActorSystem.actorSelection and ActorContext.actorSelection methods and do support sending messages:context.actorSelection("../*") ! msg
will send msg to all siblings including the current actor. As for references obtained using actorSelection, a traversal of the supervision hierarchy is done in order to perform the message send. As the exact set of actors which match a selection may change even while a message is making its way to the recipients, it is not possible to watch a selection for liveliness changes. In order to do that, resolve the uncertainty by sending a request and gathering all answers, extracting the sender references, and then watch all discovered concrete actors. This scheme of resolving a selection may be improved upon in a future release.

加粗文字的這個意思是說 通過 actorSelection 方法匹配的actor可能發生變化
所以當消息正在接收者的路徑上發送的時候,甚至消息還在路上的時候,actorSelection的匹配關係就已經變化了,所以不能通過actorSelection方法監視一個actor的生命周期

是這個意思嗎啊??


ActorSelection是ActorSystem中Actor樹形結構的切面邏輯視圖,在這個樹形結構的層級切面上可能存在0~N個Actor。ActorSelection允許以類似於「廣播」的形式向切面上的所有Actor發送消息。

通過ActorSelection發送一條消息時,會去遍歷該層級下的所有Actor並獲得其引用,然後以fire-and-forget的方式向這些Actor發送消息。

在消息向目標的傳遞過程中,與ActorSelection所匹配的Actor集合是會發生改變的,ActorSelection無法監控到Actor集合的實時變化。為了解決這個問題,通過發送請求並收集所有目標的響應、提取發送人(sender)的引用並且監控所有發現的具體的Actor來解決ActorSelection帶來的不確定性。解決的方案可能會在未來的版本提供。

ActorSelection只有當消息傳遞時,才會去查找發現現有的Actor。既不創建Actor,也不會去驗證Actor的存在。若ActorSelection發送消息的目標不存在時,這條消息會消失,不會放入系統的DeadLeater。


Actor References, Paths and Addresses

首先這句話的核心思想是:你只能watch 一個ActorRef,但是你不能watch 一個ActorSelection所對應的一組Actors。

主要是,ActorSelection出來的一組對象是變化的,不確定的。

其中,ActorRef,相當於Erlang中的PID,而ActorPath相當於DDD中的劃分。

《Erlang趣學指南》—— 基礎,因為學習 Akka不得不了解 Actor 模型的來源,以及實現。這本書生動有趣,不但涵蓋了基礎知識還包含了OTP的內容,即 Akka 集群。

《Akka 入門與實踐》 —— 入門,本書是入門的 Akka 書,可以保證您快速地上手 Akka,譯者也是摩根的大牛,清華高材生。

《反應式設計模型》—— 進階,本書我們還在翻譯,原書是前 Akka Tech Lead 編寫的 《Reactive Design Patterns》,這本書可以幫助你了解更深的理論層次的知識。

《領域驅動設計 ——軟體核心複雜性應對之道》 —— 進階,這本書雖然不是教你具體的 Akka代碼,但是對你如何使用 Akka 來解決複雜的現實的業務問題幫助非常大。

以上是個人的一點建議,雖然我也是為了擴大我們 Akka 社區的圈子:)

當然如果你想要了解 Netty 也可以關註:如何評價《Netty實戰》這本書? - 知乎


actor掛了重啟之後,select不會發生變化,ref已經變成一個新的對象了,watch select 不能感知actor是否掛了。


推薦閱讀:

Akka官方文檔中關於消息發送順序的這一段該如何翻譯呢??
共用的抽象模型(客戶及伺服器端)- HTTP 模型
AKKA~概念篇
共用的抽象模型(客戶及伺服器端)- URI 模型
akka有哪些比較好的學習資料?

TAG:Akka |