MODIFYING SERVICE PROVIDER CONTEXT INFORMATION TO FACILITATE LOCATING INTERCEPTOR CONTEXT INFORMATION
A method and system for tracking context information of a service provider and interceptors of service provider requests is provided. An interceptor modifies a portion of service provider context information to reference interceptor context information associated with a client. When the client requests a service of the service provider, the client provides the modified service provider context information along with the request. The interceptor uses the reference of the modified portion of the service provider context information to retrieve its context information. The interceptor then restores the modified portion of the service provider context information to the original unmodified portion, which the interceptor retained as part of its context information. The interceptor then forwards the request along with the original service provider context information to the service provider.
Latest Microsoft Patents:
This application is a continuation application of U.S. patent application Ser. No. 11/231,352, filed on Nov. 30, 2004, issued as U.S. Pat. No. 8,135,741, entitled “MODIFYING SERVICE PROVIDER CONTEXT INFORMATION TO FACILITATE LOCATING INTERCEPTOR CONTEXT INFORMATION,” which is incorporated herein in its entirety by reference.
BACKGROUNDComputer systems typically have services (e.g., file services) that are provided to clients (e.g., an application program). The services may implement a high-level service using low-level operations. For example, a file system may provide high-level commands to open and read files, which are implemented using low-level operations, such as sector seek and sector read. To access a file, an application program can request the file system to open the file and then read the file. The file system performs the necessary low-level operations to perform the high-level commands (e.g., open and read). Thus, the developer of an application program does not need to understand or use the low-level operations, but rather can rely on the file system for performing the appropriate low-level operations. The programs that request services of a service provider are referred to as clients. To have a service performed on its behalf, a client sends a request to a service provider of that service. The service provider performs the request and returns a result such as data or status information.
The requests for services can be satisfied synchronously or asynchronously by the service provider. When a request is satisfied synchronously, the client requesting the service waits until the service completes before continuing. For example, a client may request a service by invoking a read file function of a file system that returns after the file system has retrieved the data of the file. When a request is satisfied asynchronously, the client requesting the service does not wait until the service completes before continuing. However, when the service does complete, the service provider then notifies the client. For example, a client may request a service by invoking a read file function of the file system. That function may return immediately to the client so that the client can continue executing while the file system is reading the file. When the read completes, the service provider notifies the client, for example, by calling a callback function provided by the client or sending an event notification to the client.
One example of a client/service provider model is the Transport Device Interface (“TDI”) of Microsoft Corporation. TDI defines the interactions between a “transport provider” that implements a transport layer and a “transport client” that uses the services of the transport provider. One example of a transport provider is a TCP driver, and one example of a transport client is a redirector of a file system. The redirector invokes functions provided by the TCP driver to send and receive messages via TCP. Thus, the redirector can access files stored on other computing devices using the services of the TCP driver.
A service provider may need to maintain state information for the client between requests received from the client. For example, when a file system opens a file on behalf of a client, the file system may need to maintain a file control block so that when the client requests to read from that file, it can locate the file control block needed to satisfy the request. Such information may be referred to as “context information.” One technique for tracking context information is to return a handle to the client. The handle may be an operating system object that contains or references context information for a service provider session. A service provider session may be delimited by an open and a close request, such as an open file and a close file request. The service provider provides the handle to the client at the beginning of the session, and the client provides the handle to the service provider with each request. This allows the service provider to locate context information that is appropriate for the session. For example, the TDI model specifies that a WINDOWS file object is used as the handle for a TDI session.
It is often desirable to be able to extend the functions provided by a service provider. To support such extension, many systems allow for requests for services made by clients to a service provider to be intercepted or hooked. When a client makes a request to a service provider, an interceptor may receive the request and perform additional processing before forwarding the request to the service provider. The interceptor may also intercept the response to the request and perform additional processing before forwarding the response to the client.
Each interceptor, however, may need to maintain its context information. For example, an interceptor that simply logs to a file all invocations to a service provider during a session may have context information that includes the handle returned by the file system when the log file was opened or created.
A method and system for tracking context information of a service provider and interceptors of service provider requests is provided. The context tracking system is implemented by an interceptor. The interceptor modifies a portion of service provider context information to reference interceptor context information associated with a client. The interceptor then provides the modified context information to the client that requested the service. When the client requests a service of the service provider, the client provides the modified service provider context information along with the request. Upon receiving the request from the client, the interceptor uses the reference of the modified portion of the service provider context information to retrieve its context information. The interceptor then restores the modified portion of the service provider context information to the original unmodified portion, which the interceptor retained as part of its context information. The interceptor then forwards the request along with the original service provider context information to the service provider.
This Summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used as an aid in determining the scope of the claimed subject matter.
A method and system for tracking context information of a service provider and interceptors of service provider requests is provided. In one embodiment, the context tracking system is implemented by an interceptor. The interceptor modifies a portion of service provider context information to reference interceptor context information associated with a client. For example, when an interceptor receives a service provider context object (e.g., a file object), the interceptor replaces certain information of the context object with a reference to context information of the interceptor. The interceptor then provides the modified context information to the client that requested the service. When the client requests a service of the service provider, the client provides the modified service provider context information along with the request. Upon receiving the request from the client, the interceptor uses the reference of the modified portion of the service provider context information to retrieve its context information. The interceptor then restores the modified portion of the service provider context information to the original unmodified portion, which the interceptor retained as part of its context information. The interceptor then forwards the request along with the original service provider context information to the service provider. In this way, the interceptor can track its context information for the client without the overhead of having to look up the context information and of having to create additional context objects.
In one embodiment, the context tracking system is implemented by multiple interceptors that are layered between a client and a service provider. A client initiates a session with a service provider by sending a request to the service provider, which is first intercepted by the interceptor at the highest level. That interceptor forwards the request to the next lower level interceptor. Eventually, the lowest level interceptor receives the request, performs the requested service, and sends a response to the client that includes service provider context information, which is first intercepted by the lowest level interceptor. Upon receiving the response, the lowest level interceptor replaces a portion of the service provider context information with a reference to its context information, saves the portion before modification for later restoration, and forwards the response along with the modified service provider context information to the interceptor at the next higher layer. When the interceptor at the next higher layer receives the response with the modified service provider context information, it also replaces a portion of a service provider context with a reference to its context information, saves the portion before modification (which in this case is a reference to context information of the interceptor at the next lower layer) for later restoration, and forwards the response along with the newly modified service provider context information to the interceptor at the next higher layer. Eventually, the client receives the response with the modified service provider context information which contains a reference to the context information of the interceptor at the highest level.
When the client next requests a service from the service provider as part of the same session, the client sends a request to the service provider that includes the modified service provider information, which is first intercepted by the interceptor at the highest level. That interceptor uses the reference of the modified portion of the modified service provider information to retrieve its context information. That interceptor then replaces the portion of the service provider information that it previously modified with the unmodified portion that it retained and forwards the request along with the restored service provider context information, which is then intercepted by the interceptor at the next lower level. That next lower level interceptor uses the reference of the restored portion of the service provider context information to locate its context information. That interceptor then restores the portion of the service provider context information that it previously modified with the retained portion and then forwards the request along with the restored service provider context information to the interceptor at the next lower level. Eventually, the service provider receives from the interceptor of the lowest level that request along with the service provider context information restored to the original service provider context information. The service provider then services the request using the service provider context information without having to know that the request had been intercepted and the service provider context information had been modified by various interceptors.
In one embodiment, a client during a single session may request a service of a service provider before a previous request has been completed; that is, the previous request is still outstanding. For example, if the requests are serviced synchronously, then one thread of the client may send a request by invoking a function, and before that invoked function returns, another thread of the client may send a request by again invoking that function. If the requests are serviced asynchronously, then a thread of the client may send a request, and before the response is received asynchronously (e.g., by invocation of a callback function), the client (on the same or a different thread) may send another request. Whenever a client sends a request during a session while another request of that session is outstanding, the service provider context information is considered currently in use by the previous request and the modified portion may be in an unknown state. For example, the modified portion may contain the original unmodified content, content newly modified by the service provider as part of servicing the outstanding request, content modified by the interceptors as the response from the service provider is intercepted, and so on. Thus, an interceptor cannot modify the service provider context information without risk of overwriting content needed by the service provider or an interceptor in processing the outstanding request.
To prevent an interceptor from overwriting content needed by the service provider or another interceptor processing an outstanding request, an interceptor reverts to a conventional technique of looking up its context information based on the reference to service provider context information. When an interceptor receives a request, it determines whether a modified portion of the service provider context information contains a reference to its context information. If not, the interceptor knows that the service provider or another interceptor is processing another outstanding request. The interceptor may store a unique identifier of itself when it modifies service provider context information. If that unique identifier has been changed, then the interceptor knows that the service provider or another interceptor is processing an outstanding request. In an alternative embodiment, an interceptor may use a reference counting technique to determine whether there is an outstanding request. If a request is outstanding, then the interceptor uses the reference (e.g., pointer to or address of) to the service provider context information to locate the interceptor's context information. For example, the interceptor may use a conventional hash table data structure to locate its context information. The interceptor then performs the processing of the request and forwards the request to the interceptor at the next lower level without modifying the service provider context information. The interceptor at the next lower level again detects that a unique identifier has been changed and looks up its context information using a conventional technique. Eventually, the interceptor at the lowest level forwards the request to the service provider without modifying the service provider context information. The service provider can then process the request with the server provider context information that it expects. In this way, the interceptors can service requests issued without having to look up their context information so long as there is no outstanding request. If requests are seldom issued with outstanding requests, then the context tracking system may provide significant performance improvements over conventional techniques.
The computing devices on which the context tracking system may be implemented may include a central processing unit, memory, input devices (e.g., keyboard and pointing devices), output devices (e.g., display devices), and storage devices (e.g., disk drives). The memory and storage devices are computer-readable media that may contain instructions that implement the context tracking system. In addition, the data structures and message structures may be stored or transmitted via a data transmission medium, such as a signal on a communications link. Various communications links may be used, such as the Internet, a local area network, a wide area network, or a point-to-point dial-up connection.
The context tracking system may be implemented in various operating environments that include personal computers, server computers, hand-held or laptop devices, multiprocessor systems, microprocessor-based systems, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like. The context tracking system may also be implemented on computing devices such as cell phones, personal digital assistants, consumer electronics, home automation devices, and so on.
The context tracking system may be described in the general context of computer-executable instructions, such as program modules, executed by one or more computers or other devices. Generally, program modules include routines, programs, objects, components, data structures, and so on that perform particular tasks or implement particular abstract data types. Typically, the functionality of the program modules may be combined or distributed as desired in various embodiments.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims. Accordingly, the invention is not limited except as by the appended claims.
Claims
1. A method performed a computing device for tracking context of a service provider by an interceptor of requests from a client to the service provider, the method comprising:
- receiving, from the service provider, service provider context information;
- generating interceptor context information representing state information of the interceptor maintained for communication between the client and the service provider;
- generating a copy of a portion of the service provider context information, the copy representing a retained portion of the service provider context information;
- modifying the service provider context information to replace the copied portion with a reference to the interceptor context information, the replaced portion representing a modified portion of the service provider context information;
- providing the modified service provider context information to the client; and
- upon receiving from the client a request for a service of the service provider, the request including the modified service provider context information, retrieving, from the modified portion of the modified service provider context information included in the request, the reference to the interceptor context information representing the state information for communication between the client and the service provider; replacing the modified portion of the modified service provider context information included in the request with the retained portion to restore the service provider context information; and forwarding the request to the service provider, the forwarded request including the restored service provider context information.
2. The method of claim 1 wherein the retained portion of the service provider context information is stored in association with the interceptor context information.
3. The method of claim 2 including, upon receiving from the client a request for a service of the service provider, retrieving the retained portion stored in association with the interceptor context information identified by the retrieved reference.
4. The method of claim 1 including upon receiving from the client a request for a service of the service provider while a request for a service of that service provider is still outstanding, not modifying the service provider context information that was previously modified.
5. The method of claim 1 including upon receiving from the client a request for a service of the service provider while a request for a service of that service provider is still outstanding, using a reference to the service provider context information to locate interceptor context information.
6. The method of claim 1 including:
- upon receiving from the client a request for a service of the service provider while a
- request for a service of that service provider is still outstanding, using a reference to the service provider context information to locate interceptor context information; and not modifying the modified service provider context information.
7. A computer-readable storage medium storing computer-executable instructions for controlling a computing device to track context to an interceptor of requests from a client to a service provider, by a method comprising:
- receiving by the interceptor service provider context information;
- generating interceptor context information representing state information of the interceptor for communication between the client and the service provider;
- generating a copy of a portion of the service provider context information, the copy representing a retained portion of the service context information as received;
- modifying the service provider context information to replace the copied portion with a reference to the interceptor context information, the replaced portion representing a modified portion of the service provider context information;
- forwarding the modified service provider context information on to the client; and
- upon receiving a request for a service of the service provider, the request including the modified service provider context information, retrieving, from the modified portion of the modified service provider context information included in the request, the reference to the interceptor context information representing the state information of the interceptor; replacing the modified portion of the modified service provider context information included in the request with the retained portion to restore the service provider context information; and forwarding the request on to the service provider, the forwarded request including the restored service provider context information.
8. The computer-readable storage medium of claim 7 wherein the interceptor receives the service provider context information from a next lower-level interceptor and forwards the request on to the service provider via the next lower-level interceptor.
9. The computer-readable storage medium of claim 8 wherein the interceptor forwards the modified service provider information on to the client via a next higher-level interceptor and receives the request for service from the next higher-level interceptor.
10. The computer-readable storage medium of claim 7 wherein the interceptor forwards the modified service provider information on to the client via a next higher-level interceptor and receives the request for service from the next higher-level interceptor.
11. The computer-readable storage medium of claim 7 wherein the retained portion of the service provider context information is stored in association with the interceptor context information.
12. The computer-readable storage medium of claim 11 including, upon receiving a request for a service of the service provider, retrieving the retained portion stored in association with the interceptor context information identified by the retrieved reference.
13. The computer-readable storage medium of claim 7 including upon receiving a request for a service of the service provider while a request for a service of that service provider is still outstanding, not modifying the service provider context information that was previously modified.
14. The computer-readable storage medium of claim 7 including upon receiving from the client a request for a service of the service provider while a request for a service of that service provider is still outstanding, using a reference to the service provider context information to locate interceptor context information.
15. A computing device for tracking context of provided to an interceptor of requests from a client to a service provider, comprising:
- a memory storing computer-executable instructions of an interceptor that: receives service provider context information; generates interceptor context information representing state information of the interceptor for communication between the client and the service provider; generates a copy of a portion of the service provider context information, the copy representing a retained portion of the service context information as received; modifies the service provider context information to replace the copied portion with a reference to the interceptor context information, the replaced portion representing a modified portion of the service provider context information; forwards the modified service provider context information on to the client; and upon receiving a request for a service of the service provider, the request including the modified service provider context information, retrieves, from the modified portion of the modified service provider context information included in the request, the reference to the interceptor context information representing the state information of the interceptor; replaces the modified portion of the modified service provider context information included in the request with the retained portion to restore the service provider context information; and forwards the request on to the service provider, the forwarded request including the restored service provider context information; and
- a processor for executing the computer-executable instructions stored in the memory.
16. The computing device of claim 15 wherein the interceptor receives the service provider context information from a next lower-level interceptor and forwards the request on to the service provider via the next lower-level interceptor.
17. The computing device of claim 16 wherein the interceptor forwards the modified service provider information on to the client via a next higher-level interceptor and receives the request for service from the next higher-level interceptor.
18. The computing device of claim 15 wherein the interceptor forwards the modified service provider information on to the client via a next higher-level interceptor and receives the request for service from the next higher-level interceptor.
19. The computing device of claim 15 wherein the retained portion of the service provider context information is stored in association with the interceptor context information.
20. The computing device of claim 16 wherein the interceptor, upon receiving a request for a service of the service provider, retrieves the retained portion stored in association with the interceptor context information identified by the retrieved reference.
Type: Application
Filed: Mar 5, 2012
Publication Date: Jun 28, 2012
Applicant: Microsoft Corporation (Redmond, WA)
Inventors: Bhupinder S. Sethi (Redmond, WA), Sachin C. Sheth (Bothell, WA)
Application Number: 13/412,325