Documentation Archive Developer
Search
Table of Contents Previous Section

Starting the Request-Response Loop

A WebObjects application can start up in one of two ways: automatically, when it receives a request (autostarting), or manually, when it's run from the command line. Either way, its entry point is the same as that of any C program: the main function. In a WebObjects application, main is usually very short. Its job is to create and run the application.

The main function begins by creating an autorelease pool that's used for the automatic deallocation of objects that receive an autorelease message. It then calls a function that loads the Java Virtual Machine (VM) if necessary.

The next step is to create a WOApplication (or WebApplication) object. This seems fairly straightforward, but in the init method or constructor the application creates and stores, in an instance variable, one or more adaptors. These adaptors, all instances of a WOAdaptor subclass, handle communication between an HTTP server and the WOApplication object. The application first parses the command line for the specified adaptors (with necessary arguments); if none are specified, as happens when the application is autostarted, it creates a suitable default adaptor.

The run method initiates the request-response loop. When run is invoked, the application sends registerForEvents to each of its adaptors to tell them to begin receiving events. Then the application begins running in its run loop.

The autorelease pool is released and recreated immediately before the run message is sent. Releasing the autorelease pool at this point releases any temporary variables created during initialization of the application class. Creating a new autorelease pool before sending run ensures that all variables created while running the application will be released. The last message releases the autorelease pool, which in turn releases any object that has been added to the pool since the application started running.

In the rest of this section, we look at what happens during one complete cycle of the request-response loop.

Table of Contents Next Section