Documentation Archive Developer
Search
Table of Contents Previous Section

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:

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".

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:

	// WebScript DodgeDemo Application.wos 
	- awake {
		++requestCount;
		[self logWithFormat:@"Now serving request %@", requestCount];
	}


	// Java DodgeDemo Application.java 
	public void awake() {
		++requestCount;
		this.logString("Now serving request " + requestCount);
	}

Table of Contents Next Section