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. (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|