Hello Andrea

The problem you are pointing can be solved in a simplier way...


> A deeper analysis shows an architectural problem with the sql
> based EPSG factories, in particular, they get a hold on a single
> SQL connection and try to perform every operation against it,
> without any possibility to recover from corruptions.

Actually there is already a timeout (30-60 minutes in current default) after 
which the connection is closed and will be reopened later when needed. This 
timeout is probably way too long for server environment and can be reduced. The 
only thing you need to do for solving the first part of the problem is to 
change 
that timeout. The easiest way is to just change the default value:

   * Open ThreadedEpsgFactory class. At line 194, change the timeout for a
     small value (e.g. 30 seconds).

Alternatively a user can set its own timeout at application starting time (I 
admit this is not obvious code):

ThreadedEpsgFactory factory = (ThreadedEpsgFactory) 
ReferencingFactoryFinder.getCRSAuthorityFactory(new 
Hints(Hints.CRS_AUTHORITY_FACTORY, ThreadedAuthorityFactory.class), null);
factory.setTimeout(30 * 1000L); // 30 seconds.

This setTimeout method exists since GeoTools 2.1.

For the second part of the problem (invalid connection), you can process as 
below: In DeferredAuthorityFactory add a new method:

    protected boolean isValid(AbstractAuthorityFactory factory) {
        return true;
    }

In DeferredAuthorityFactory.getBackingStore() method, at line 131 (just after 
the assert statement and before the if statement), add the following lines:

    if (backingStore != null && !isValid(backingStore)) {
        try {
            backingStore.dispose();
        } catch (FactoryException e) {
            // Log the error and forget about this factory.
        }
        backingStore = null;
    }

In ThreadedAuthorityFactory, add

   @Override
   protected isValid(AbstractAuthorityFactory factory) {
       return ((DirectEpsgFactory) factory).checkTheConnectionHere();
   }


> Checking is done as in most connection pools, by running a user
> provided statement , different for every database, that is at the
> same time fast, while forcing a communication with the server.

In Java 6 there is method for that:

http://java.sun.com/javase/6/docs/api/java/sql/Connection.html#isValid(int)

But I realize that you are restricted to Java 5...

     Martin


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to