Package org.apache.commons.pool

Examples of org.apache.commons.pool.KeyedObjectPool


    }

    synchronized public Object makeObject() throws Exception {
        Connection conn = _connFactory.createConnection();
        if(null != _stmtPoolFactory) {
            KeyedObjectPool stmtpool = _stmtPoolFactory.createPool();
            conn = new PoolingConnection(conn,stmtpool);
            stmtpool.setFactory((PoolingConnection)conn);
        }
        return new PoolableConnection(conn,_pool,_config);
    }
View Full Code Here


        if (conn == null) {
            throw new IllegalStateException("Connection factory returned null from createConnection");
        }
        initializeConnection(conn);
        if(null != _stmtPoolFactory) {
            KeyedObjectPool stmtpool = _stmtPoolFactory.createPool();
            conn = new PoolingConnection(conn,stmtpool);
            stmtpool.setFactory((PoolingConnection)conn);
        }
        return new PoolableManagedConnection(transactionRegistry,conn,_pool,_config);
    }
View Full Code Here

        int maxIdle, boolean testOnBorrow, boolean testOnReturn,
        long timeBetweenEvictionRunsMillis,
        int numTestsPerEvictionRun, long minEvictableIdleTimeMillis,
        boolean testWhileIdle) {
        */
        KeyedObjectPool stmtPool = null;
        if (isPoolPreparedStatements()) {
            if (getMaxPreparedStatements() <= 0)
            {
                // since there is no limit, create a prepared statement pool with an eviction thread
                //  evictor settings are the same as the connection pool settings.
View Full Code Here

        if (conn == null) {
            throw new IllegalStateException("Connection factory returned null from createConnection");
        }
        initializeConnection(conn);
        if(null != _stmtPoolFactory) {
            KeyedObjectPool stmtpool = _stmtPoolFactory.createPool();
            conn = new PoolingConnection(conn,stmtpool);
            stmtpool.setFactory((PoolingConnection)conn);
        }
        return new PoolableConnection(conn,_pool,_config);
    }
View Full Code Here

     * Close and free all {@link PreparedStatement}s or {@link CallableStatement} from the pool, and
     * close the underlying connection.
     */
    public synchronized void close() throws SQLException {
        if(null != _pstmtPool) {
            KeyedObjectPool oldpool = _pstmtPool;           
            _pstmtPool = null;
            try {
                oldpool.close();
            } catch(RuntimeException e) {
                throw e;
            } catch(SQLException e) {
                throw e;
            } catch(Exception e) {
View Full Code Here

        int maxIdle, boolean testOnBorrow, boolean testOnReturn,
        long timeBetweenEvictionRunsMillis,
        int numTestsPerEvictionRun, long minEvictableIdleTimeMillis,
        boolean testWhileIdle) {
        */
        KeyedObjectPool stmtPool = null;
        if (isPoolPreparedStatements())
        {
            stmtPool = new GenericKeyedObjectPool(null,
                getMaxActive(), GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 0,
                getMaxIdle(), false, false, getTimeBetweenEvictionRunsMillis(),
View Full Code Here

        int maxIdle, boolean testOnBorrow, boolean testOnReturn,
        long timeBetweenEvictionRunsMillis,
        int numTestsPerEvictionRun, long minEvictableIdleTimeMillis,
        boolean testWhileIdle) {
        */
        KeyedObjectPool stmtPool = null;
        if (isPoolPreparedStatements()) {
            stmtPool = new GenericKeyedObjectPool(null,
                getMaxActive(), GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 0,
                getMaxIdle(), false, false, getTimeBetweenEvictionRunsMillis(),
                getNumTestsPerEvictionRun(),
View Full Code Here

   }

   @Override
   public void releaseTransport(Transport transport) {
      // The invalidateObject()/returnObject() calls could take a long time, so we hold the lock only until we get the connection pool reference
      KeyedObjectPool pool = getConnectionPool();
      TcpTransport tcpTransport = (TcpTransport) transport;
      if (!tcpTransport.isValid()) {
         try {
            if (log.isTraceEnabled()) {
               log.tracef("Dropping connection as it is no longer valid: %s", tcpTransport);
            }
            pool.invalidateObject(tcpTransport.getServerAddress(), tcpTransport);
         } catch (Exception e) {
            log.couldNoInvalidateConnection(tcpTransport, e);
         }
      } else {
         try {
            pool.returnObject(tcpTransport.getServerAddress(), tcpTransport);
         } catch (Exception e) {
            log.couldNotReleaseConnection(tcpTransport, e);
         } finally {
            logConnectionInfo(tcpTransport.getServerAddress());
         }
View Full Code Here

         return servers;
      }
   }

   private void logConnectionInfo(SocketAddress server) {
      KeyedObjectPool pool = getConnectionPool();
      if (log.isTraceEnabled()) {
         log.tracef("For server %s: active = %d; idle = %d", server, pool.getNumActive(server), pool.getNumIdle(server));
      }
   }
View Full Code Here

      }
   }

   private Transport borrowTransportFromPool(SocketAddress server) {
      // The borrowObject() call could take a long time, so we hold the lock only until we get the connection pool reference
      KeyedObjectPool pool = getConnectionPool();
      try {
         return (Transport) pool.borrowObject(server);
      } catch (Exception e) {
         String message = "Could not fetch transport";
         log.couldNotFetchTransport(e);
         throw new TransportException(message, e);
      } finally {
View Full Code Here

TOP

Related Classes of org.apache.commons.pool.KeyedObjectPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.