File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JBoss/WildFly and the fly likes Help Needed: Stopping JBoss when the databse server is down Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Help Needed: Stopping JBoss when the databse server is down" Watch "Help Needed: Stopping JBoss when the databse server is down" New topic
Author

Help Needed: Stopping JBoss when the databse server is down

Anand Natraj
Ranch Hand

Joined: May 17, 2004
Posts: 53
Hi All,

I am a newbie to JBoss.

I want to configure my JBoss server in such a way that when my Database server is down my JBoss server should not start. How do i do this.

Please help me out.

Thanks in advance.

Regards,
Anand
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

I dont see a way of doing that. JBoss might have multiple applications deployed on it, if you would prevent JBoss from starting just because the database for one application is down, the other applications will also be affected. Why would you want this behaviour? Any specific requirement?


[My Blog] [JavaRanch Journal]
Anand Natraj
Ranch Hand

Joined: May 17, 2004
Posts: 53
Hi Jaikiran,

Thanks a lot for replying. Yes i have a specifc requirement for stopping the JBoss server if the databse server is down.

Thanks and Regards,
Anand
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

Here's a not so elegant method of doing what you want:
(Note that, in this approach, the shutdown of the server will happen only after your application is deployed)
- I guess you are using datasource for connecting to database.
- Once your application is deployed, do a lookup of the datasource and invoke the getConnection method on the datasource. Now since your database is down, you will be getting an exception. Catch the exception.
- Once you have caught the exception, programatically get access to the "jboss.system:type=Server" MBean(for doing this, you will have to get access to MBeanServer first as mentioned here.)
- Now once you have got access to the "jboss.system:type=Server" MBean, you can invoke the shutdown() method which is available on that MBean.

P.S.: I have never tried this before, but this is the only thing that came to my mind looking at your requirement.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

But how would you do that if the JBoss Server is already running and the database is already running and something bad happens that the database goes down. JBoss won't be able to know that unless it is constantly requesting information from the database to see if it is still there.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

You are right, that case cannot be handled by the approach mentioned in my post.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Now, how about this concept. JBoss allows for validation queries to run when you create a Connection and when you get one out of the Pool. I think you can create your own validation object, that if the connection is bad, it double checks that the database is still up, and then if not, it shutsdown the App Server. That would be scary.

Mark
Johny Kk
Greenhorn

Joined: Oct 23, 2006
Posts: 8
HI Mark,

i think it can be done in the code level rte? caz i got the same kind of issue. During the start up process if the DB server is not available then i need to stop the application server b4 its getting started? is that possible

Thanks
Karthik
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Originally posted by Karthik Arumugam:
HI Mark,

i think it can be done in the code level rte? caz i got the same kind of issue. During the start up process if the DB server is not available then i need to stop the application server b4 its getting started? is that possible

Thanks
Karthik


Just scroll up and see Jaikiran Pai suggestion in this thread.

Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

Now, how about this concept. JBoss allows for validation queries to run when you create a Connection and when you get one out of the Pool. I think you can create your own validation object, that if the connection is bad, it double checks that the database is still up, and then if not, it shutsdown the App Server


Are we talking about the <new-connection-sql> or <valid-connection-sql> on the datasource? Yes, this too looks like a option, provided we can create our own validation object(i will have to look at some docs to see if thats possible)
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

Originally posted by Mark Spritzler:
That would be scary.



The whole requirement of shutting down the app server because the database is down, looks scary. Usually if the database is down, the application would show a page which will mention the same, but the application server will still be running.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Originally posted by Jaikiran Pai:


The whole requirement of shutting down the app server because the database is down, looks scary. Usually if the database is down, the application would show a page which will mention the same, but the application server will still be running.


Exactly, it should handle exceptions form the database, and then catch them accordingly.

Also from the stand point of App Server startup, shouldn't you know when you start your App Server if your database is down. I would hope so.

Mark
Johny Kk
Greenhorn

Joined: Oct 23, 2006
Posts: 8
Thanks for your reply sri and Mark. But i got the requirement like this wat 2 do?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Originally posted by Karthik Arumugam:
Thanks for your reply sri and Mark. But i got the requirement like this wat 2 do?


Hit the person that made the requirement with a baseball bat, then throw them down the stairs, and yes that is a joke.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help Needed: Stopping JBoss when the databse server is down