Listener interface to implement

I want to be able to notify an object when it is added/removed to/from a Session which
Listener interface do I implement and why?

HttpSessionActivationListener or HttpSessionBindingListener?

Thanks in advance

inzaghiAsked:
Who is Participating?
 
bloodredsunCommented:
>> I want to be able to notify an object when it is added/removed to/from a Session

For bjects being removed from/added to the session use HttpSessionBindingListener

>>I want this object to only be notified when the Session is passivated either by expiring or when the method session.invalidate is called

Then, as Tim mentioned,  you need HttpSessionListener, specifically sessionCreated(HttpSessionEvent e)  and sessionDestroyed(HttpSessionEvent e) which will tell you when a session is about to be created or is about to be destroyed (which includes when you call session.invalidate() ). I assume you meant when the session is destroyed as "passivated " has a different meaning,(see below)

HttpSessionActivationListener is to do with inter-JVM communication, e.g. a large cluster of servlet containers which share sessions as it says in the API "A container that migrates session between VMs or persists sessions is required to notify all attributes bound to sessions implementing HttpSessionActivationListener."
0
 
bloodredsunCommented:
HttpSessionBindingListener: Because it causes an object to be notified when it is bound to or unbound from a session. The object is notified by an HttpSessionBindingEvent object.

with the methods valueBound(HttpSessionBindingEvent event)and  valueUnbound(HttpSessionBindingEvent event)

0
 
bloodredsunCommented:
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
inzaghiAuthor Commented:
Why is the HttpSessionActivationListener different, what is the difference?
0
 
inzaghiAuthor Commented:
I want this object to only be notified when the Session is passivated either by expiring or when the method session.invalidate is called

sorry 4 the confusion
0
 
TimYatesCommented:
From the API docs:

----------
Objects that are bound to a session may listen to container events notifying them that sessions will be passivated and that session will be activated. A container that migrates session between VMs or persists sessions is required to notify all attributes bound to sessions implementing HttpSessionActivationListener.
----------

So basically, it's when the session gets serialized the methods:

---------
sessionWillPassivate
    public void sessionWillPassivate(HttpSessionEvent se)
        Notification that the session is about to be passivated.

sessionDidActivate
    public void sessionDidActivate(HttpSessionEvent se)
        Notification that the session has just been activated.

--------
will be called
0
 
TimYatesCommented:
>> I want this object to only be notified when the Session is passivated either by expiring or when the method session.invalidate is called

In that case, you want HttpSessionListener
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.