Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 554
Eleco Avatar asked Apr 06 '11 12:04

Eleco


People also ask

How does a reactor pattern work?

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.

Why Reactor pattern?

The purpose of the Reactor design pattern is to avoid the common problem of creating a thread for each message, request, and connection. Then it receives events from a set of handlers and distributes them sequentially to the corresponding event handlers.

Where is Reactor pattern used?

Reactor Pattern is used to avoid the blocking of the Input/Output operations. It provides us with a handler that is associated with I/O operations.

What is event loop in reactor?

Event Loop checks the event queue, picks the event and provides result to its callback handler. The event loop send the response to the application by callback handler or stores another event in the event demultiplexer. Event loop will run continuously and check the event queue until event queue get empty.


1 Answers

You 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.

like image 160
reese Avatar answered Oct 10 '22 07:10

reese