Posted by srikanth
on May 13, 2004 at 7:18 PM PDT
Imagine you entered a retail outlet to shop that just says OPEN. Now what will happen to you if something suddenly throws you out of the shop No reasons given. And then you find the retail outlet with a sign CLOSED. You will be frustrated wont you? Guess what - a lot of J2EE systems in production might be doing just that...
Imagine you entered a retail outlet to shop that just says OPEN. Now what is your reaction if something suddenly throws you out of the shop No reasons given. And then you find the retail outlet with a sign CLOSED. You will be frustrated wont you? You'd expect that the outlet lets you shop now that you have entered it before the "CLOSED" sign is put up. right?
Guess what - a lot of J2EE systems in production might not be doing that at all.
When new deployments go out, active users on the system are unceremoniously ousted.
What we want is:
- Some minutes before the site is brought down, stop new users from entering the sytem.
- However, let the existing users continue to use the syetm with a message that system will go down in 15 minutes.
- When 15 minutes pass, bring down the system.
As any other problem there are many solutions to this problem at different levels.
At the hardware level, you can configure your router to not accept new requests for the application. You can also configure this at the web server level. In this blog, I am glossiing over a J2EE based solution to this problem.
I'd like to call this "Retail Outlet" Pattern, since it mimics the real world shopping experience. When the OPEN becomes CLOSED it lets existing shoppers to continue their unfinished work for another 15 minutes without letting any new shoppers in.
To implement, it requires a JMX MBean that holds info if the shop should be closed or not. Why JMX? well, a lot of people who start and stop the production application servers are administrators, not developers. MBean properties can be edited from any SNMP console, which all of them are familiar with. Some application servers allow editing of MBeans from their own console. Most of all, changes in JMX attributes are reflected immediately. (Another area where I like to use JMX is to control Log4J log level. More on that later.)
Another component is a Servlet Filter that interacts with another object (Session Lifecycle Listener) that counts the number of active users and keeps track of it. When the Mbeans switch is flipped to indicate the CLOSE status, the Filter blocks all new requests (those without a session), but let those with an active session to continue for another (say) 15 minutes.
A word of caution though. I have never used this approach before. However I would like to try this out. Any thoughts on your experiences?