Re: Options to prevent web app from being available if DB not available?

2005-09-26 Thread Steve Dodge

Mike,

Doing this with pure J2EE Servlet  code, I would use three components.  
First, use the Context Listener to check the Database on start up, if no 
DB connectivity set a ApplicationContext attribute to that effect.  The 
second part would be a javax.servlet.Filter which checks the status of 
the ApplicationContext attribute forwarding to an error page if the 
attribute indicates database connectivity issues.  Third, instead of 
just a String, I'd use a self-updating object as the attribute in the 
ApplicationContext.  This self updating object runs an internal timer 
thread which tests connectivity at a fixed interval setting the DB 
status to up or down.  This third component is optional.


Regarding your issue not wanting to start certain servlets if the 
Database is down, you could carry out a DB connectivity test in the base 
class to all your servlets, skipping initialization if no connectivity.


Steve

Mike Miller wrote:

Hi, 


I am looking for options to prevent my web application from being
available if our database is not available. I've used context listeners
in the past, but since you can return a bad return code they don't like
the cleanest approach.  




I have tried registering a context listener and then throwing a
RuntimeException if the database is not available but that seems like a
kludge.

Any other options?



Thanks in advance,

Mike


 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Options to prevent web app from being available if DB not available?

2005-09-26 Thread Mike Miller
Thanks for the replies - several suggested filters.  I guess I have two
concerns with that approach:

1) Since this doesn't happen very often, I'm not sure I want to add
additional processing to EVERY request processed by the system.  I may
be wrong and it may not be much extra?

2) we have several servlets that are init'd in a specific order.  If the
database is not available, I don't even want them to be called.  If I
used a filter, I guess I could just configure the same filter to each
servlet...


-Original Message-
From: Tim Funk [mailto:[EMAIL PROTECTED] 
Sent: Monday, September 26, 2005 1:22 PM
To: Tomcat Users List
Subject: Re: Options to prevent web app from being available if DB not
available?

Servlet filter.

The filter can check the database status on init. Then the filter could
be 
made smart enough to let all traffic through if the database comes back
to 
life. (or conversely also goes away)

-Tim

Mike Miller wrote:

> Hi, 
> 
> I am looking for options to prevent my web application from being
> available if our database is not available. I've used context
listeners
> in the past, but since you can return a bad return code they don't
like
> the cleanest approach.  
> 
>  
> 
> I have tried registering a context listener and then throwing a
> RuntimeException if the database is not available but that seems like
a
> kludge.
> 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Options to prevent web app from being available if DB not available?

2005-09-26 Thread Arup Vidyerthy
Haven't really thought it through as I just woke up :-) 

However, I don't see why couldn't write a filter that filters all request.
It checks the DB connection and if it isn't there it just simply forwards
the user to an appropriate page.

As to making the whole web app unavailable - I am not sure dude.

Arup 

-Original Message-
From: Mike Miller [mailto:[EMAIL PROTECTED] 
Sent: 26 September 2005 19:18
To: tomcat-user@jakarta.apache.org
Subject: Options to prevent web app from being available if DB not
available?

Hi, 

I am looking for options to prevent my web application from being available
if our database is not available. I've used context listeners in the past,
but since you can return a bad return code they don't like the cleanest
approach.  

 

I have tried registering a context listener and then throwing a
RuntimeException if the database is not available but that seems like a
kludge.

Any other options?

 

Thanks in advance,

Mike




___ 
To help you stay safe and secure online, we've developed the all new Yahoo! 
Security Centre. http://uk.security.yahoo.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Options to prevent web app from being available if DB not available?

2005-09-26 Thread Tim Funk

Servlet filter.

The filter can check the database status on init. Then the filter could be 
made smart enough to let all traffic through if the database comes back to 
life. (or conversely also goes away)


-Tim

Mike Miller wrote:

Hi, 


I am looking for options to prevent my web application from being
available if our database is not available. I've used context listeners
in the past, but since you can return a bad return code they don't like
the cleanest approach.  

 


I have tried registering a context listener and then throwing a
RuntimeException if the database is not available but that seems like a
kludge.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]