your programing

Simple Explanation for the “Reactor Pattern” with its Applications [closed]

lovepro 2020. 9. 25. 23:19
반응형

Simple Explanation for the “Reactor Pattern” with its Applications [closed]


Reactor pattern is explained in wikipedia, and it's a bit too abstract. Can you describe this pattern in a more concrete way? Ideally with code snippets or high-level class diagrams describing some applications of reactor pattern.


You'll might want to check the original paper describing it http://www.dre.vanderbilt.edu/~schmidt/PDF/reactor-siemens.pdf

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.


A reactor allows multiple tasks which block (say due to IO) to be processed efficiently using a single thread. The reactor manages a pool of handlers and runs an event loop. When it is called to perform a task it links it with a new or vacant handler making it active. The event loop (1) finds all the handlers that are active and unblocked (or delegates this to a dispatcher implementation) (2) executes each of these found handlers sequentially until they either complete or reach a point where they block. Completed handlers become inactive and vacant for reuse whereas blocked active handlers yield, allowing the event loop to continue. (3) Repeats from step (1)

참고URL : https://stackoverflow.com/questions/5566653/simple-explanation-for-the-reactor-pattern-with-its-applications

반응형