[Seaside] seaside et WASession

Bany, Michel mbany at cincom.com
Fri Jan 19 16:38:50 UTC 2007

> I have developped a Seaside application and I just want to 
> know how can I get the session which are currently active.

Hi Sylvain,

Not sure if I understand what you want exactly. You may want to try

	WASession allInstances select: [ :each | each isActive ].

If you have subclassed WASession, you may want this.

	WASession allGeneralInstances select: [ :each | each isActive ]

or maybe this

	MySessionClass allInstances select: [ :each | each isActive ]

The above will answer with a collection of session objects that are
active (=usable), i.e. sessions that can still be used from a browser.

> In fact when I opened my browser I see a new instance in ( 
> MyWAComponent allInstances ).
> But when I close my browser, this instance is not remove from 
> ( MyWAComponent allInstances ).

When you close your browser, there is no impact at all on what objects
you have in your server image. As a matter of fact the browser does not
send anything to any server when it is closed. The same applies if you
navigate away to a new url in your browser.

> I see the WASession object but I don't find how to know if 
> the session has expired because when I get all the instances 
> of WASession which linked to my MyWAComponent, none of them 
> are expired even if my browser is closed.

When you close your browser (or more generally when you stop using a
session, going for a cup of coffee or navigating away to another web
the session is still around in the image and is still usable. For
if you re-open the browser, it is possible to return to your most recent
sessions using the browser history. However if you wait too long before
returning to your session, it may have become unusable. This is the
time out, it defaults to 10 minutes but can be set to any value.

A Seaside session can be forced-expired by sending #expire to the
session object.
This happens for instance when you select "New Session" in the toolbar.

You may see situations where

	WASession allGeneralInstances select: [ :each | each isActive ]

is empty, and

	WASession allGeneralInstances reject: [ :each | each isActive ]

is not empty. This means that all sessions have become unusable.  
However they are still around in the image and this is designed that

When Seaside sessions are created they are kept in a registry
to ensure they are not garbage collected while being used.

>From time to time(*), Seaside cleans up the contents of the registry and
unregisters those sessions that are found unusable.
See method WARegistry>unregisterExpiredHandlers. The actual garbage
collection of a Seaside session occurs some time (not immediately) after
has been unregistered, that is some more time after it has become
An unusable session may sit for some time in the registry before it is

(*) The clean-up of the session registry occurs every 10th (on average)
new session creation. See method WARegistry>shouldCollectHandlers

See also


More information about the Seaside mailing list