This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

A question about HttpSessionActivation Listener

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I studied about HttpSessionActivation Listener and in order understand it fully I created a simple program . I studied that the listener will be invoked whenever session attribute is migrated from one JVM to another .


The following was what I did to understand HttpSessionActivationListener

Created two instances of Tomcat in a single box.(Actually two services)

Configured Apache Http Server to point the two instances (Load balancing and fail over)

Created a small web application and deployed in two servers


Whenever I stop once instance I'm getting a message "Session Will Passivated "(which is what I have in overridden sessionWillPassivate method)

but I'm not getting "Session Did Activated" message (overridden in sessionDidActivated method) .

Please clarify me why I'm not getting Activated method message .

Thanks in advance

 
Parthiban Malayandi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I did


Servlet
=====




JSP File
======



My Web.xml File
===========




http://thought-bytes.blogspot.com/2007/03/how-to-load-balance-tomcat-55-with.html

That is URL I used to configure Apache with Tomcat for Load balancing .

Please clarify me.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you try this ?
mark web apps as distributable.
 
Parthiban Malayandi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi AJ,

Thanks for your reply.First of all sorry for the delayed response from my side. I tried as you said(Implementing Serializable interface in HttpSessionActivationListener class) and I'm getting "SessionDidActivated" message but not when I expected.

Here's the Scenario when I'm getting SessionDidActivated
=====================================

When I stop Tomcat instance (say for example currently "Tomcat Instance 1" is serving the request) after hitting "SessionExample" Servlet (mapped as "/sessiontest.do") as I said I'm getting "SessionWillPassivate " message . When I start the same Tomcat instance again I'm getting "SessionDidActivated" message.

What I Thought
==========

After stopped the Tomcat instance I reloaded the same page expecting this time it will served by another Tomcat instance(say "Tomcat Instance 2" and I will get "SessionDidActivated" message since the session will be migrated.

As I expected the page is served by another Tomcat instance but the session is not migrated and I'm not getting "SessionDidActivated" in the new Tomcat instance.

I also created a new Servlet named as (Servlet3) and modified SessionExample.java so that It contains button and when it clicked it will hit a new Servlet(Servlet 3) to test this instead of reloading the same page but it also doesn't help.


Modified Source codes
===============

Modified Listener class
-------------------------



Added in web.xml
---------------------


Modified SessionExample.java
-----------------------------------



Servlet3.java
---------------



I'm trying this in a single physical machine with two tomcat instance configured with Apache Http Server .

Is anything I'm missing ? Will it work ?

Thanks for your patience for reading lengthy post .



 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that when you shutdown your first Tomcat instance you are killing your session. When you refresh it is like you are re-sending it.

I think so because I used to work with a software that we got a user inside our session. And, when testing, if we shutdown the Tomcat we lost the insides of our session.
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!