db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer ConnectionFactory.java ConnectionFactoryAbstractImpl.java ConnectionFactoryDBCPImpl.java ConnectionFactoryNotPooledImpl.java ConnectionFactoryPooledImpl.java
Date Sat, 18 Dec 2004 13:32:10 GMT
arminw      2004/12/18 05:32:10

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        ConnectionFactory.java
                        ConnectionFactoryAbstractImpl.java
                        ConnectionFactoryDBCPImpl.java
                        ConnectionFactoryNotPooledImpl.java
                        ConnectionFactoryPooledImpl.java
  Log:
  introduce monitoring methods in ConnectionFactory
  
  Revision  Changes    Path
  1.14      +18 -3     db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactory.java
  
  Index: ConnectionFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactory.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ConnectionFactory.java	14 Sep 2004 16:03:32 -0000	1.13
  +++ ConnectionFactory.java	18 Dec 2004 13:32:10 -0000	1.14
  @@ -16,6 +16,7 @@
    */
   
   import java.sql.Connection;
  +import java.util.Date;
   
   /**
    * ConnectionFactory is responsible to lookup and release the
  @@ -37,14 +38,28 @@
   
       /**
        * Release connection - CAUTION: Release every connection after use to avoid abandoned
connections.
  -     * Depending on the used implementation connection will be closed, returned to pool,
...
  +     * Depending on the used implementation the connection will be closed, returned to
pool, ...
        */
       public void releaseConnection(Connection con);
   
       /**
        * Release all resources
  -     * used by the implementing class (e.g. connection pool, ...)
  -     * for the given connection descriptor.
  +     * used by the implementing class (e.g. connection pool, ...).
        */
       public void releaseAllResources();
  +
  +    /**
  +     * Returns the number of active connections.
  +     * When {@link #releaseConnection(java.sql.Connection)}
  +     * was called, the connection was removed from active connections.
  +     *
  +     * @return Date array of active connections.
  +     */
  +    public int getActiveConnections();
  +
  +    /**
  +     * The number of idle connections in this class, e.g. idle connections in pool.
  +     * @return Number of idle connections
  +     */
  +    public int getIdleConnections();
   }
  
  
  
  1.13      +16 -7     db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryAbstractImpl.java
  
  Index: ConnectionFactoryAbstractImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryAbstractImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ConnectionFactoryAbstractImpl.java	14 Sep 2004 16:03:32 -0000	1.12
  +++ ConnectionFactoryAbstractImpl.java	18 Dec 2004 13:32:10 -0000	1.13
  @@ -15,12 +15,6 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  -import org.apache.ojb.broker.platforms.PlatformException;
  -import org.apache.ojb.broker.util.ClassHelper;
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  -
   import javax.naming.InitialContext;
   import javax.naming.NamingException;
   import javax.sql.DataSource;
  @@ -30,6 +24,12 @@
   import java.util.HashMap;
   import java.util.Map;
   
  +import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  +import org.apache.ojb.broker.platforms.PlatformException;
  +import org.apache.ojb.broker.util.ClassHelper;
  +import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
  +
   /**
    * Abstract base class to simplify implementation of {@link ConnectionFactory}'s.
    *
  @@ -40,6 +40,7 @@
   {
       private Logger log = LoggerFactory.getLogger(ConnectionFactoryAbstractImpl.class);
       private final JdbcConnectionDescriptor jcd;
  +    private int activeConnections;
   
       /**
        * holds the datasource looked up from JNDI in a map, keyed
  @@ -79,9 +80,15 @@
       public abstract void returnConnectionToPool(Connection con)
               throws LookupException;
   
  +    public int getActiveConnections()
  +    {
  +        return activeConnections;
  +    }
  +
       public void releaseConnection(Connection con)
       {
           if (con == null) return;
  +        --activeConnections;
           if (jcd.isDataSource())
           {
               try
  @@ -142,6 +149,7 @@
                   throw new LookupException("Connection check failed", e);
               }
           }
  +        ++activeConnections;
           return conn;
       }
   
  @@ -175,6 +183,7 @@
        */
       public synchronized void releaseAllResources()
       {
  +        this.activeConnections = 0;
           this.dataSourceCache.clear();
       }
   
  
  
  
  1.14      +8 -3      db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java
  
  Index: ConnectionFactoryDBCPImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ConnectionFactoryDBCPImpl.java	15 Nov 2004 17:35:35 -0000	1.13
  +++ ConnectionFactoryDBCPImpl.java	18 Dec 2004 13:32:10 -0000	1.14
  @@ -54,6 +54,11 @@
           super(jcd);
       }
   
  +    public int getIdleConnections()
  +    {
  +        return connectionPool.getNumIdle();
  +    }
  +
       public Connection getConnectionFromPool() throws LookupException
       {
           synchronized (dummy)
  @@ -89,8 +94,7 @@
   
       public synchronized void releaseAllResources()
       {
  -        log.warn("Release all resources and destroy pooled connections");
  -        super.releaseAllResources();
  +        log.warn("Clear connection pool");
           synchronized (dummy)
           {
               try
  @@ -104,6 +108,7 @@
               connectionPool = null;
               dataSource = null;
           }
  +        super.releaseAllResources();
       }
   
       /**
  
  
  
  1.7       +6 -1      db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryNotPooledImpl.java
  
  Index: ConnectionFactoryNotPooledImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryNotPooledImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConnectionFactoryNotPooledImpl.java	11 Aug 2004 00:42:52 -0000	1.6
  +++ ConnectionFactoryNotPooledImpl.java	18 Dec 2004 13:32:10 -0000	1.7
  @@ -37,6 +37,11 @@
           super(jcd);
       }
   
  +    public int getIdleConnections()
  +    {
  +        return 0;
  +    }
  +
       public Connection getConnectionFromPool() throws LookupException
       {
           if (log.isDebugEnabled())
  
  
  
  1.19      +8 -3      db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java
  
  Index: ConnectionFactoryPooledImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ConnectionFactoryPooledImpl.java	15 Nov 2004 17:35:35 -0000	1.18
  +++ ConnectionFactoryPooledImpl.java	18 Dec 2004 13:32:10 -0000	1.19
  @@ -49,6 +49,11 @@
           pool = createConnectionPool();
       }
   
  +    public int getIdleConnections()
  +    {
  +        return pool.getNumIdle();
  +    }
  +
       public void returnConnectionToPool(Connection con)
               throws LookupException
       {
  @@ -79,8 +84,7 @@
        */
       public void releaseAllResources()
       {
  -        log.warn("Release all resources and destroy pooled connections");
  -        super.releaseAllResources();
  +        log.warn("Clear connection pool");
           try
           {
               pool.clear();
  @@ -89,6 +93,7 @@
           {
               log.error("Error while clear connection pool", e);
           }
  +        super.releaseAllResources();
       }
   
       /**
  
  
  

---------------------------------------------------------------------
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