This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question about notifying servlets of outages" Watch "Question about notifying servlets of outages" New topic
Author

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
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
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


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ 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: http://aspose.com/file-tools
 
subject: Question about notifying servlets of outages
 
Similar Threads
"porting" a PHP application to Java...
Session Replication
Handling Uploaded Files
help converting asp appliction to servlets
Application Server Toolkit(6.1.1) - Unable to create more than one servers..