3.3 asynchronous completion token, Act)
1. Problem
When a client applicationProgramWhen an operation request to one or more services is called asynchronously, each service returns its response to the application through a completion event. Then the application must break down the event multiple times to the corresponding handler. A handler can be a function or object used to process Asynchronous Operation responses contained in a completed event. To effectively solve this problem, you need to consider the following three mandatory conditions:
· A service may not know the context in which the client application calls its operations asynchronously. Therefore, the client application, rather than the server, must be responsible for determining how to break down the event to the handler assigned to process it.
· To determine how the client can perform multi-path decomposition and event processing after the asynchronous operation is completed, communication between the client application and the service is required. This communication overhead should be minimized.
· When the service response reaches a client application. Applications should process Asynchronous Operation responses in as little time as possible.
2. Solution
It indicates the initiator. if the service response information is processed, it is transmitted together with each asynchronous operation called by the client Startup Program for a service. After the operation is complete, the information is returned to the Startup Program. With this information, you can efficiently break down the response multiple times so that the startup program can process it accordingly.
Specifically, an asynchronous completion mark is created for each asynchronous operation called by each client Startup Program for a service. Asynchronous completion tag includes information that uniquely identifies the completion handler. The service saves the asynchronous completion identifier, but does not modify it. When the service responds to the Startup Program, the response includes the original asynchronous completion mark. In this way, the startup program can use the asynchronous completion mark to identify the completion handler used to process the response from the original asynchronous operation.
3. Structure
The service provides some functions that can be accessed asynchronously.
The client starts a program to call services asynchronously. It also splits the responses returned by these operations into the specified processing program. A completion handler is a function or object in an application that processes service responses.
An asynchronous completion mark (Act) contains information that identifies the completion processing program of a Startup Program. When the startup program calls an operation, it passes the asynchronous completion mark to the service. When the asynchronous operation is complete, the service returns the unchanged asynchronous completion mark to the Startup Program. The processing program then processes the response from the original asynchronous operation. The service stores a set of asynchronous completion tags for processing multiple asynchronous operations called by the Startup Program at the same time.
4. Implementation
1) define the expression of the asynchronous completion mark. The asynchronous completion mark indicates that it should be meaningful for the Startup Program and the completion handler, but it is not transparent to the service.
· The pointer completes the tag asynchronously. Generally, a pointer pointing to the structure in the programming language is used to indicate the completion of the tag asynchronously.
· The object reference completes the tag asynchronously. To simplify the use of asynchronous completion tags in heterogeneous systems, asynchronous completion tags can be represented as object references defined in distributed object computing middleware (such as CORBA.
· The index completes the tag asynchronously. The asynchronous completion mark is the index of the table of the completion handler that can be accessed by the Startup Program.
2) select to save the asynchronous completion tag and Policy in the startup program.
· Implicit asynchronous completion mark. The asynchronous completion mark is defined as the address of the completion handler object of the Startup Program, which can be implicitly saved. This policy is usually used in asynchronous completion marking of pointers or object references. The time and space efficiency of the implicit asynchronous completion mark is very high, but the robustness and security are not good.
· Explicitly complete the tag asynchronously. The startup program saves the asynchronous completion mark in a clear data structure. This policy applies to the asynchronous completion mark of the index. The advantage of saving asynchronous completion tags using explicit data structures in the startup program is that it improves robustness and reliability.
3) Determine how to pass the asynchronous completion mark from the Startup Program to the service.
· Implicit parameters are usually stored transparently in the context or environment passed to the service.
· Explicit parameters are defined in asynchronous operations.
4) determine the policy for saving the asynchronous completion tag in the service.
· If the service is executed synchronously, the asynchronous completion mark can be simply resident in the runtime stack of the service during service processing, if the service and the Startup Program are running in different threads or processes, service operations can be performed synchronously, but an asynchronous programming model is still provided to the Startup Program.
· If the service processes Startup Program operations asynchronously, it may need to process multiple requests simultaneously. In this case, an asynchronous completion tag must be maintained in the data structure, which resides outside the runtime stack range of any service.
5) determine the number of times the asynchronous completion tag is available.
· The startup program passes a separate asynchronous completion mark for each asynchronous call. However, a startup program can call an Asynchronous Operation multiple times for a service. For each call, it can assign the same completion handler to process the response of the operation, so that the overhead of creating and destroying the asynchronous completion tag is minimized.
· The service returns only one asynchronous completion mark and a response from the asynchronous operation. However, once a specific event occurs, the service can also use the same asynchronous completion tag to send a system response. In this case, the asynchronous completion mark from an Asynchronous Operation call can be returned to the Startup Program multiple times.
6) determine the policies for the Startup Program to decompose the asynchronous completion mark multiple channels to complete the handler Hook method.
· Queuing completion events. An asynchronous completion tag is placed in a completion event queue by a service or a local service proxy remotely. The Startup Program deletes the asynchronous completion tag from the completion event queue, and controls its subsequent processing with information encapsulated in the asynchronous completion tag.
· Callback. The Startup Program transmits a callback function or object to the service. When asynchronous operations are completed, the service or local service proxy can call the callback function. Asynchronous completion mark can be returned to the callback function or object as a parameter, and type conversion is performed downward to find the complete processing program for efficient processing.
5. Conclusion
Advantages:
1) Simplify the data structure of the Startup Program. The Startup Program does not need a complex data structure to combine service response with the completion processing program. The asynchronous completion mark returned by the service can be converted or re-interpreted downward, so that it carries the information required by the Startup Program to break it down to the corresponding completion activity.
2) Efficient status query. The time for marking asynchronous completion has good performance because it does not need to perform complex analysis on the data returned together with the service response. The information required to combine the response with the previous request can be stored in the asynchronous completion mark or in the object referenced by the asynchronous completion mark. On the other hand, the asynchronous completion mark can be used as a pointer or index to access the status for efficient access, thus eliminating expensive table searches.
3) high space efficiency. The asynchronous completion mark can provide sufficient information to the application when the minimum data space is consumed, and combine a large number of states to process asynchronous operations.
4) flexibility. To use the asynchronous completion tag of a service, the custom asynchronous completion tag does not have to inherit an interface. In this way, the application can use an object that cannot predict its type conversion or that cannot perform type conversion as an asynchronous tag transfer. The general feature of asynchronous completion mark can be used to associate any type of objects with an asynchronous operation.
5) Non-authoritarian concurrency policies. This operation can be performed asynchronously because the time-consuming operation status can be effectively restored from the asynchronous completion mark. Therefore, the startup program can be single-threaded or multi-threaded, depending on application requirements.
Disadvantages:
1) Memory leakage. If the Startup Program uses a pointer to the dynamically allocated memory area as the asynchronous completion mark, a memory leak occurs when the service cannot return the asynchronous completion mark (for example, when the service crashes. The Startup Program considering this possibility should maintain a separate asynchronous completion tag storage pool or table, so that explicit garbage collection can be performed when the service fails or the service breaks the asynchronous completion tag.
2) authentication. When an asynchronous event is completed, the asynchronous completion mark is returned to the Startup Program, which requires authentication before use. This authentication is required if the server cannot regard the asynchronous completion tag as non-transparent and may change the value of the asynchronous completion tag.
3) Application re ing. If the asynchronous completion mark is a direct pointer to the memory, an error occurs when a part of the application is directly mapped to the virtual memory. In a persistent application that is restarted after the crash, and for objects allocated from the memory ing address space, this may happen. To prevent these errors, you can use the index of the storage pool as an asynchronous completion mark. This indirect method provided by "Asynchronous index completion marking" can prevent re- ing, because the index remains valid during the re- ing process, but the pointer to the memory does not.