Asynchronous Completion Token

来源:互联网 发布:如何获得软件源代码 编辑:程序博客网 时间:2024/04/29 06:59
 This article is extracted from POSA2 as my reading note.

See a familiar scene that all people experienced now and then: HTTP Cokkies. Web servers can use the Asynchronous Completion Token pattern if they expect responses from Web browsers. For example, a Web server may expect a user to transmit data they filled into a form that was downloaded from the server to the browser in response to a previous HTTP GET request. Due to the sessionless design of the HTTP protocol, and because users need not complete forms immediately, the Web server, acting in the role of a initiator, transmits a cookie(the ACT) to the Web browser along with the form. This cookie allows the server to associate the user's response with his or her original request for the form. Web browsers need not interpret the cookie, but simply return it unchanged to the Web server along with the completed form.

The Asynchronous Completion Token design pattern allows an application to demultiplex and process efficiently the responses of asynchronous operations it invokes on services. Four participants form the structure of the ACT pattern:

Service: A service provides some type of functionality that can be accessed asynchronously.

Initiator: A client initiator invokes operations on a service asynchronously. It also demultiplexes the response returned by these operations to a designated completion handler.

Completion handler: It is a function or object withit an application that is responsible for processing service responses.

ACT: An asynchronous completion token contains information that identifies a particular initiator's completion handler. The initiator passes the ACT to the service when it invokes an operation; the service returns the ACT to the initiator unchanged when the asynchronous operation completes. The initiator then uses this ACT to efficiently demultiplex to the completion handler that processes the response from the original asynchronous operation. Services can hold a collection of ACTs to handle multiple asynchronous operations invoked by initiators simultaneously.

 

 

原创粉丝点击