diff geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java @ 265:e5379e129799

Fixed issue 34 geo-backend/trunk@215 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 13 Oct 2009 13:20:26 +0000
parents e4eacd613356
children ff1b7967e6b9
line wrap: on
line diff
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java	Tue Oct 13 09:00:30 2009 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java	Tue Oct 13 13:20:26 2009 +0000
@@ -12,70 +12,115 @@
 
 /**
  *This is the ArcSDE specific implementation of the Interface ConnectionPool
+ * 
  * @author Tim Englich <tim.englich@intevation.de>
  */
 public class ArcSDEConnectionPool implements ConnectionPool {
 
-	/**
+    /**
      * the logger, used to log exceptions and additonaly information
      */
-    private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class);
-    
-	/**
-	 * The Pool which stores the Connections to the ArcSDE Backend
-	 */
-	private GenericObjectPool pool = null;
-	
-	/**
-	 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#closeConnection(java.lang.Object)
-	 */
-	public void closeConnection(Connection connection) throws ConnectionException {
-		
-		try {
-			//TODO: Muss Connection geschlossen werden?
-			this.pool.returnObject(connection);
-		} catch (Exception e) {
-			log.error(e,e);
-			throw new ConnectionException(e);
-		}
-
-	}
+    private static Logger log = Logger
+            .getLogger(ArcSDEPoolableObjectFactory.class);
 
-	/**
-	 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#getConnection(java.lang.String)
-	 */
-	public synchronized Connection getConnection(String connectionID) throws ConnectionException{
-		try {
-			Object object = this.pool.borrowObject();
-			
-			if (object instanceof Connection){
-				return (Connection)object;
-			}else{
-				throw new ConnectionException("Created Object is not an java.sql.Connection");
-			}
-			
-		} catch (Exception e) {
-			log.error(e,e);
-			throw new ConnectionException(e);
-		}
+    /**
+     * The Pool which stores the Connections to the ArcSDE Backend
+     */
+    private GenericObjectPool pool = null;
+
+    /**
+     * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#closeConnection(java.lang.Object)
+     */
+    public void closeConnection(Connection connection)
+                                                      throws ConnectionException {
+
+        try {
+            // TODO: Muss Connection geschlossen werden?
+            this.pool.returnObject(connection);
+        } catch (Exception e) {
+            log.error(e, e);
+            throw new ConnectionException(e);
+        }
+
+    }
+
+    /**
+     * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#getConnection(java.lang.String)
+     */
+    public synchronized Connection getConnection(String connectionID)
+                                                                     throws ConnectionException {
+        try {
+            Object object = this.pool.borrowObject();
+
+            if (object instanceof Connection) {
+                return (Connection) object;
+            } else {
+                throw new ConnectionException(
+                        "Created Object is not an java.sql.Connection");
+            }
+
+        } catch (Exception e) {
+            log.error(e, e);
+            throw new ConnectionException(e);
+        }
+    }
+
+    /**
+     * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#initialize(java.util.Properties)
+     */
+    public void initialize(Properties properties) {
+        log.info("ArcSDEConnectionPool.initialize has been called");
+        log.info("ConnectionPool will be initialized");
+
+        PoolableObjectFactory poolableObjectFactory = new ArcSDEPoolableObjectFactory(
+                properties);
+
+        int maxActive = Integer.parseInt(properties.getProperty("maxActive",
+                "10"));
+        long maxWait = Long.parseLong(properties.getProperty("maxWait",
+                "" + GenericObjectPool.DEFAULT_MAX_WAIT));
+        int maxIdle = Integer.parseInt(properties.getProperty("maxIdle",
+                "" + GenericObjectPool.DEFAULT_MAX_IDLE));
+        int minIdle = Integer.parseInt(properties.getProperty("minIdle",
+                "" + GenericObjectPool.DEFAULT_MIN_IDLE));
+        boolean testOnBorrow = Boolean.parseBoolean(properties.getProperty(
+                "testOnBorrow", "" + GenericObjectPool.DEFAULT_TEST_ON_BORROW));
+        boolean testOnReturn = Boolean.parseBoolean(properties.getProperty(
+                "testOnReturn", "" + GenericObjectPool.DEFAULT_TEST_ON_RETURN));
+        long timeBetweenEvictionRunsMillis = Long
+                .parseLong(properties
+                        .getProperty(
+                                "timeBetweenEvictionRunsMillis",
+                                ""
+                                        + GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS));
+        int numTestsPerEvictionRun = Integer.parseInt(properties.getProperty(
+                "numTestsPerEvictionRun",
+                "" + GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN));
+        long minEvictableIdleTimeMillis = Long
+                .parseLong(properties
+                        .getProperty(
+                                "minEvictableIdleTimeMillis",
+                                ""
+                                        + GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
+        boolean testWhileIdle = Boolean.parseBoolean(properties
+                .getProperty("testWhileIdle",
+                        "" + GenericObjectPool.DEFAULT_TEST_WHILE_IDLE));
+        
+        log.info("Maximum Number of active Connections: " + maxActive);
+        log.info("Maximum Number of waiting: " + maxWait);
+        log.info("Maximum Number of idle: " + maxIdle);
+        log.info("Minimum Number of idle: " + minIdle);
+        log.info("TestOnBorrow: " + testOnBorrow);
+        log.info("TestOnReturn: " + testOnReturn);
+        log.info("TimeBetweenEvictionRunsMillis: " + timeBetweenEvictionRunsMillis);
+        log.info("NumTestsPerEvictionRun: " + numTestsPerEvictionRun);
+        log.info("MinEvictableIdleTimeMillis: " + minEvictableIdleTimeMillis);
+        log.info("TestWhileIdle: " + testWhileIdle);
+        
+        this.pool = new GenericObjectPool(poolableObjectFactory, maxActive,
+                                            GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, maxWait,
+                                            maxIdle, minIdle, testOnBorrow, testOnReturn,
+                                            timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
+                                            minEvictableIdleTimeMillis, testWhileIdle);
 	}
-	
-	/**
-	 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#initialize(java.util.Properties)
-	 */
-	public void initialize(Properties properties) {
-		log.info("ArcSDEConnectionPool.initialize has been called");
-		log.info("ConnectionPool will be initialized");
-		
-		PoolableObjectFactory poolableObjectFactory = new ArcSDEPoolableObjectFactory(properties);
-		
-		int maxActive = Integer.parseInt(properties.getProperty("maxActive", "10"));
-		
-	    log.info("Maximum Number of active Connections: "+maxActive);
-		// TODO weitere Werte einparsen und setzen.
-		
-		this.pool = new GenericObjectPool(poolableObjectFactory,maxActive);
-		
-	}
-
 }

http://dive4elements.wald.intevation.org