db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r450012 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker: accesslayer/ConnectionFactoryDBCPImpl.java accesslayer/ConnectionFactoryPooledImpl.java util/pooling/PoolConfiguration.java
Date Tue, 26 Sep 2006 12:09:05 GMT
Author: arminw
Date: Tue Sep 26 05:09:05 2006
New Revision: 450012

URL: http://svn.apache.org/viewvc?view=rev&rev=450012
Log:
add support for property 'initialSize' (connection-pool size at startup)

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/pooling/PoolConfiguration.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java?view=diff&rev=450012&r1=450011&r2=450012
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java
Tue Sep 26 05:09:05 2006
@@ -61,6 +61,7 @@
     public static final String PARAM_NAME_UNWRAP_ALLOWED = "accessToUnderlyingConnectionAllowed";
     public static final String PARAM_NAME_POOL_STATEMENTS = "poolPreparedStatements";
     public static final String PARAM_NAME_STATEMENT_POOL_MAX_TOTAL = "maxOpenPreparedStatements";
+    public static final String PARAM_INITIAL_SIZE = "initialSize";
 
     private Logger log = LoggerFactory.getLogger(ConnectionFactoryDBCPImpl.class);
 
@@ -246,6 +247,25 @@
                 defaultReadOnly,
                 defaultAutoCommit,
                 ac);
+
+        // perform initial connection size
+        int initialSize = jcd.getConnectionPoolDescriptor().getInitialSize();
+        if(initialSize > 0)
+        {
+            try
+            {
+                for (int i = 0 ; i < initialSize ; i++)
+                {
+                    connectionPool.addObject();
+                }
+            }
+            catch (Exception e)
+            {
+                log.error("Error preloading the connection pool (initialSize=" + initialSize
+ ")", e);
+            }
+            log.info("Setup connection-pool initial size to " + initialSize);
+        }
+
         return poolableConnectionFactory.getPool();
     }
 
@@ -273,6 +293,7 @@
         connectionPool.setNumTestsPerEvictionRun(config.numTestsPerEvictionRun);
         connectionPool.setMinEvictableIdleTimeMillis(config.minEvictableIdleTimeMillis);
         connectionPool.setTestWhileIdle(config.testWhileIdle);
+        //connectionPool.setSoftMinEvictableIdleTimeMillis(config.softMinEvictableIdleTimeMillis);
         return connectionPool;
     }
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java?view=diff&rev=450012&r1=450011&r2=450012
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java
Tue Sep 26 05:09:05 2006
@@ -132,7 +132,27 @@
         if (log.isDebugEnabled()) log.debug("createPool was called");
         PoolableObjectFactory pof = new ConPoolFactory(this, jcd);
         GenericObjectPool.Config conf = jcd.getConnectionPoolDescriptor().getObjectPoolConfig();
