Scala --Actor Communication Model Overview

  1. Actor communication model summary

     

1) Actor Akka protocol used in the model information transmission.

2) Actor-based system, all things are Actor, as if the object-oriented design in which all things are objects.

3) Actor model as a concurrency model design and architecture. Only through the message communication, as shown in MailBox between Actor and Actor.

4) it can only be used between Actor and Actor message communication, when an Actor to another Actor message, the message is in order (message queue), simply posting the message to the appropriate mailbox.

5) how to handle the message is determined by the Actor receive messages, send messages Actor can wait reply process may be asynchronous.

Responsibilities 6) ActorSystem is responsible for creating and managing Actor they create, ActorSystem are singletons (ActorSystem may be a factory, specially created Actor), a JVM process can have a rather Acotr can have more of them.

7) Actor model is the concurrent model is more abstract.

8) Actor model is asynchronous, non-blocking, high-performance event-driven programming model. 9) Actor model is a lightweight event processing (1GB of memory can hold one million level a Actor), and therefore handling large high concurrent performance.

 2. ActorSystem hierarchy

 

1) ActorySystem create Actor

2) ActorRef: Actor will be understood to be an agent or a reference. Message is transmitted through ActorRef, not made by Actor

Send messages, which ActorRef message through, it means that the message which the issue Actor

3) message to the Dispatcher Message (message distributor), it gets the message, the message will be distributed to the corresponding

MailBox. (Note: Dispatcher Message will be understood to be a thread pool, the MailBox be understood to be a message queue, may slow

Chong multiple messages, follow FIFO)

4) Actor can be acquired by the message receive method, and then processed.

 

Actor model of message mechanism (the map)

1) Each message is a Message object. Message inherited Runable, because the Message is the thread class.

2) from the Actor model looks very cumbersome mechanism, but the programmer need only write Actor programming on it, the other to the Actor model can be completed.

3) A Actor B Actor send a message to give, you must first get A Actor (also known as hold) B Actor proxy object ActorRef to send a message

 

 

3. What is ActorPath

What is an Actor Path?

Since the Actor is created strict hierarchical way, there is a unique sequence Actor name, followed by recursively supervision links between child and parents Actor downward toward the root system is given. This sequence can be seen as file system folders, so we use the name "path" to refer to it, despite the actor and the hierarchy of the file system hierarchy there are some fundamental differences.

A path includes one actor anchor, it identifies the system actor, then the series path element, from the root to the specified actor guardian; path name of the actor elements are traversed, separated by slashes.

 4. How do you find Actor Reference? How to Create Actor Reference

Actor Reference is a subtype of ActorRef's main role is to support the ActorRef it represents Actor send a message.

Each actor can access its specification (local) through self reference, by default,

This reference is also used as the sender sent the message to another Actor.

During message processing, Actor may obtain a reference to the message sender by accessing the sender field.

 

 5. Scala Implicit conversion

Scala modified using implicit variables, methods, classes implicit conversion is supported

When the class is not present in the object call a method or member, the compiler will automatically convert objects implicit (depending on type)

使用implicit修饰的变量,可以在方法需要参数时,编辑器自动加载到方法参数中

隐式转换函数是以 implicit 关键字声明的带有单个参数的函数。这种函数将会自动应用,将值从一种类型转换为另一种类型

1)  隐式转换函数的函数名可以是任意的,隐式转换与函数名称无关,只与函数签名(函数参数类

型和返回值类型)有关。

 

2)  隐式函数可以有多个(即:隐式函数列表),但是需要保证在当前环境下,只有一个隐式函数能

被识别

隐式类使用有如下几个特点:

1) 隐式类的构造参数有且只能有一个

2)  隐式类必须被定义在“类”或“伴生对象”或“包对象”里,即隐式类不能是顶级的(top-level objects)。

3)  隐式类不能是 case class

4)  作用域内不能有与之相同名称的标识符

Guess you like

Origin www.cnblogs.com/eric666666/p/11203479.html