tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r1311844 - in /tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool: ConnectionPool.java PoolProperties.java jmx/ConnectionPool.java
Date Tue, 10 Apr 2012 16:29:43 GMT
Author: fhanik
Date: Tue Apr 10 16:29:42 2012
New Revision: 1311844

URL: http://svn.apache.org/viewvc?rev=1311844&view=rev
Log:
https://issues.apache.org/bugzilla/show_bug.cgi?id=50864
Add in the ability to configure most pool properties even while the pool is running

Modified:
    tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
    tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
    tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java

Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java?rev=1311844&r1=1311843&r2=1311844&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
(original)
+++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
Tue Apr 10 16:29:42 2012
@@ -442,11 +442,7 @@ public class ConnectionPool {
             idle = new ArrayBlockingQueue<PooledConnection>(properties.getMaxActive(),properties.isFairQueue());
         }
 
-        //if the evictor thread is supposed to run, start it now
-        if (properties.isPoolSweeperEnabled()) {
-            poolCleaner = new PoolCleaner(this, properties.getTimeBetweenEvictionRunsMillis());
-            poolCleaner.start();
-        } //end if
+        initializePoolCleaner(properties);
 
         //create JMX MBean
         if (this.getPoolProperties().isJmxEnabled()) createMBean();
@@ -496,6 +492,15 @@ public class ConnectionPool {
     }
 
 
+    public void initializePoolCleaner(PoolConfiguration properties) {
+        //if the evictor thread is supposed to run, start it now
+        if (properties.isPoolSweeperEnabled()) {
+            poolCleaner = new PoolCleaner(this, properties.getTimeBetweenEvictionRunsMillis());
+            poolCleaner.start();
+        } //end if
+    }
+
+
 //===============================================================================
 //         CONNECTION POOLING IMPL LOGIC
 //===============================================================================

Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java?rev=1311844&r1=1311843&r2=1311844&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
(original)
+++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
Tue Apr 10 16:29:42 2012
@@ -42,55 +42,55 @@ public class PoolProperties implements P
     public static final int DEFAULT_MAX_ACTIVE = 100;
 
     protected static AtomicInteger poolCounter = new AtomicInteger(0);
