Application initialization – Apple WebObjects 3.5 User Manual
Page 47

Initialization and Deallocation Methods
47
- awake {
/* initializations go here */
}
public void awake () {
/* initializations go here. */
}
Application Initialization
The application
init
method is invoked only once, when the application is
launched. You perform two main tasks in the application’s
init
method:
•
Initialize application variables
•
Configure applicationwide settings
For example, the Visitors application has this
init
method in
Application.wos
:
// WebScript Visitors Application.wos
- init {
[super init];
lastVisitor = @"";
[self setTimeOut:7200];
return self;
}
// Java Visitors Application.java
public Application () {
super();
...
lastVisitor = "";
setTimeOut(7200);
...
}
This method begins by calling the application’s
init
method. Then, it
initializes the application variable
lastVisitor
to be the empty string. (The
application has just started, so there has been no last visitor.) Finally, it sets
the application to terminate after it has been running 2 hours.
This example sets the application time-out value. You might want to do
other configurations in the application object’s
init
method as well. For
example, you can control how pages and components are cached and how
state is stored. For more information, read the chapter “Managing State”
(page 109).
The application’s
awake
method is invoked at the start of every cycle of the
request-response loop. Therefore, in the
awake
method, you perform
anything that should happen before each and every user request is
processed. For example, the DodgeDemo example application keeps track
of the number of requests the application has received. It increments and
logs that number at the top of the request-response loop: