leif        02/02/22 01:26:21

  Modified:    src/scratchpad/org/apache/avalon/excalibur/datasource
                        ResourceLimitingJdbcDataSource.java
  Log:
  Make it possible to set the max-strict flag on the pool.
  Based on changes by Mark Woon.
  
  Revision  Changes    Path
  1.6       +85 -42    
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/datasource/ResourceLimitingJdbcDataSource.java
  
  Index: ResourceLimitingJdbcDataSource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/datasource/ResourceLimitingJdbcDataSource.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ResourceLimitingJdbcDataSource.java       8 Feb 2002 12:03:52 -0000       
1.5
  +++ ResourceLimitingJdbcDataSource.java       22 Feb 2002 09:26:21 -0000      
1.6
  @@ -19,15 +19,29 @@
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   
   /**
  - * The ResourceLimiting implementation for DataSources in Avalon.  This uses 
the
  - * normal <code>java.sql.Connection</code> object and
  + * The ResourceLimiting implementation for DataSources in Avalon.
  + * This uses the normal <code>java.sql.Connection</code> object and
    * <code>java.sql.DriverManager</code>.
    * <p>
  + * This datasource pool implementation is designed to make as many
  + * database connections as are needed available without placing
  + * undo load on the database server.
  + * <p>
  + * If an application under normal load needs 3 database connections
  + * for example, then the <code>max</code> pool size should be set
  + * to a value like 10.  This will allow the pool to grow to accomodate
  + * a sudden spike in load without allowing the pool to grow to such
  + * a large size as to place undo load on the database server.  The
  + * pool's trimming features will keep track of how many connections
  + * are actually needed and close those connections which are no longer
  + * required.
  + * <p>
    * Configuration Example:
    * <pre>
    *   &lt;jdbc&gt;
  - *     &lt;pool-controller max="<i>10</i>" blocking="<i>true</i>"
  - *       timeout="<i>-1</i>" trim-interval="<i>60000</i>"
  + *     &lt;pool-controller max="<i>10</i>" maxStrict="<i>true</i>"
  + *       blocking="<i>true</i>" timeout="<i>-1</i>"
  + *       trim-interval="<i>60000</i>" auto-commit="true"
    *       connection-class="<i>my.overrided.ConnectionClass</i>"&gt;
    *       &lt;keep-alive disable="false"&gt;select 1&lt;/keep-alive&gt;
    *     &lt;/pool-controller&gt;
  @@ -50,48 +64,74 @@
    * <p>
    * Configuration Attributes:
    * <ul>
  - * <li>The <code>max</code> attribute is used to set the maximum number of 
connections which
  - *  will be opened.  See the <code>blocking</code> attribute.  (Defaults to 
"3")</li>
  + * <li>The <code>max</code> attribute is used to set the maximum
  + * number of connections which will be opened.  See the
  + * <code>blocking</code> attribute.  (Defaults to "3")</li>
  + *
  + * <li>The <code>max-strict</code> attribute is used to determine whether
  + * or not the maximum number of connections can be exceeded.  If true,
  + * then an exception will be thrown if more than max connections are
  + * requested and blocking is false.  (Defaults to "true")<br>
  + * <i>WARNING: In most cases, this value
  + * should always be set to true.  Setting it to false means that under
  + * heavy load, your application may open a very large number of
  + * connections to the database.  Some database servers behave very poorly
  + * under large connection loads and can even crash.</i></li>
  + *
  + * <li>The <code>blocking</code> attributes is used to specify the
  + * behavior of the DataSource pool when an attempt is made to allocate
  + * more than <code>max</code> concurrent connections.  If true, the
  + * request will block until a connection is released, otherwise, a
  + * NoAvailableConnectionException will be thrown.  Ignored if
  + * <code>max-strict</code> is false.  (Defaults to "true")</li>
  + *
  + * <li>The <code>timeout</code> attribute is used to specify the
  + * maximum amount of time in milliseconds that a request for a
  + * connection will be allowed to block before a
  + * NoAvailableConnectionException is thrown.  A value of "0" specifies
  + * that the block will never timeout.  (Defaults to "0")</li>
  + *
  + * <li>The <code>trim-interval</code> attribute is used to specify how
  + * long idle connections will be maintained in the pool before being
  + * closed.  For a complete explanation on how this works, see [EMAIL 
PROTECTED]
  + * org.apache.avalon.excalibur.pool.ResourceLimitingPool#trim()}
  + * (Defaults to "60000", 1 minute)</li>
  + *
  + * <li>The <code>auto-commit</code> attribute is used to determine the
  + * default auto-commit mode for the <code>Connection</code>s returned
  + * by this <code>DataSource</code>.
  + *
  + * <li>The <code>connection-class</code> attribute is used to override
  + * the Connection class returned by the DataSource from calls to
  + * getConnection().  Set this to
  + * "org.apache.avalon.excalibur.datasource.Jdbc3Connection" to gain
  + * access to JDBC3 features.  Jdbc3Connection does not exist if your
  + * JVM does not support JDBC3.  (Defaults to
  + * "org.apache.avalon.excalibur.datasource.JdbcConnection")</li>
    *
  - * <li>The <code>blocking</code> attributes is used to specify the behavior 
of the DataSource
  - *  pool when an attempt is made to allocate more than <code>max</code> 
concurrent connections.
  - *  If true, the request will block until a connection is released, 
otherwise, a 
  - *  NoAvailableConnectionException will be thrown.  (Defaults to "true")</li>
  - *
  - * <li>The <code>timeout</code> attribute is used to specify the maximum 
amount of time in
  - *  milliseconds that a request for a connection will be allowed to block 
before a
  - *  NoAvailableConnectionException is thrown.  A value of "0" specifies that 
the block will never
  - *  timeout.  (Defaults to "0")</li>
  - *
  - * <li>The <code>trim-interval</code> attribute is used to specify how long 
idle connections will
  - *  be maintained in the pool before being closed.  For a complete 
explanation on how this works,
  - *  see [EMAIL PROTECTED] 
org.apache.avalon.excalibur.pool.ResourceLimitingPool#trim()}
  - *  (Defaults to "60000", 1 minute)</li>
  - *
  - * <li>The <code>connection-class</code> attribute is used to override the 
Connection class returned
  - *  by the DataSource from calls to getConnection().  Set this to 
  - *  "org.apache.avalon.excalibur.datasource.Jdbc3Connection" to gain access 
to JDBC3 features.
  - *  Jdbc3Connection does not exist if your JVM does not support JDBC3.
  - *  (Defaults to 
"org.apache.avalon.excalibur.datasource.JdbcConnection")</li>
  - *
  - * <li>The <code>keep-alive</code> element is used to override the query 
used to monitor the health
  - *  of connections.  If a connection has not been used for 5 seconds then 
before returning the
  - *  connection from a call to getConnection(), the connection is first used 
to ping the database
  - *  to make sure that it is still alive.  Setting the <code>disable</code> 
attribute to true will
  - *  disable this feature.  (Defaults to a query of "SELECT 1" and being 
enabled)</li>
  + * <li>The <code>keep-alive</code> element is used to override the
  + * query used to monitor the health of connections.  If a connection
  + * has not been used for 5 seconds then before returning the
  + * connection from a call to getConnection(), the connection is first
  + * used to ping the database to make sure that it is still alive.
  + * Setting the <code>disable</code> attribute to true will disable
  + * this feature.  (Defaults to a query of "SELECT 1" and being
  + * enabled)</li> 
    *
  - * <li>The <code>driver</code> element is used to specify the driver to use 
when connecting to the
  - *  database.  The specified class must be in the classpath.  (Required)</li>
  + * <li>The <code>driver</code> element is used to specify the driver
  + * to use when connecting to the database.  The specified class must
  + * be in the classpath.  (Required)</li>
    *
  - * <li>The <code>dburl</code> element is the JDBC connection string which 
will be used to connect to
  - *  the database.  (Required)</li>
  + * <li>The <code>dburl</code> element is the JDBC connection string
  + * which will be used to connect to the database.  (Required)</li>
    *
  - * <li>The <code>user</code> and <code>password</code> attributes are used 
to specify the user and
  - *  password for connections to the database. (Required)</li>
  + * <li>The <code>user</code> and <code>password</code> attributes are
  + * used to specify the user and password for connections to the
  + * database. (Required)</li>
    * </ul>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
  - * @version CVS $Revision: 1.5 $ $Date: 2002/02/08 12:03:52 $
  + * @version CVS $Revision: 1.6 $ $Date: 2002/02/22 09:26:21 $
    * @since 4.1
    */
   public class ResourceLimitingJdbcDataSource 
  @@ -172,9 +212,11 @@
           
           final Configuration controller = configuration.getChild( 
"pool-controller" );
           String keepAlive = controller.getChild( "keep-alive" ).getValue( 
"SELECT 1" );
  -        final boolean disableKeepAlive = controller.getChild( "keep-alive" 
).getAttributeAsBoolean( "disable", false );
  +        final boolean disableKeepAlive = 
  +            controller.getChild( "keep-alive" ).getAttributeAsBoolean( 
"disable", false );
           
           final int     max          = controller.getAttributeAsInteger( 
"max", 3 );
  +        final boolean maxStrict    = controller.getAttributeAsBoolean( 
"max-strict", true );
           final boolean blocking     = controller.getAttributeAsBoolean( 
"blocking", true );
           final long    timeout      = controller.getAttributeAsLong   ( 
"timeout", 0 );
           final long    trimInterval = controller.getAttributeAsLong   ( 
"trim-interval", 60000 );
  @@ -222,7 +264,8 @@
               l_max = max;
           }
   
  -        // If the keepAlive disable attribute was set, then set the 
keepAlive query to null, disabling it.
  +        // If the keepAlive disable attribute was set, then set the 
keepAlive query to null,
  +        //  disabling it.
           if (disableKeepAlive)
           {
               keepAlive = null;
  @@ -251,7 +294,7 @@
           try
           {
               m_pool = new ResourceLimitingJdbcConnectionPool
  -                (factory, l_max, true, blocking, timeout, trimInterval, 
autoCommit );
  +                (factory, l_max, maxStrict, blocking, timeout, trimInterval, 
autoCommit );
               m_pool.enableLogging( getLogger() );
           }
           catch (Exception e)
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to