This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

2 Listeners - No need to configure in DD

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have to register HttpSessionBindingListener & HttpSessionActivationListener in DD.

Is this statement correct ?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/view?DeclaringListeners
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sandeep,

We never configure the HttpSessionBindingListener & HttpSessionActivationListener in the deployment descriptor.

HttpSessionBindingListener:

The servlet container calls methods on an object implementing this interface only if that object is added to or removed from a session.

HttpSessionActivationListener:

It is possible to monitor the activation and passivation of session via the HttpSessionActivationListener. We always implement this interface in a listener class to track session migration events i.e. activation or passivation.


Thanks,
Mahesh

--------

SCJP 1.4 | SCWCD 1.4 | SCBCD 1.3 | SCEA Part I - Preparing..
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the FAQ:

Classes implementing interfaces other than HttpSessionBindingListener and HttpSessionActivationListener need to be declared in DD.

OK, I understand. But I have one question: if the HttpSessionActivationListener is implemented by some *other* class than an attribute class of which objects are bound to a session (as in HFSJ p.262)... then shouldn't the HttpSessionActivationListener be registered in the DD? In other words, never for attribute classes but still for other classes since the container would not "detect" objects of these classes.

Greeting,
Yves
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not the purpose of HttpSessionActivationListener. This interface is used for session objects which need to be notified when a session if migrated.
Objects not in session do not need to be notified, because they don't care about the session being migrated.

I think that what the container does is :
1. Get the session which is about to be migrated (HttpSession)
2. Get all attributes in that session (getAttributeNames)
3. Loop through each attribute and check if it is an instance of HttpSessionActivationListener
4. If it is, cast the object to HttpSessionActivationListener and call sessionWillPassivate/sessionDidActivate

(I can't tell about p262 because I don't own the book)

From the API:

Containers must notify any session attributes implementing the
HttpSessionActivationListener during migration of a session. They must notify
listeners of passivation prior to serialization of a session, and of activation after
deserialization of a session.


When container migrates a session between VMs in a distributed container setting,
all session attributes implementing the HttpSessionActivationListener
interface are notified.


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.
 
Yeah, but is it art? What do you think tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic