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

 

 

intent:
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 为了处理一个或者多个客户端并发分发到应用程序的请求.
应用程序由许多不同的方法组成来处理客户端端每一个特殊的请求.通过初始化一个dispatcher来管理注册的事件,同时负责分发请求.
多路复用服务器请求是通过一个同步的事件分发器.

 

Benefits
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.
 
提高应用程序的可移植性:
在执行事件的多路复用部分,可以根据不同的操作系统调用不同的函数来初始化Dispatcher.
在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)的激活.
在应用程序进程中在初始化Dispatcher的级别上序列化将消除对于复杂的同步和锁的使用.

 

 

 

相关文章推荐

用ACE的Reactor模式实现网络通讯时,ACE内部用WSAEventSelect函数把网络事件与一个事件对象关联起来,目的是为了后面用WaitForMultipleObjects函数统一处理。

用ACE的Reactor模式实现网络通讯时,ACE内部用WSAEventSelect函数把网络事件与一个事件对象关联起来,目的是为了后面用WaitForMultipleObjects函数统一处理。...
  • 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

thttp学习

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
  • 下载

目的入口(dst_entry)

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

Web Server版有的优点

  • 2013年06月04日 15:25
  • 11KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:The Reactor pattern 目的和优点
举报原因:
原因补充:

(最多只允许输入30个字)