The Reactor pattern 目的和优点

翻译 2015年07月08日 16:05:24

the Reactor Pattern from  An Object Behavioral Pattern for Demultiplexing and Dispatching Handles for Synchronous Events



The Reactor design pattern handles service requests that are delivered concurrently to an application by one or more clients.
Each service in an application may consist of serveral methods and is represented by a separate event handler that is responsible for dispatching service-specific requests.
Dispatching of event handlers is performed by an initiation dispatcher, which manages the registered event handlers.
Demultiplexing of service requests is performed by a synchronous event demultiplexer.
Reactor Pattern 为了处理一个或者多个客户端并发分发到应用程序的请求.


The Reactor pattern offers the following benefits:

Separation of concerns:
The Reactor pattern decouples application-independent demultiplexing and dispatching mechanisms from application-specific hook method functionality.
The application-independent mechanisms become reusable components that know how to demultiplex events and dispatch the appropriate hook methods defined by Event Handlers.
In contrast, the application-specific functionality in a hook method knows how to perform a particular type of service.

Reactor Pattern 通过在应用程序中指定函数把多路复用和分发器分离机制来解耦合.

Improve modularity, reusability, and configurability of event-driven applications:
The pattern decouples application functionality into separate classes.
For instance, there are two separate classes in the logging server: one for establishing connections and another for receiving and processing logging records.
This decoupling enables the reuse of the connection establishment class for different types of connection-oriented services
(such as file transfer, remote login, and video-on-demand).
Therefore, modifying or extending the functionality of the logging server on only affects the implementation of the logging handler class.

Reactor Pattern 把应用程序分离成不同的部分:
例如,在LoggingServer 中把程序分离成2个部分,一部分处理链接的建立(Socket的建立),另外一部分来处理日志的记录.(Socket I/O 输入输出部分)
所有,修改和拓展LoggingServer的功能仅仅影响Logging handler 实现部分.

Improves application portability:
The Initiation Dispatcher’s interface can be reused independently of the OS system calls that perform event demultiplexing.
These system calls detect and report the occurrence of one or more events that may occur simultaneously on multiple sources of events.
Common sources of events may in-clude I/O handles, timers, and synchronization objects.
On UNIX platforms, the event demultiplexing system calls are called select and poll .
In the Win32 API , the  WaitForMultipleObjects system call performs event demultiplexing.
在Unix 操作系统上,事件的多路复用可以使用select() 和Poll()函数.
在win32 API中,可以使用WaitForMultipleObjects()来调用事件的多路复用.

Provides coarse-grained concurrency control:
The Reactor pattern serializes the invocation of event handlers at the level of event demultiplexing and dispatching within a process or thread.
Serialization at the Initiation Dispatcher level often eliminates the need for more complicated synchronization or locking within an application process.

Reactor Pattern 模型在一个线程或者一个进程中在多路复用和分发器的级别上序列化事件处理(event handler)的激活.






  • iw1210
  • iw1210
  • 2014年07月07日 18:26
  • 889

Reactor Pattern Explained

Handling concurrent events a Server receives is often thought of as a use-case for creating a sepa...

Reactor pattern - Introduction by wiki

The reactor design pattern is an event handling pattern for handling service requests deliveredcon...

Reactor模式 - @ Pattern by java【转载内容】

Reactor模式 - @ Pattern by java   经典的网络服务的设计如下图,在每个线程中完成对数据的处理: 但这种模式在用户负载增加时,性能将下降非常的快。我们需要重新寻找一个新的方...
  • taizans
  • taizans
  • 2013年08月17日 10:14
  • 749

thttpd源码小分析之Reactor pattern


the reactor pattern and java nio

在《java NIO》作者PPT《How to Build a Scalable Multiplexed Server With NIO》 和 Doug Lea 《Scalable IO in Jav...

2.0 flash优点

  • 2014年02月12日 20:52
  • 834KB
  • 下载


  • 2012年09月08日 16:55
  • 49KB
  • 下载


最终生成的IP数据报的路由称为目的入口(dst_entry),目的入口反映了相邻的外部主机在主机内部的一种“映象”,目的入口在内核中的定义如下:     struct dst_entry     ...

Web Server版有的优点

  • 2013年06月04日 15:25
  • 11KB
  • 下载
您举报文章:The Reactor pattern 目的和优点