• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Question about notifying servlets of outages

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 <><
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rick Crawford
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 <><
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic