Table of Contents
Previous Section
The application, session, and component objects in a WebObjects application receive two messages that allow the objects to initialize themselves. The two methods, init and awake, are invoked in both scripted and compiled instances of WOApplication, WOSession, and WOComponent subclasses. The main difference between the methods is when they are invoked.
When objects are created, they receive an init message. The init method gives the receiver an opportunity to initialize its state and behavior just after it is created. The initialization is effective over the lifetime of an object; this lifetime varies according to the object's type:
- The WOApplication object exists from the time the application is started until it is terminated (either explicitly or through application time-out).
- The WOSession object persists through a session. As session is a period during which a particular user is accessing the application, and during which resources are allocated accordingly. An application can have multiple concurrent sessions. The application object creates a WOSession object if a request is the first from a user (that is, there is no session ID associated with it). Sessions can be explicitly terminated or can end when a session time-out---a period of no user activity---occurs.
- The WOComponent objects of an application are created each time a page is directly requested via URL and each time a pageWithName: message is sent to the application object. There are a couple exceptions to this. If page caching is turned on, as it is by default, the session object stores each component instance (page) at the end of each request-response loop. If the user backtracks through a session, the application restores page instances from this cache. Also, if the request component returns self or (preferably) nil in an action method, the application returns the cached instance of the request component rather than re-creating a new instance.
An object's awake method, on the other hand, is invoked at that point in each cycle of the request-response loop that the object begins to participate in request handling. This usually occurs right after init, except in those two cases noted above where an page is restored from a cache rather than created. In these cases, the awake method is invoked without a prior invocation of the init method.
See "How WebObjects Works" for a discussion of init and awake in the context of the request-response loop.
Table of Contents
Next Section