Reactor

This article told a brief introduction of reactor illustrated in POSA2, so there are more you want to know, refer to POSA2.

The Reactor architectural pattern allows event-driven applications to demultiplex and dispatch service requests that are delivered to an application from one or more clients.

There are five key participants in the Reactor pattern:

Handles: Handles are provided by operating systems to identify event sources, such as network connections or open files, that can generate and queue indication events. Indication events can originate from external sources, such as CONNECT events or READ events sent to a service from clients, or internal sources, such as  timeouts. When an indication event occurs on an event source, the event is queued on its associated handle and the handle is marked as 'ready'. At this point, an operation, such as an accept() or read(), can be performed on the handle without blocking the calling  thread.

Synchronous event demultiplexer:
A synchronous event demultiplexer is a function called to wait for one or more indication events to occur on a set of handles --- a handle set. This call blocks until indication events on its handle set inform the synchronous event demultiplexer that one or more handles in the set have become 'ready', meaning that an operation can be initiated on them without blocking.

Event handler: An event handler specifies an interface consisting of one or more hook methods. These methods represent the set of operations available to process application-specific indication events that occur on handles associated with an event handler.

Concrete event handlers: Concrete event handlers specialize the event handler and implement a specific service that the applicaton offers. Each concrete event handler is associated with a handle that identifies this service within the application. In particular,  concrete event handlers implement the hook methods responsible for  processing indication events received through their associated handle. Any results of the service can be returned to its caller by  writing output to the handle.

Reactor: A reactor defines an interface that allows applications to  register or remove event handlers and their associated handles, and run the application's event loop. A reactor uses its synchronous event demultiplexer to wait for indication events to occur on its handle set. When this occurs, the reactor first demultiplexes each indication event from the handle on which it occurs to its associated event handler, then it dispatches the appropriate hook method on the handler to process the event.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值