Pascuzzi Domenico wrote:
>
> I need to model the following situation:
>
> 1. a client logs into application server (J2EE).
> 2. The servlet creates a session bean to maintain client state
> 3. If a timeout (TIMER1) expires then the session bean's handle is
> serialized and saved in secondary storage.
>
This might possibly be done in the destroy() method, which is called by the
servlet container when the servlet is being removed (due to the timeout). If the
getLastAccessedTime() is checked, the servlet could be able to determine if it
is being destroyed due to timeout or just the end of the session (should not be
hardcoded though - maybe the timeout value could be retrieved from the
ServletContext).
If it's a timeout, serialize the handle and put a timestamp on it (add it to the
name of the file for example). Also, link it to the client given some
information about the client. A cookie with a session id might do the trick
(have to keep the cookie in the servlet however, since it is part of the request
data).
> 4. If the client relogs, the system is able to recover the handle
> and restore session
>
The servlet could look for the handle. If it exists, deserialize it and get the
session bean.
> 5. If the client doesn't relog and a second timeout (TIMER2 not
> equal to TIMER1) expires then the handle is removed!
>
This is probably best done using a separate process that does cleanup sweeps of
the handle database. Handles older than TIMER2 are removed (and consecutive
relogs would make the servlet unable to find it and thus create a new session
bean).
> WHAT is the right approach according EJB framework?
>
Well, it's AN approach. Don't know if it's the right one though :)
> How can I define entities that monitor state of session communication
> with client?
>
The only entity you need to put outside the servlet I think is the handle
cleanup process (since it happens rarely you don't want the servlet to do it).
Anyway, that would be my initial plan, FWF.
/Kalle
--
In a Bangkok temple: "It is forbidden to enter a woman even a foreigner if
dressed as a man."
Karl-Fredrik Blixt
Computer Science student at LiTH, Sweden
Homepage: http://travel.to/kp
Telephone: +46-(0)13-17 99 29
Cellular: +46-(0)739-87 11 03
ICQ: 4744258
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".