当前位置:网站首页>Detailed introduction of distributed pressure measurement system VIII: basic introduction of akka actor model

Detailed introduction of distributed pressure measurement system VIII: basic introduction of akka actor model

2022-07-06 20:17:00 Wang Wei, Wang Pangpang

actor Model

Previous picture , I got it online :
 Insert picture description here
It looks like sending email , Think of this model as sending email , And there's a mailbox , It seems to be multi person communication , One actor It's just one person ,actor Communicate with each other , Using email . I have used email at ordinary times , What are the characteristics of email , Is the advantage of asynchronous non blocking , The sender may not care when the receiver receives , Whether it has been handled , He just sends it to his mailbox , Of course, the recipient is also , He doesn't care who sent it to him , If he wants to deal with the mail, he takes it out of the mailbox , Process according to the specific email content .

characteristic

  1. Asynchronous non-blocking , Those who write letters belong to those who write letters , Write it and put it in the mailbox , The receiver belongs to the receiver , Deal with it whenever you want , In fact, it is similar to message queue , Send a message to the queue and it's done , Go on with the rest , That is, the thread can not wait .
  2. Data is isolated from each other , Event driven , Those who write letters cannot control the receipt , What the recipient wants to do is up to him , His own data can only be modified by himself , Relative to others is isolation , That is, there is no need to share data , Maintain their own data , Only modify the data according to the incoming letter , And the letters are orderly in the queue , The time to deal with it is 1 Sealed , Therefore, there is no concurrent data sharing problem
  3. No need for synchronous lock , There is no shared data , There is no need for synchronous lock
  4. Good concurrency , There is no need for threads to synchronize in order to share resources , Greatly improve the utilization of threads

akka System structure

Whole actor In fact, it is an attribute structure , It should be convenient for unified management, scheduling and query :
 Insert picture description here

akka Core elements

 Insert picture description here

akka Dependencies between core elements

You can see ,actorCell You can visit Actor, however actorCell It's internal ,Actor No direct access , therefore ,Actor You can't directly modify another Actor The state of , Thread safety can be achieved
 Insert picture description here

akka actor System initialization process

 Insert picture description here

akka actor The system creates a node process

 Insert picture description here

akka actor Send and process messages

 Insert picture description here

The above are sorted out from the source code , There may be something wrong , Some specific details should be read by yourself .
Okay , That's it today , I hope it is helpful for learning and understanding , Don't spray when the great God sees , Only for their own learning and understanding , Limited ability , Please forgive me .

原网站

版权声明
本文为[Wang Wei, Wang Pangpang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131226528280.html