官术网_书友最值得收藏!

The actor paradigm

All this concurrent programming is tricky. What is the correct synchronization and visibility? What if we could go back to our simpler sequential programming model and let the platform handle concurrency for us? 

Look at the following diagram:

Actors are the abstraction over threads. We write our code using the message passing model only. The only way of talking to an actor is by sending it a message.

Looking back at our UNIX shell model, the concurrency is there, but we don't deal with it directly. Using actors, we write code as if it were for a sequential message processor.

We need to be aware of the underlying threading model, though. For example, we should always use the tell and not the ask pattern, as shown in the picture. The tell pattern is where we send a message to an actor and then forget about it, that is, we don't block for an answer. This is essentially the asynchronous way of doing things:

An actor is a lightweight entity (threads are heavyweight). The creation and destruction of actors, monetarily speaking, is similar to the creation and destruction of Java objects. Just as we don't think of the cost while designing a UNIX pipeline (we focus largely on getting our job done), actors give us the same freedom.  

Actors also allow us to add supervision and restart capabilities, thereby allowing us to write robust, resilient systems. This is the let it crash philosophy. 

Actors are pretty old as a design; the paradigm was tried and tested in the Telecom domain using the Erlang language.

We will be looking at the actor model and the Akka library in detail in an upcoming chapter.   

主站蜘蛛池模板: 通许县| 宝丰县| 兴安县| 巴马| 镇康县| 镇沅| 赣榆县| 滁州市| 桐城市| 漾濞| 荔波县| 平顺县| 庆阳市| 宁晋县| 和平区| 乐平市| 治多县| 上思县| 灌阳县| 沁阳市| 山阳县| 绥中县| 宣汉县| 长春市| 遂川县| 璧山县| 舟曲县| 平遥县| 扶余县| 天门市| 麻江县| 庆阳市| 阿克陶县| 海兴县| 无锡市| 东明县| 资兴市| 宜州市| 田东县| 鄄城县| 荥阳市|