Using a state machine interface, it is possible to implement a variety of protocols in the AFPA framework. Protocol specific code for a given application such as Web serving is encapsulated in an AFPA module.
Each AFPA module is partitioned into three components: state, program actions, and control elements. AFPA manages three types of internal state data for each module instance: global data, connection data, and request data. Global data is data independent of each connection and request. Connection data is information that changes on a per connection basis. Request data is information that changes per request within the same connection. State functions are either written by the module developer, exist in another AFPA module's library of state functions, or are intrinsic to AFPA as a general service. State functions indirectly manage state transitions through a separately managed table. The layer of indirection permits state functions to be reusable and reconfigurable.
A simplified version of the state machine used by the AFPA HTTP module is shown in Figure 1. The state machine illustrates how the HTTP module can be used as a standalone Web cache, work in conjunction with a user-mode Web server, or act as a front end Web cache for one or more back end Web servers. The module implements a function corresponding to each of the following client connection states:
This function is invoked when new data is received on a connection. When sufficient data has arrived to complete a well-formed request, the function computes the parsed request, storing it in the connection data structure.
This function uses the parsed request in the connection data structure to perform a key-based lookup in the AFPA cache. If successful, the cache object is sent. If unsuccessful, the connection transitions to Derive Miss Response state.
This function is invoked when a response is not found in the AFPA cache. The HTTP module either performs necessary file I/O to create a new cache object (Derive Uncached Response), passes the request to a local user-mode Web server (Derive Deferred Response), or sends the request to a remote Web server (Derive Remote Response).
This function creates a cache object and response header. The file is either read into the newly created cache object or a reference to the file system cache is created depending on the AFPA implementation. Once created, the cache object is sent to the client. Any errors creating the cache object may result in sending request to another Web server or generating an error response.
This function routes the parsed request to a remote server. In versions of AFPA modules acting as content-based routers, this function expands to an alternate state machine for managing connections to other Web servers.
This function routes the parsed request to a user-mode server which takes control of the connection.
The Send Engine is a function invoked by the Derive Cached Response or Derive Uncached Response states. The send engine sends the cache object. Persistence, serialization, and fragmentation of large requests are managed by AFPA. This function is exported by the AFPA runtime system.