You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by se...@apache.org on 2001/11/03 04:15:03 UTC

cvs commit: jakarta-james/src/java/org/apache/james/transport/mailets JDBCAlias.java JDBCListserv.java

serge       01/11/02 19:15:03

  Modified:    src/java/org/apache/james/transport/mailets JDBCAlias.java
                        JDBCListserv.java
  Log:
  Wrap excalibur's getConnection in a retry block since it doesn't pool well when at max num of conns.
  
  Revision  Changes    Path
  1.5       +22 -7     jakarta-james/src/java/org/apache/james/transport/mailets/JDBCAlias.java
  
  Index: JDBCAlias.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/mailets/JDBCAlias.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JDBCAlias.java	2001/11/01 16:05:33	1.4
  +++ JDBCAlias.java	2001/11/03 03:15:03	1.5
  @@ -18,6 +18,7 @@
   import org.apache.avalon.excalibur.datasource.DataSourceComponent;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.CascadingRuntimeException;
   import org.apache.james.Constants;
   
   /**
  @@ -60,7 +61,7 @@
               // Get the data-source required.
               datasource = (DataSourceComponent)datasources.select(datasourceName);
   
  -            conn = datasource.getConnection();
  +            conn = getConnection();
   
               // Check if the required table exists. If not, complain.
               DatabaseMetaData dbMetaData = conn.getMetaData();
  @@ -157,13 +158,27 @@
       /**
        * Opens a database connection.
        */
  -    private Connection getConnection() throws MessagingException {
  -        try {
  -            return datasource.getConnection();
  -        } catch (SQLException sqle) {
  -            throw new MessagingException (
  -                "An exception occurred getting a database connection.", sqle);
  +    protected Connection getConnection() {
  +        int attempts = 0;
  +        while (attempts < 1000) {
  +            try {
  +                return datasource.getConnection();
  +            } catch (SQLException e1) {
  +                if (e1.getMessage().equals("Could not create enough Components to service your request.")) {
  +                    //stupid pool
  +                    try {
  +                        Thread.sleep(50);
  +                    } catch (InterruptedException ie) {
  +                        //ignore
  +                    }
  +                    attempts++;
  +                } else {
  +                    throw new CascadingRuntimeException(
  +                        "An exception occurred getting a database connection.", e1);
  +                }
  +            }
           }
  +        throw new RuntimeException("Failed to get a connection after " + attempts + " attempts");
       }
   
       /**
  
  
  
  1.4       +22 -7     jakarta-james/src/java/org/apache/james/transport/mailets/JDBCListserv.java
  
  Index: JDBCListserv.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/mailets/JDBCListserv.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JDBCListserv.java	2001/11/01 16:06:26	1.3
  +++ JDBCListserv.java	2001/11/03 03:15:03	1.4
  @@ -18,6 +18,7 @@
   import org.apache.avalon.excalibur.datasource.DataSourceComponent;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.CascadingRuntimeException;
   import org.apache.james.Constants;
   
   /**
  @@ -95,7 +96,7 @@
               // Get the data-source required.
               datasource = (DataSourceComponent)datasources.select(datasourceName);
   
  -            conn = datasource.getConnection();
  +            conn = getConnection();
   
               // Check if the required listserv table exists. If not, complain.
               DatabaseMetaData dbMetaData = conn.getMetaData();
  @@ -255,13 +256,27 @@
       /**
        * Opens a database connection.
        */
  -    private Connection getConnection() throws MessagingException {
  -        try {
  -            return datasource.getConnection();
  -        } catch (SQLException sqle) {
  -            throw new MessagingException (
  -                "An exception occurred getting a database connection.", sqle);
  +    protected Connection getConnection() {
  +        int attempts = 0;
  +        while (attempts < 1000) {
  +            try {
  +                return datasource.getConnection();
  +            } catch (SQLException e1) {
  +                if (e1.getMessage().equals("Could not create enough Components to service your request.")) {
  +                    //stupid pool
  +                    try {
  +                        Thread.sleep(50);
  +                    } catch (InterruptedException ie) {
  +                        //ignore
  +                    }
  +                    attempts++;
  +                } else {
  +                    throw new CascadingRuntimeException(
  +                        "An exception occurred getting a database connection.", e1);
  +                }
  +            }
           }
  +        throw new RuntimeException("Failed to get a connection after " + attempts + " attempts");
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>