Package aquarium :: Package session :: Module SessionContainer :: Class SessionContainer
[show private | hide private]
[frames | no frames]

Class SessionContainer

Known Subclasses:

This is a container for sessions.

A container class is needed because:

On the other hand, no instance state is kept, so one instance of this class is just as good as another. All state is kept in the class. I'd use a singleton, but the version of Python I'm stuck with doesn't have class methods.

Concerning locking: in general, a global lock (of some sort) should be used so that creating, deleting, reading, and writing sessions is serialized. However, it is not necessary to have a lock for each session. If a user wishes to use two browser windows at the same time, the last writer wins.

Concerning aquarium.util.AquariumClass: this class does not subclass aquarium.util.AquariumClass and does not require a ctx parameter in its constructor. Subclasses may choose to mixin aquarium.util.AquariumClass as necessary, but they will then require a ctx in their constructors. aquarium.util.Aquarium is aware of this.

This base class is useful for mutlithreaded environments. For other environments, such as CGI, it simply provides an API.

The following class level constants are defined:

This is the length of standard sid's.

These are needed since not all "mutexes" provide the same API, unfortunately:

Acquire the global lock.
Release the global lock.

The following protected class variables are used:

This is the global lock. It is initialized statically. (This base class uses threading.Lock. Subclasses can set this to something different if appropriate.)
This is the global dictionary of sessions.

Method Summary
  adjustTime(self, deltaSeconds)
Adjust all of the lastModified keys.
Delete all of the expired sessions.
  open(self, sid)
Create or open a session.

Class Variable Summary
int SID_LENGTH = 20                                                                    

Method Details

adjustTime(self, deltaSeconds)

Adjust all of the lastModified keys.

If you have to change the time, do this:


You have to manage the lock yourself, otherwise changing the time might cause some sessions to get deleted before we can update them.


Delete all of the expired sessions.

It's the application's responsibility to occasionally call this.

open(self, sid=None)

Create or open a session.

If this is None, the default, or if no such session exists, a new sid will be generated (even if you provided an sid) and a new session will be created with that sid.

Return the session.

Class Variable Details



Generated by Epydoc 2.1 on Mon Jan 1 16:34:19 2007