And bind them to the
servlet context:
Next, the sessions themselves. In its simplest form, a session is nothing but a mapping from Strings to Objects. In addition to that, in order to eventually expire sessions you need to track when they were last accessed.
To retrieve a session, you would get the manager out of the servlet context:
The final ingredient is a daemon
thread that every now and then goes through the sessions object in the WapSessionManager and cleans out all expired sessions. A quick and dirty way would be to add a WapSessionManager constructor spawning this thread:
Note that the above was written on the fly, it probably doesn't even compile. There may be a few details that aren't quite right (watch out thread safety).
More importantly, I glossed over a few details, such as the fact that it isn't possible to retrieve a session from the WapSessionManager while the expiry thread is iterating through its collection (solution: let it make a
copy of the values Collection and do the iteration
outside the synchronized block. When you think you have a session that's expired, synchronize again, check again, and remove. Also, you may want a way to clean the WapSessionManager including interrupting the expiry thread.
HTH
- Peter
[This message has been edited by Peter den Haan (edited February 08, 2001).]