Table of Contents Previous Section

Session Initialization

A session object is created each time the application receives a request from a new user. An application may have multiple sessions running concurrently. The session ends when a session time-out value is reached.

In the session object's init method, you set the session's time-out value and initialize variables that should have unique values for each session. For example, in the CyberWind application, each session keeps track of which number it is. These values are changed in the session object's init method:

	//From CyberWind Session.wos
	- init {
		[super init];
		[self setTimeOut:120]; // session idle time is 2 minutes.
		[[self application] setSessionCount:[[self application] 
			sessionCount + 1];
		sessionNumber = [[self application] sessionCount];
		return self;
	}


	//From CyberWindJava Session.java
	public Session() {
		super();
		Application application = (Application)application();
		this.setTimeOut(120);
		application.setSessionCount(application.sessionCount() + 1);
		sessionNumber = application.sessionCount();
	}
The session object's awake method is invoked each time the user associated with the session makes a new request. After the application object has performed its own awake method, it restores the appropriate session object and sends it the awake message too.

The CyberWind application keeps track of the number of requests per session. It increments the number in the session's awake method.

	- awake {
		requestCount++;
	}

Table of Contents Next Section