Package org.apache.commons.pool.impl

Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool


        final List calledMethods = new ArrayList();
        final Object key = new Object();

        // Test that the minIdle check doesn't add too many idle objects
        final KeyedPoolableObjectFactory kpof = (KeyedPoolableObjectFactory)createProxy(KeyedPoolableObjectFactory.class, calledMethods);
        final KeyedObjectPool kop = new GenericKeyedObjectPool(kpof);
        PoolUtils.checkMinIdle(kop, key, 2, 100);
        Thread.sleep(400);
        assertEquals(2, kop.getNumIdle(key));
        assertEquals(2, kop.getNumIdle());
        kop.close();
        int makeObjectCount = 0;
        final Iterator iter = calledMethods.iterator();
        while (iter.hasNext()) {
            final String methodName = (String)iter.next();
            if ("makeObject".equals(methodName)) {
View Full Code Here


            config.maxActive = poolSize;
            config.testOnBorrow = true;
            config.whenExhaustedAction = GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK;
            config.maxWait = 10000;
            StringPoolableObjectFactory objFactory = new StringPoolableObjectFactory();
            final KeyedObjectPool pool = new GenericKeyedObjectPool(objFactory, config);
            PerformanceTest test = new PerformanceTest() {

                @Override
                public void doOperation(int id) throws Exception {
                    Integer key = id % numKeys;
                    String s = (String) pool.borrowObject(key);
                    pool.returnObject(key, s);
                }
            };
            test.run(numRequests, numThreads);
            test.printStats();
            System.out.println();
View Full Code Here

   }

   public void testClosedConnection() throws Exception {
      rc.put("k","v"); //make sure a connection is created

      GenericKeyedObjectPool keyedObjectPool = transportFactory.getConnectionPool();
      InetSocketAddress address = new InetSocketAddress("127.0.0.1", hotRodServer.getPort());

      assertEquals(0, keyedObjectPool.getNumActive(address));
      assertEquals(1, keyedObjectPool.getNumIdle(address));

      TcpTransport tcpConnection = (TcpTransport) keyedObjectPool.borrowObject(address);
      keyedObjectPool.returnObject(address, tcpConnection);//now we have a reference to the single connection in pool

      tcpConnection.destroy();

      assertEquals("v", rc.get("k"));
      assertEquals(0, keyedObjectPool.getNumActive(address));
      assertEquals(1, keyedObjectPool.getNumIdle(address));

      TcpTransport tcpConnection2 = (TcpTransport) keyedObjectPool.borrowObject(address);

      assert tcpConnection2.getId() != tcpConnection.getId();
   }
View Full Code Here

    private final GenericKeyedObjectPool pool;

    public DefaultConfigurableKeyedObjectPool()
    {
        pool = new GenericKeyedObjectPool();

        // NOTE: testOnBorrow MUST be FALSE. this is a bit of a design bug in
        // commons-pool since validate is used for both activation and passivation,
        // but has no way of knowing which way it is going.
        pool.setTestOnBorrow(false);
View Full Code Here

        final List calledMethods = new ArrayList();
        final Object key = new Object();

        // Test that the minIdle check doesn't add too many idle objects
        final KeyedPoolableObjectFactory kpof = (KeyedPoolableObjectFactory)createProxy(KeyedPoolableObjectFactory.class, calledMethods);
        final KeyedObjectPool kop = new GenericKeyedObjectPool(kpof);
        PoolUtils.checkMinIdle(kop, key, 2, 100);
        Thread.sleep(400);
        assertEquals(2, kop.getNumIdle(key));
        assertEquals(2, kop.getNumIdle());
        kop.close();
        int makeObjectCount = 0;
        final Iterator iter = calledMethods.iterator();
        while (iter.hasNext()) {
            final String methodName = (String)iter.next();
            if ("makeObject".equals(methodName)) {
View Full Code Here

     */
    GenericKeyedObjectPool _pool;

    public void initializeService()
    {
        _pool = new GenericKeyedObjectPool(this);

        _pool.setMaxActive(Integer.parseInt(_propertySource.getPropertyValue("org.apache.tapestry.page-pool-max-active")));
        _pool.setMaxIdle(Integer.parseInt(_propertySource.getPropertyValue("org.apache.tapestry.page-pool-max-idle")));

        _pool.setMinIdle(Integer.parseInt(_propertySource.getPropertyValue("org.apache.tapestry.page-pool-min-idle")));
View Full Code Here

        throws javax.naming.NamingException, SQLException {

        ConnectionPoolDataSource cpds = testCPDS(username, password);

        // Create an object pool to contain our PooledConnections
        GenericKeyedObjectPool tmpPool = new GenericKeyedObjectPool(null);
        tmpPool.setMaxActive(getMaxActive());
        tmpPool.setMaxIdle(getMaxIdle());
        tmpPool.setMaxWait(getMaxWait());
        tmpPool.setWhenExhaustedAction(whenExhaustedAction(maxActive, maxWait));
        tmpPool.setTestOnBorrow(getTestOnBorrow());
        tmpPool.setTestOnReturn(getTestOnReturn());
        tmpPool.setTimeBetweenEvictionRunsMillis(
            getTimeBetweenEvictionRunsMillis());
        tmpPool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
        tmpPool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
        tmpPool.setTestWhileIdle(getTestWhileIdle());
        pool = tmpPool;
        // Set up the factory we will use (passing the pool associates
        // the factory with the pool, so we do not have to do so
        // explicitly)
        new KeyedCPDSConnectionFactory(cpds, pool, getValidationQuery());
View Full Code Here

        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(),
                getMinEvictableIdleTimeMillis(), false);           
        }
View Full Code Here

     */
    GenericKeyedObjectPool _pool;

    public void initializeService()
    {
        _pool = new GenericKeyedObjectPool(this);

        _pool.setMaxActive(Integer.parseInt(_propertySource.getPropertyValue("org.apache.tapestry.page-pool-max-active")));
        _pool.setMaxIdle(Integer.parseInt(_propertySource.getPropertyValue("org.apache.tapestry.page-pool-max-idle")));

        _pool.setMinIdle(Integer.parseInt(_propertySource.getPropertyValue("org.apache.tapestry.page-pool-min-idle")));
View Full Code Here

        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.
                stmtPool = new GenericKeyedObjectPool(null,
                    getMaxActive(), GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 0,
                    getMaxIdle(), false, false,
                    getTimeBetweenEvictionRunsMillis(),getNumTestsPerEvictionRun(),getMinEvictableIdleTimeMillis(),
                    false);
            }
            else
            {
                // since there is limit, create a prepared statement pool without an eviction thread
                //  pool has LRU functionality so when the limit is reached, 15% of the pool is cleared.
                // see org.apache.commons.pool.impl.GenericKeyedObjectPool.clearOldest method
                stmtPool = new GenericKeyedObjectPool(null,
                    getMaxActive(), GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 0,
                    getMaxIdle(), getMaxPreparedStatements(), false, false,
                    -1,0,0, // -1 tells the pool that there should be no eviction thread.
                    false);
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.pool.impl.GenericKeyedObjectPool

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.