Examples of ObjectPool


Examples of org.apache.commons.pool.ObjectPool

    /**
     * Verifies that initIdleCapacity is not a hard limit, but maxIdle is.
     */
    public void testInitIdleCapacityExceeded() throws Exception {
        PoolableObjectFactory factory = new SimpleFactory();
        ObjectPool pool = new StackObjectPool(factory, 2, 1);
        pool.addObject();
        pool.addObject();
        assertEquals(2, pool.getNumIdle());
        pool.close();
        pool = new StackObjectPool(factory, 1, 2);
        pool.addObject();
        pool.addObject();
        assertEquals(1, pool.getNumIdle());
    }
View Full Code Here

Examples of org.apache.commons.pool.ObjectPool

     * Verifies close contract - idle instances are destroyed, returning instances
     * are destroyed, add/borrowObject throw IllegalStateException.
     */
    public void testClose() throws Exception {
        SelectiveFactory factory = new SelectiveFactory();
        ObjectPool pool = new StackObjectPool(factory);
        pool.addObject(); // 0
        pool.addObject(); // 1
        pool.addObject(); // 2
        Integer two = (Integer) pool.borrowObject();
        assertEquals(2, two.intValue());
        pool.close();
        assertEquals(0, pool.getNumIdle());
        assertEquals(1, pool.getNumActive());
        List destroyed = factory.getDestroyed();
        assertEquals(2, destroyed.size());
        assertTrue(destroyed.contains(new Integer(0)));
        assertTrue(destroyed.contains(new Integer(0)));
        pool.returnObject(two);
        assertTrue(destroyed.contains(two));
        try {
            pool.addObject();
            fail("Expecting IllegalStateException");
        } catch (IllegalStateException ex) {
            // Expected
        }
        try {
            pool.borrowObject();
            fail("Expecting IllegalStateException");
        } catch (IllegalStateException ex) {
            // Expected
        }
    }
View Full Code Here

Examples of org.apache.commons.pool.ObjectPool

    return dataSource;
  }

  public static void printDriverStats() throws Exception {
    ObjectPool connectionPool = ConnectionManager._pool;
    logger.debug("NumActive: " + connectionPool.getNumActive());
    logger.debug("NumIdle: " + connectionPool.getNumIdle());
  }
View Full Code Here

Examples of org.apache.commons.pool.ObjectPool

     */
    public static ObjectPool createConnectionPool(String uri,
            Properties properties) {
        // Create an ObjectPool that will serve as the actual pool of
        // connections
        ObjectPool result = new GenericObjectPool(null);

        // Create a ConnectionFactory that the pool will use to create
        // Connections
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
                uri, properties);
View Full Code Here

Examples of org.apache.commons.pool.ObjectPool

        try
        {
            if (useConnectionPool())
            {
                ObjectPool pool = getClientPool(endpoint);
                client = (SftpClient) pool.borrowObject();
            }
            else
            {
                client = SftpConnectionFactory.createClient(endpoint);
            }
View Full Code Here

Examples of org.apache.commons.pool.ObjectPool

            }
            else
            {
                if (client != null && client.isConnected())
                {
                    ObjectPool pool = getClientPool(endpoint);
                    if (logger.isDebugEnabled())
                    {
                        logger.debug("Releasing connection for endpoint " + endpoint.getEndpointURI());
                    }
                    pool.returnObject(client);
                }
            }
        }
        else
        {
View Full Code Here

Examples of org.apache.commons.pool.ObjectPool

    {
        if (useConnectionPool())
        {
            if ((client != null) && (client.isConnected()))
            {
                ObjectPool pool = getClientPool(endpoint);
                pool.invalidateObject(client);
            }
        }
    }
View Full Code Here

Examples of org.apache.commons.pool.ObjectPool

        connector.setConnectionFactoryClass(testFactory.getClass().getName());
        // no validate call for simplicity
        connector.setValidateConnections(false);

        ObjectPool pool = connector.getFtpPool(endpointURI);
        Object obj = pool.borrowObject();
        assertEquals("Custom FTP connection factory has been ignored.", testObject, obj);
    }
View Full Code Here

Examples of org.apache.commons.pool.ObjectPool

        if (logger.isDebugEnabled())
        {
            logger.debug("=== get pool for " + uri);
        }
        String key = uri.getUser() + ":" + uri.getPassword() + "@" + uri.getHost() + ":" + uri.getPort();
        ObjectPool pool = pools.get(key);
        if (pool == null)
        {
            try
            {
                FtpConnectionFactory connectionFactory =
View Full Code Here

Examples of org.apache.commons.pool.ObjectPool

     */
    public synchronized DataSource getPoolingDataSource(
        Object key,
        ConnectionFactory connectionFactory)
    {
        ObjectPool connectionPool = getPool(key, connectionFactory);
        // create pooling datasource
        return new PoolingDataSource(connectionPool);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.