views:

73

answers:

2

I am interested in doing a stackoverflow type notification on my website. I know there are a few questions on this topic, but all of them are concerned with the client side css and ajax.

I would like to know the best way to handle things on the server side (jsp). I want to notify all users currently using the system that the server will be going down. So I can make a db with all the necessary information, and when the record is set to active, out comes the notification div. First question, is this the best way to handle this portion?

The next part is, how do I actually get the notification out. The only solutions I have thought of are to be polling from the web site with jQuery or to only check when pages are loaded. I know there are some push like things (comet, reverse ajax) but have no experience with these. Would these be useful in this situation, or would they be overkill? Is polling (pretty simple) the best way to go?

+1  A: 

I would approach this from a separate angle. If you were to give more notice, say 30 minutes, then just worry about displaying the message on page load. If someone's loading a page so infrequently that they don't see this message, chances are polling isn't going to help most of that audience either. I'd say that the polling approach will just result in a lot of wasteful hits on your website 99% of the time it seems.

Nick Craver
For most applications this is the clear way to go. But my application has some cases where a user might be sitting on the same page for 25+ minutes. And these restarts are often announced 30 minutes before. So in most cases the notification will work as intended, but there may be a few users that wont be notified.
UmYeah
A: 

I would say that one possible middle ground for you would be to piggyback off of other ajax requests. So instead of polling, take the opportunity to intercept a request that the user was doing for some other reason, and include some piece of information about the db going down. You could put this in the response body, or even a cookie or http header.

Russell Leggett