File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Question about notifying servlets of outages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question about notifying servlets of outages" Watch "Question about notifying servlets of outages" New topic

Question about notifying servlets of outages

Rick Crawford
Ranch Hand

Joined: Aug 17, 2001
Posts: 34
Hello all. I've got a question that I hope there's a ready answer for. I wasn't sure if this is the right forum for this, but I thought I'd start here.
I am working on a website that will experience scheduled outages for back-end database administration. I'm trying to figure out an elegant way to detect when an outage is in effect so my application won't attempt to connect to the database, and display some sort of a 'we're sorry
but the web is unavailable until ??? time' message. I thought about having an 'outage-config.xml' file where the scheduled outages are
listed, but I hate to have to read this file everytime one of my application pages are hit. I am concerned about the file io overhead, as well as the XML parsing that'd have to be done. Is there some slick way to do this that someone could share? Is there a way to have a separate process, an outage poller maybe, that wakes up every so often and reads this file, then sets a system property that my servlets and .jsp's could check to see if an outage is in effect? By the way, I'm using Tomcat 3.2.3 on a Linux box.
Thanks in advance for any assistance,
Rick <><
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
Put a global switch in the ServletContext that all pages check for. Turn the switch on or off with a hidden (and protected!) URL.

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
Rick Crawford
Ranch Hand

Joined: Aug 17, 2001
Posts: 34
Thanks so much for your response. I'd like to ask a few more questions if I may. I'm trying to understand what you can and can't do with ServletContext.
I ended up creating a couple of classes for outage management. My Outage class contains the start and end times for a specific outage. It features an isOutageInEffect() method that returns boolean by comparing the current date and time to the start and end times of an Outage instance. I then created an OutageCalendar class for maintaining a collection of Outages (in case we ever have to have more than one outage / week.) This class also has an isOutageInEffect()
method to test each Outage in the collection. I created an xml file with my outage information, and use it to build the OutageCalendar.
I'm kind of a servlet novice, but I've been studying Servlet contexts and see references to getInitParameter, which I'm thinking is the way to get a handle on the context. But is there a way to utilize this functionality I've mentioned above within ServletContext?
Another idea I was considering: what if I made my OutageCalendar class a singleton class? In it's constructor, it could load up all the outages in the config file. Then each servlet could just ask the same copy of the OutageCalendar if an outage is in effect.
Thanks again for the response.
Rick <><
I agree. Here's the link:
subject: Question about notifying servlets of outages
It's not a secret anymore!