Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 484
  • Last Modified:

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

0
inzaghi
Asked:
inzaghi
  • 3
  • 2
  • 2
2 Solutions
 
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
 
inzaghiAuthor Commented:
Why is the HttpSessionActivationListener different, what is the difference?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now