-    protected Properties dbProperties = new Properties();
-    protected String url = null;
-    protected String driverClassName = null;
-    protected Boolean defaultAutoCommit = null;
-    protected Boolean defaultReadOnly = null;
-    protected int defaultTransactionIsolation = DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION;
-    protected String defaultCatalog = null;
-    protected String connectionProperties;
-    protected int initialSize = 10;
-    protected int maxActive = DEFAULT_MAX_ACTIVE;
-    protected int maxIdle = maxActive;
-    protected int minIdle = initialSize;
-    protected int maxWait = 30000;
-    protected String validationQuery;
-    protected String validatorClassName;
-    protected Validator validator;
-    protected boolean testOnBorrow = false;
-    protected boolean testOnReturn = false;
-    protected boolean testWhileIdle = false;
-    protected int timeBetweenEvictionRunsMillis = 5000;
-    protected int numTestsPerEvictionRun;
-    protected int minEvictableIdleTimeMillis = 60000;
-    protected final boolean accessToUnderlyingConnectionAllowed = true;
-    protected boolean removeAbandoned = false;
-    protected int removeAbandonedTimeout = 60;
-    protected boolean logAbandoned = false;
-    protected String name = "Tomcat Connection Pool["+(poolCounter.addAndGet(1))+"-"+System.identityHashCode(PoolProperties.class)+"]";
-    protected String password;
-    protected String username;
-    protected long validationInterval = 30000;
-    protected boolean jmxEnabled = true;
-    protected String initSQL;
-    protected boolean testOnConnect =false;
-    protected String jdbcInterceptors=null;
-    protected boolean fairQueue = true;
-    protected boolean useEquals = true;
-    protected int abandonWhenPercentageFull = 0;
-    protected long maxAge = 0;
-    protected boolean useLock = false;
-    protected InterceptorDefinition[] interceptors = null;
-    protected int suspectTimeout = 0;
-    protected Object dataSource = null;
-    protected String dataSourceJNDI = null;
-    protected boolean alternateUsernameAllowed = false;
-    protected boolean commitOnReturn = false;
-    protected boolean rollbackOnReturn = false;
-    protected boolean useDisposableConnectionFacade = true;
-    protected boolean logValidationErrors = false;
-    protected boolean propagateInterruptState = false;
+    private volatile Properties dbProperties = new Properties();
+    private volatile String url = null;
+    private volatile String driverClassName = null;
+    private volatile Boolean defaultAutoCommit = null;
+    private volatile Boolean defaultReadOnly = null;
+    private volatile int defaultTransactionIsolation = DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION;
+    private volatile String defaultCatalog = null;
+    private volatile String connectionProperties;
+    private volatile int initialSize = 10;
+    private volatile int maxActive = DEFAULT_MAX_ACTIVE;
+    private volatile int maxIdle = maxActive;
+    private volatile int minIdle = initialSize;
+    private volatile int maxWait = 30000;
+    private volatile String validationQuery;
+    private volatile String validatorClassName;
+    private volatile Validator validator;
+    private volatile boolean testOnBorrow = false;
+    private volatile boolean testOnReturn = false;
+    private volatile boolean testWhileIdle = false;
+    private volatile int timeBetweenEvictionRunsMillis = 5000;
+    private volatile int numTestsPerEvictionRun;
+    private volatile int minEvictableIdleTimeMillis = 60000;
+    private volatile boolean accessToUnderlyingConnectionAllowed = true;
+    private volatile boolean removeAbandoned = false;
+    private volatile int removeAbandonedTimeout = 60;
+    private volatile boolean logAbandoned = false;
+    private volatile String name = "Tomcat Connection Pool["+(poolCounter.addAndGet(1))+"-"+System.identityHashCode(PoolProperties.class)+"]";
+    private volatile String password;
+    private volatile String username;
+    private volatile long validationInterval = 30000;
+    private volatile boolean jmxEnabled = true;
+    private volatile String initSQL;
+    private volatile boolean testOnConnect =false;
+    private volatile String jdbcInterceptors=null;
+    private volatile boolean fairQueue = true;
+    private volatile boolean useEquals = true;
+    private volatile int abandonWhenPercentageFull = 0;
+    private volatile long maxAge = 0;
+    private volatile boolean useLock = false;
+    private volatile InterceptorDefinition[] interceptors = null;
+    private volatile int suspectTimeout = 0;
+    private volatile Object dataSource = null;
+    private volatile String dataSourceJNDI = null;
+    private volatile boolean alternateUsernameAllowed = false;
+    private volatile boolean commitOnReturn = false;
+    private volatile boolean rollbackOnReturn = false;
+    private volatile boolean useDisposableConnectionFacade = true;
+    private volatile boolean logValidationErrors = false;
+    private volatile boolean propagateInterruptState = false;
 
 
     /**

Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java?rev=1311844&r1=1311843&r2=1311844&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
(original)
+++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
Tue Apr 10 16:29:42 2012
@@ -490,176 +490,177 @@ public class ConnectionPool extends Noti
 
     @Override
     public void setInitialSize(int initialSize) {
-        // TODO Auto-generated method stub
+        // noop - this pool is already running
+        throw new UnsupportedOperationException();
 
     }
 
 
     @Override
     public void setInitSQL(String initSQL) {
-        // TODO Auto-generated method stub
+        getPoolProperties().setInitSQL(initSQL);
 
     }
 
 
     @Override
     public void setJdbcInterceptors(String jdbcInterceptors) {
-        // TODO Auto-generated method stub
-
+        // noop - this pool is already running
+        throw new UnsupportedOperationException();
     }
 
 
     @Override
     public void setJmxEnabled(boolean jmxEnabled) {
-        // TODO Auto-generated method stub
-
+        // noop - this pool is already running and obviously jmx enabled
+        throw new UnsupportedOperationException();
     }
 
 
     @Override
     public void setLogAbandoned(boolean logAbandoned) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setLogAbandoned(logAbandoned);
     }
 
 
     @Override
     public void setMaxActive(int maxActive) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setMaxActive(maxActive);
     }
 
 
     @Override
     public void setMaxIdle(int maxIdle) {
-        // TODO Auto-generated method stub
+        getPoolProperties().setMaxIdle(maxIdle);
 
     }
 
 
     @Override
     public void setMaxWait(int maxWait) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setMaxWait(maxWait);
     }
 
 
     @Override
     public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
-        // TODO Auto-generated method stub
-
+        boolean wasEnabled = getPoolProperties().isPoolSweeperEnabled();
+        getPoolProperties().setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
+        boolean shouldBeEnabled = getPoolProperties().isPoolSweeperEnabled();
+        //make sure pool cleaner starts when it should
+        if (!wasEnabled && shouldBeEnabled) pool.initializePoolCleaner(getPoolProperties());
     }
 
 
     @Override
     public void setMinIdle(int minIdle) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setMinIdle(minIdle);
     }
 
 
     @Override
     public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setNumTestsPerEvictionRun(numTestsPerEvictionRun);
     }
 
 
     @Override
     public void setPassword(String password) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setPassword(password);
     }
 
 
     @Override
     public void setRemoveAbandoned(boolean removeAbandoned) {
-        // TODO Auto-generated method stub
-
+        boolean wasEnabled = getPoolProperties().isPoolSweeperEnabled();
+        getPoolProperties().setRemoveAbandoned(removeAbandoned);
+        boolean shouldBeEnabled = getPoolProperties().isPoolSweeperEnabled();
+        //make sure pool cleaner starts when it should
+        if (!wasEnabled && shouldBeEnabled) pool.initializePoolCleaner(getPoolProperties());
     }
 
 
     @Override
     public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
-        // TODO Auto-generated method stub
-
+        boolean wasEnabled = getPoolProperties().isPoolSweeperEnabled();
+        getPoolProperties().setRemoveAbandonedTimeout(removeAbandonedTimeout);
+        boolean shouldBeEnabled = getPoolProperties().isPoolSweeperEnabled();
+        //make sure pool cleaner starts when it should
+        if (!wasEnabled && shouldBeEnabled) pool.initializePoolCleaner(getPoolProperties());
     }
 
 
     @Override
     public void setTestOnBorrow(boolean testOnBorrow) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setTestOnBorrow(testOnBorrow);
     }
 
 
     @Override
     public void setTestOnConnect(boolean testOnConnect) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setTestOnConnect(testOnConnect);
     }
 
 
     @Override
     public void setTestOnReturn(boolean testOnReturn) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setTestOnReturn(testOnReturn);
     }
 
 
     @Override
     public void setTestWhileIdle(boolean testWhileIdle) {
-        // TODO Auto-generated method stub
-
+        boolean wasEnabled = getPoolProperties().isPoolSweeperEnabled();
+        getPoolProperties().setTestWhileIdle(testWhileIdle);
+        boolean shouldBeEnabled = getPoolProperties().isPoolSweeperEnabled();
+        //make sure pool cleaner starts when it should
+        if (!wasEnabled && shouldBeEnabled) pool.initializePoolCleaner(getPoolProperties());
     }
 
 
     @Override
     public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
-        // TODO Auto-generated method stub
-
+        boolean wasEnabled = getPoolProperties().isPoolSweeperEnabled();
+        getPoolProperties().setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
+        boolean shouldBeEnabled = getPoolProperties().isPoolSweeperEnabled();
+        //make sure pool cleaner starts when it should
+        if (!wasEnabled && shouldBeEnabled) pool.initializePoolCleaner(getPoolProperties());
     }
 
 
     @Override
     public void setUrl(String url) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setUrl(url);
     }
 
 
     @Override
     public void setUseEquals(boolean useEquals) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setUseEquals(useEquals);
     }
 
 
     @Override
     public void setUseLock(boolean useLock) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setUseLock(useLock);
     }
 
 
     @Override
     public void setUsername(String username) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setUsername(username);
     }
 
 
     @Override
     public void setValidationInterval(long validationInterval) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setValidationInterval(validationInterval);
     }
 
 
     @Override
     public void setValidationQuery(String validationQuery) {
-        // TODO Auto-generated method stub
-
+        getPoolProperties().setValidationQuery(validationQuery);
     }
 
     /**
@@ -686,7 +687,7 @@ public class ConnectionPool extends Noti
 
     @Override
     public void setSuspectTimeout(int seconds) {
-        //no op
+        getPoolProperties().setSuspectTimeout(seconds);
     }
 
     /**
@@ -711,7 +712,7 @@ public class ConnectionPool extends Noti
      */
     @Override
     public void setDataSourceJNDI(String jndiDS) {
-        //noop
+        getPoolProperties().setDataSourceJNDI(jndiDS);
     }
 
     /**
@@ -735,7 +736,7 @@ public class ConnectionPool extends Noti
      */
     @Override
     public void setAlternateUsernameAllowed(boolean alternateUsernameAllowed) {
-        //noop
+        getPoolProperties().setAlternateUsernameAllowed(alternateUsernameAllowed);
     }
 
     /**
@@ -743,7 +744,7 @@ public class ConnectionPool extends Noti
      */
     @Override
     public void setValidator(Validator validator) {
-        //noop
+        getPoolProperties().setValidator(validator);
     }
 
     /**



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


Mime
View raw message