Active Object模式,也称为Actor模式
对象分为主动对象和被动对象,主动对象内部包含一个线程,可以自动完成动作或改变状态,而一般的被动对象只能通过被其他对象调用才有所作为。在多线程程序中,经常把一个线程封装到主动对象里面。
Active Object 设计模式的本质是解耦合方法的调用 (Method invocation) 与方法的执行 (Method execution), 方法调用发生在调用者线程, 而方法的执行发生在独立于调用者线程的Active Object线程, 并且这个过程对用户透明.
Active Object模式,也称为Actor模式。Active Object即主动对象,它不仅拥有独立线程,并且可以从外部接收异步消息,并能配合需要返回处理结果。
Activie Object将独立线程,接收异步消息并返回处理结果这些方面看作一个整体。
分离调用和执行,还使用了生产者消费者模式。
Active Object 模式是Command模式的一种,是实现多线程控制的一项古老技术 .
The active object design pattern decouples method execution from method invocation for objects that each reside in their own thread of control.[1] The goal is to introduce concurrency, by using asynchronous method invocation and a scheduler for handling requests.[2]
The pattern consists of six elements:[3]
- A proxy, which provides an interface towards clients with publicly accessible methods.
- An interface which defines the method request on an active object.
- A list of pending requests from clients.
- A scheduler, which decides which request to execute next.
- The implementation of the active object method.
- A callback or variable for the client to receive the result.
https://en.wiki.hancel.org/wiki/Active_object