Contents

Reactor Pattern

Intent 意图

  • The Reactor design pattern handles service requests that are delivered concurrently to an application by one or more clients. 反应器设计模式处理由一个或多个客户端并发传递到应用程序的服务请求,
  • The application can register specific handlers for processing which are called by reactor on specific events. 应用程序可以注册用于处理的特定处理程序,这些处理程序由反应器在特定事件上调用
  • 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. 服务请求的解复用由同步事件解复用器执行

Class diagram 类图

/img/source/pattern/reactor/reactor.png

Applicability 应用

Use Reactor pattern when 以下场景可以使用Reactor 模式

  • A server application needs to handle concurrent service requests from multiple clients. 服务器应用程序需要处理来自多个客户机的并发服务请求
  • A server application needs to be available for receiving requests from new clients even when handling older client requests. 服务器应用程序需要能够接收来自新客户机的请求,即使在处理旧客户机请求时也是如此
  • A server must maximize throughput, minimize latency and use CPU efficiently without blocking. 服务器必须最大限度地提高吞吐量,最小化延迟并有效地使用CPU而不阻塞

Real world examples 真是使用项目

代码

Credits 参考