Another article that understands reactor mode is a paper: "Reactor-siemens", the environment of the paper is an example of a log server:
The client sends the log to the log server, which logs the logs through various device outputs.
Intention:
The reactor design pattern handles service requests that are
Delivered concurrently to a application by one or more
Clients. Each service in a application may consist of
Serveral methods and is represented by a separate event handler
That's responsible for dispatching service-specific requests.
Dispatching of event handlers is performed by a initiation
Dispatcher, which manages the registered event handlers.
Demultiplexing of service Requests is performed by a
Synchronous event Demultiplexer.
The reactor design pattern is designed to handle requests sent by one or more clients to an application, each of which has a separate time processor, the event handler is distributed by a specific service request, and the time processor is distributed by initiation dispatcher , initiation dispatcher manages many event handlers, and the separation of service requests is handled by synchronized event separators.
We take out the core knowledge of the thesis and say:
Figure A is the process of initialization:
1. The logging server (1) registers the logging acceptor with the initiation Dispatcher to handle connection;
The log service is used to process connection requests by initializing the Distributor to log acceptor.
2. The logging server invokes the handle events method (2) of the initiation Dispatcher;
The log server invokes the handling event method of the initialization distributor.
3. The initiation Dispatcher invokes the synchronous event demultiplexing Select (3) operation to wait for connection requ ESTs or logging data to arrive;
Initializes the event-splitting method (select ()) of the Distributor's universal synchronization to wait for the connection request or the arrival of the data.
4. A client Connects (4) to the logging server;
A client connects to a service
5. The Logging acceptor is notified by the initiation Dispatcher (5) of the new connection request;
When a connection request comes in, the log sink is awakened by the initialization dispatcher.
6. The Logging Acceptor accepts (6) the new connection;
The log sink accepts a new connection.
7. The Logging acceptor creates (7) a Logging Handler to service the new client;
The log sink creates a log processor to service the new client.
8. Logging Handler Registers (8) its socket handle with the initiation Dispatcher and instructs I t when the socket becomes "ready for reading."
The log processor registers with the receiver by initializing the distributor to handle his socket, and instructs the distributor to remind him when the socket becomes ready.
Figure B is the process of subsequent other client connections:
1. The client sends (1) a logging record;
A client sends a log.
2. The initiation Dispatcher notifies (2) The associated Logging Handler when a client Logging the record was queued on it s socket handle by OS;
When a client's log enters the processor's queue, the dispatcher notifies the associated log processor.
3. The record was received (3) in a non-blocking manner (steps 2 and 3 repeat until the logging record has been Ed completely); The
Log accepts a non-blocking method by repeating steps 2 and 3 until all logs are accepted.
4. The Logging Handler processes the Logging record and writes (4) it to the standard output. The
Log processor processes logs and writes to the standard output.
5. The Logging Handler returns (5) control to the initiation Dispatcher ' s event loop.
The processing is completed to return to the initiation dispatcher time loop.