reactor design pattern

reactor design pattern


详见:http://en.wikipedia.org/wiki/Reactor_pattern


The reactor design pattern is an event handling pattern for handling service requests delivered(交付的)concurrently(并行的) to a service handler by one or more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers.


Properties

All reactor systems are single threaded by definition, but can exist in a multithreaded environment.


Benefits

The reactor pattern completely separates application specific code from the reactor implementation, which means that application components can be divided into modular(模块化), reusable(可复用的) parts. Also, due to the synchronous calling of request handlers, the reactor pattern allows for simple coarse-grain concurrency while not adding the complexity of multiple threads to the system.


Limitations

The reactor pattern can be more difficult to debug than a procedural pattern due to the inverted flow of control. Also, by only calling request handlers synchronously, the reactor pattern limits maximum concurrency, especially on symmetric(相称性的,均衡的) multiprocessing hardware. The scalability of the reactor pattern is limited not only by calling request handlers synchronously, but also by the demultiplexer(多路信号分离器,多路输出选择器)。


最后看一个在网络编程中的Reactor模式示意图,

reactor design pattern_第1张图片

==================END==================

你可能感兴趣的:(reactor design pattern)