2 Replies Latest reply on Sep 10, 2008 12:42 PM by vickyk

    How to mark DataSource as temporarily unavailable

    kenevel

      Hi there,

      I'm working on a project in which one of the requirements is for the JBoss middle tier code to be able to support a cold outage of the database (which it its applications are upgraded). I've been looking through the JCA documentation, but haven't found any particular point in the code where a simple, elegant change could produce the effect we're after - for example throwing a custom RuntimeException along the lines of a DataSourceTemporarilyUnavailableException. This could travel up the stack to the front-end and result in appropriate messages being generated for the system's users.

      I was wondering about the effect of simply invoking the stop() method on the ManagedConnectionPool or TxConnectionManager. I seem to recall that the latter throws an exception if a Connection is requested while it is in the stopped state - but then the question becomes one of the effect of simply invoking the start() method once the DB is available again: will JBoss simply replenish its pool with new DB connections and serve these as if it had not been stopped? Are there any knock-on effects of simply stopping that data-source or its managing components?

      Best wishes,

      Michael

        • 1. Re: How to mark DataSource as temporarily unavailable
          peterj

          I have never tried this so my thoughts here are entirely speculation. Based on discussions I have seen in other posts, I suspect that doing a stop on the connection pool might remove the *-ds.xml file from the deploy directory. (I am not sure about that at all - there are up to a half-dozen MBeans generated for a *-ds.xml file and am am not sure what effect stopping one of them would have.) I suspect that once the datasource is stopped that your apps will get various errors. I do not know what will happen with threads that already have connections - most likely they will continue to use the connections successfully but then might get exceptions when closing the connection. You would probably have to do some recoding to gracefully handle these exceptions.

          Now as I mentioned, this is all speculation. I could try this with one of my apps and report on what happens. But then, you could do that just as easily.

          One other thought I had was to write your own datasource (or perhaps a service) as a layer over the actual datasource, and place into your datasource the ability to "temporarily shut down" the database. Then you could define the exact behavior for what happens during a shutdown and your apps will be depended on behavior that could change (which is a very likely possibility as you move to apps to newer versions of JBossAS.)

          • 2. Re: How to mark DataSource as temporarily unavailable
            vickyk

             

            "kenevel" wrote:
            for example throwing a custom RuntimeException along the lines of a DataSourceTemporarilyUnavailableException. This could travel up the stack to the front-end and result in appropriate messages being generated for the system's users.

            Why can't you guys handle this in through the application without playing with the JCa pool Mbeans?
            You can have a utility class which will get the connection from the underlying datasource and if it fails to get the connection due to unavailability of DB this utility class throws required application exception.
            Looks to me you wanted to take care of this scenario
            http://wiki.jboss.org/wiki/WhatHappensToJBossIfIRestartTheDatabase