-        return new GenericObjectPool(pof, conf);
+        ObjectPool pool = new GenericObjectPool(pof, conf);
+
+        // perform initial connection size
+        int initialSize = jcd.getConnectionPoolDescriptor().getInitialSize();
+        if(initialSize > 0)
+        {
+            try
+            {
+                for (int i = 0 ; i < initialSize ; i++)
+                {
+                    pool.addObject();
+                }
+            }
+            catch (Exception e)
+            {
+                log.error("Error preloading the connection pool (initialSize=" + initialSize
+ ")", e);
+            }
+            log.info("Setup connection-pool initial size to " + initialSize);
+        }
+        
+        return pool;
     }
 
     /**
@@ -199,8 +219,7 @@
                 }
                 if (isValid)
                 {
-                    final String validationQuery;
-                    validationQuery = jcd.getConnectionPoolDescriptor().getValidationQuery();
+                    final String validationQuery = jcd.getConnectionPoolDescriptor().getValidationQuery();
                     if (validationQuery != null)
                     {
                         isValid = validateConnection(con, validationQuery);

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/pooling/PoolConfiguration.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/pooling/PoolConfiguration.java?view=diff&rev=450012&r1=450011&r2=450012
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/pooling/PoolConfiguration.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/pooling/PoolConfiguration.java
Tue Sep 26 05:09:05 2006
@@ -28,14 +28,14 @@
  * Encapsulates configuration properties for
  * implementations using {@link org.apache.commons.pool.ObjectPool}.
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 public class PoolConfiguration extends Properties implements Serializable, AttributeContainer
 {
-
 	private static final long serialVersionUID = -3850488378321541047L;
 
+    private int initialSize = 0;
+
     //*****************************************************
     // constants
     //*****************************************************
@@ -50,15 +50,17 @@
     public static final String TIME_BETWEEN_EVICTION_RUNS_MILLIS = "timeBetweenEvictionRunsMillis";
     public static final String NUM_TESTS_PER_EVICTION_RUN = "numTestsPerEvictionRun";
     public static final String MIN_EVICTABLE_IDLE_TIME_MILLIS = "minEvictableIdleTimeMillis";
+    //public static final String SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = "softMinEvictableIdleTimeMillis";
     public static final String LOG_ABANDONED = "logAbandoned";
     public static final String REMOVE_ABANDONED = "removeAbandoned";
     public static final String REMOVE_ABANDONED_TIMEOUT = "removeAbandonedTimeout";
     public static final String VALIDATION_QUERY = "validationQuery";
+    public static final String INITIAL_SIZE = "initialSize";
 
     //*****************************************************
     // used default values
     //*****************************************************
-    public static final int DEFAULT_MAX_ACTIVE = 21;
+    public static final int DEFAULT_MAX_ACTIVE = 30;
     public static final int DEFAULT_MAX_IDLE = -1;
     public static final int DEFAULT_MIN_IDLE = 0;
     public static final long DEFAULT_MAX_WAIT = 5000;
@@ -84,6 +86,7 @@
         this.setTestOnReturn(DEFAULT_TEST_ON_RETURN);
         this.setTestWhileIdle(DEFAULT_TEST_WHILE_IDLE);
         this.setMinEvictableIdleTimeMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
+        //this.setSoftMinEvictableIdleTimeMillis(GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
         this.setTimeBetweenEvictionRunsMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
         this.setNumTestsPerEvictionRun(DEFAULT_NUM_TESTS_PER_EVICTION_RUN);
         this.setLogAbandoned(DEFAULT_LOG_ABANDONED);
@@ -111,6 +114,7 @@
         conf.minIdle = getMinIdle();
         conf.maxWait = getMaxWait();
         conf.minEvictableIdleTimeMillis = getMinEvictableIdleTimeMillis();
+        //conf.softMinEvictableIdleTimeMillis = getSoftMinEvictableIdleTimeMillis();
         conf.numTestsPerEvictionRun = getNumTestsPerEvictionRun();
         conf.testOnBorrow = isTestOnBorrow();
         conf.testOnReturn = isTestOnReturn();
@@ -251,7 +255,7 @@
 
     public byte getWhenExhaustedAction()
     {
-        return new Byte(getProperty(WHEN_EXHAUSTED_ACTION)).byteValue();
+        return Byte.parseByte(getProperty(WHEN_EXHAUSTED_ACTION));
     }
 
     public void setWhenExhaustedAction(byte whenExhaustedAction)
@@ -315,6 +319,17 @@
     }
 
 
+//    public long getSoftMinEvictableIdleTimeMillis()
+//    {
+//        return Integer.parseInt(getProperty(SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
+//    }
+//
+//    public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis)
+//    {
+//        this.setProperty(SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS, Long.toString(softMinEvictableIdleTimeMillis));
+//    }
+
+
     public int getNumTestsPerEvictionRun()
     {
         return Integer.parseInt(getProperty(NUM_TESTS_PER_EVICTION_RUN));
@@ -325,5 +340,14 @@
         this.setProperty(NUM_TESTS_PER_EVICTION_RUN, Integer.toString(numTestsPerEvictionRun));
     }
 
+    public int getInitialSize()
+    {
+        return initialSize;
+    }
+
+    public void setInitialSize(int initialSize)
+    {
+        this.initialSize = initialSize;
+    }
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message