Example usage for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_GROW

List of usage examples for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_GROW

Introduction

In this page you can find the example usage for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_GROW.

Prototype

byte WHEN_EXHAUSTED_GROW

To view the source code for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_GROW.

Click Source Link

Document

A "when exhausted action" type indicating that when the pool is exhausted (i.e., the maximum number of active objects has been reached), the #borrowObject method should simply create a new object anyway.

Usage

From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericKeyedObjectPool.java

public void testWhenExhaustedGrow() throws Exception {
    pool.setMaxActive(1);//from  ww w  .  j a v  a  2  s . com
    pool.setMaxTotal(1);
    pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    for (int i = 0; i < 10; i++) {
        pool.borrowObject("a");
    }
}

From source file:com.tango.logstash.flume.redis.source.RedisSource.java

@Override
protected void doConfigure(Context context) throws FlumeException {
    logger.info("Configuring");
    host = context.getString(RedisSourceConfigurationConstant.HOST);
    Preconditions.checkState(StringUtils.isNotBlank(host),
            "host cannot be empty, please specify in configuration file");

    port = context.getInteger(RedisSourceConfigurationConstant.PORT, Protocol.DEFAULT_PORT);
    timeout = context.getInteger(RedisSourceConfigurationConstant.TIMEOUT, Protocol.DEFAULT_TIMEOUT);
    database = context.getInteger(RedisSourceConfigurationConstant.DATABASE, Protocol.DEFAULT_DATABASE);
    password = context.getString(RedisSourceConfigurationConstant.PASSWORD);
    redisKey = context//w  w w.  ja  v  a2s  .  com
            .getString(RedisSourceConfigurationConstant.KEY, RedisSourceConfigurationConstant.DEFAULT_KEY)
            .getBytes();
    batchSize = context.getInteger(RedisSourceConfigurationConstant.BATCH_SIZE,
            RedisSourceConfigurationConstant.DEFAULT_BATCH_SIZE);
    String serializerClassName = context.getString(RedisSourceConfigurationConstant.SERIALIZER,
            RedisSourceConfigurationConstant.DEFAULT_SERIALIZER_CLASS_NAME);

    maxActive = context.getInteger(RedisSourceConfigurationConstant.REDIS_MAX_ACTIVE);
    maxIdle = context.getInteger(RedisSourceConfigurationConstant.REDIS_MAX_IDLE);
    minIdle = context.getInteger(RedisSourceConfigurationConstant.REDIS_MIN_IDLE);
    numTestsPerEvictionRun = context
            .getInteger(RedisSourceConfigurationConstant.REDIS_NUM_TESTS_PER_EVICTION_RUN);
    maxWait = context.getLong(RedisSourceConfigurationConstant.REDIS_MAX_WAIT);
    minEvictableIdleTimeMillis = context
            .getLong(RedisSourceConfigurationConstant.REDIS_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    softMinEvictableIdleTimeMillis = context
            .getLong(RedisSourceConfigurationConstant.REDIS_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    testOnBorrow = context.getBoolean(RedisSourceConfigurationConstant.REDIS_TEST_ON_BORROW);
    testOnReturn = context.getBoolean(RedisSourceConfigurationConstant.REDIS_TEST_ON_RETURN);
    testWhileIdle = context.getBoolean(RedisSourceConfigurationConstant.REDIS_TEST_WHILE_IDLE);
    timeBetweenEvictionRunsMillis = context
            .getLong(RedisSourceConfigurationConstant.REDIS_TIME_BETWEEN_EVICTION_RUNS_MILLIS);

    String whenExhaustedActionStr = context
            .getString(RedisSourceConfigurationConstant.REDIS_WHEN_EXHAUSTED_ACTION);
    if (StringUtils.isNotBlank(whenExhaustedActionStr) == true) {
        if (whenExhaustedActionStr.equalsIgnoreCase(WHEN_EXHAUSTED_BLOCK)) {
            whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
        } else if (whenExhaustedActionStr.equalsIgnoreCase(WHEN_EXHAUSTED_FAIL)) {
            whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
        } else if (whenExhaustedActionStr.equalsIgnoreCase(WHEN_EXHAUSTED_GROW)) {
            whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        }
    }

    Preconditions.checkState(batchSize > 0,
            RedisSourceConfigurationConstant.BATCH_SIZE + " parameter must be greater than 1");

    try {
        /**
         * Instantiate serializer
         */
        @SuppressWarnings("unchecked")
        Class<? extends Serializer> clazz = (Class<? extends Serializer>) Class.forName(serializerClassName);
        serializer = clazz.newInstance();

        /**
         * Configure it
         */
        Context serializerContext = new Context();
        serializerContext.putAll(context.getSubProperties(RedisSourceConfigurationConstant.SERIALIZER_PREFIX));
        serializer.configure(serializerContext);

    } catch (ClassNotFoundException e) {
        logger.error("Could not instantiate event serializer", e);
        Throwables.propagate(e);
    } catch (InstantiationException e) {
        logger.error("Could not instantiate event serializer", e);
        Throwables.propagate(e);
    } catch (IllegalAccessException e) {
        logger.error("Could not instantiate event serializer", e);
        Throwables.propagate(e);
    }

    if (sourceCounter == null) {
        sourceCounter = new SourceCounter(getName());
    }

}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericKeyedObjectPool.java

public void testSettersAndGetters() throws Exception {
    GenericKeyedObjectPool pool = new GenericKeyedObjectPool();
    {/*from  www  . j a v  a  2 s  .  com*/
        pool.setFactory(new SimpleFactory());
    }
    {
        pool.setMaxActive(123);
        assertEquals(123, pool.getMaxActive());
    }
    {
        pool.setMaxIdle(12);
        assertEquals(12, pool.getMaxIdle());
    }
    {
        pool.setMaxWait(1234L);
        assertEquals(1234L, pool.getMaxWait());
    }
    {
        pool.setMinEvictableIdleTimeMillis(12345L);
        assertEquals(12345L, pool.getMinEvictableIdleTimeMillis());
    }
    {
        pool.setNumTestsPerEvictionRun(11);
        assertEquals(11, pool.getNumTestsPerEvictionRun());
    }
    {
        pool.setTestOnBorrow(true);
        assertTrue(pool.getTestOnBorrow());
        pool.setTestOnBorrow(false);
        assertTrue(!pool.getTestOnBorrow());
    }
    {
        pool.setTestOnReturn(true);
        assertTrue(pool.getTestOnReturn());
        pool.setTestOnReturn(false);
        assertTrue(!pool.getTestOnReturn());
    }
    {
        pool.setTestWhileIdle(true);
        assertTrue(pool.getTestWhileIdle());
        pool.setTestWhileIdle(false);
        assertTrue(!pool.getTestWhileIdle());
    }
    {
        pool.setTimeBetweenEvictionRunsMillis(11235L);
        assertEquals(11235L, pool.getTimeBetweenEvictionRunsMillis());
    }
    {
        pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_BLOCK, pool.getWhenExhaustedAction());
        pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_FAIL, pool.getWhenExhaustedAction());
        pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
    }
}

From source file:net.sf.farrago.namespace.jdbc.MedJdbcDataServer.java

private void initializeDataSource() throws SQLException {
    assert (!disableConnectionPool);

    if (jndiName != null) {
        try {/*  w w w  .j a v a 2 s  .  c  om*/
            // TODO: Allow specification of initial context factory and
            // provider URL via addition options.  These should be stored
            // in jndiEnv before the initJndi call and the names (keys) of
            // the those properties would be used in the JndiUtil
            // constructor. Can also allow artibrary env properties.
            JndiUtil jndiUtil = new JndiUtil("", Context.INITIAL_CONTEXT_FACTORY, Context.PROVIDER_URL);

            Properties jndiEnv = new Properties();
            jndiUtil.initJndi(jndiEnv);
            InitialContext initCtx = jndiUtil.newInitialContext(jndiEnv);

            dataSource = jndiUtil.lookup(initCtx, jndiName, DataSource.class);

            if (dataSource == null) {
                throw FarragoResource.instance().MedJdbc_InvalidDataSource.ex(jndiName);
            }

            return;
        } catch (NamingException e) {
            throw FarragoResource.instance().MedJdbc_InvalidDataSource.ex(jndiName, e);
        }
    }

    String userName = getUserName();
    String password = getPassword();

    ConnectionFactory connectionFactory;
    if (connectProps != null) {
        if (userName != null) {
            connectProps.setProperty("user", userName);
        }
        if (password != null) {
            connectProps.setProperty("password", password);
        }

        connectionFactory = new DriverManagerConnectionFactory(url, connectProps);
    } else if (userName == null) {
        connectionFactory = new DriverManagerConnectionFactory(url, new Properties());
    } else {
        if (password == null) {
            password = "";
        }

        connectionFactory = new DriverManagerConnectionFactory(url, userName, password);
    }

    if (validateWhileIdle && (evictionTimerPeriodMillis <= 0L)) {
        logger.warning("Request to validate on idle ignored: property " + PROP_EVICTION_TIMER_PERIOD_MILLIS
                + " must be > 0");

        if ((validationQuery != null) && !validateOnBorrow && !validateOnReturn) {
            validateOnBorrow = true;

            logger.warning("Enabling validation on request");
        }
    }

    connectionPool = new GenericObjectPool();
    connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    connectionPool.setMaxActive(-1);

    connectionPool.setTestOnBorrow(validateOnBorrow);
    connectionPool.setTestOnReturn(validateOnReturn);
    connectionPool.setTestWhileIdle(validateWhileIdle);

    connectionPool.setMaxIdle(maxIdleConnections);
    connectionPool.setTimeBetweenEvictionRunsMillis(evictionTimerPeriodMillis);
    connectionPool.setMinEvictableIdleTimeMillis(minEvictionIdleMillis);

    CustomPoolableConnectionFactory poolableConnectionFactory = new CustomPoolableConnectionFactory(
            connectionFactory, connectionPool, validationQuery, autocommit, null);

    connectionPool.setFactory(poolableConnectionFactory);
    PoolingDataSource pds = new PoolingDataSource(connectionPool);
    pds.setAccessToUnderlyingConnectionAllowed(true);
    dataSource = pds;
}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java

public void testSettersAndGetters() throws Exception {
    GenericObjectPool pool = new GenericObjectPool();
    {/*from  ww  w  .  j a v a  2  s .c o  m*/
        pool.setFactory(new SimpleFactory());
    }
    {
        pool.setMaxActive(123);
        assertEquals(123, pool.getMaxActive());
    }
    {
        pool.setMaxIdle(12);
        assertEquals(12, pool.getMaxIdle());
    }
    {
        pool.setMaxWait(1234L);
        assertEquals(1234L, pool.getMaxWait());
    }
    {
        pool.setMinEvictableIdleTimeMillis(12345L);
        assertEquals(12345L, pool.getMinEvictableIdleTimeMillis());
    }
    {
        pool.setNumTestsPerEvictionRun(11);
        assertEquals(11, pool.getNumTestsPerEvictionRun());
    }
    {
        pool.setTestOnBorrow(true);
        assertTrue(pool.getTestOnBorrow());
        pool.setTestOnBorrow(false);
        assertTrue(!pool.getTestOnBorrow());
    }
    {
        pool.setTestOnReturn(true);
        assertTrue(pool.getTestOnReturn());
        pool.setTestOnReturn(false);
        assertTrue(!pool.getTestOnReturn());
    }
    {
        pool.setTestWhileIdle(true);
        assertTrue(pool.getTestWhileIdle());
        pool.setTestWhileIdle(false);
        assertTrue(!pool.getTestWhileIdle());
    }
    {
        pool.setTimeBetweenEvictionRunsMillis(11235L);
        assertEquals(11235L, pool.getTimeBetweenEvictionRunsMillis());
    }
    {
        pool.setSoftMinEvictableIdleTimeMillis(12135L);
        assertEquals(12135L, pool.getSoftMinEvictableIdleTimeMillis());
    }
    {
        pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_BLOCK, pool.getWhenExhaustedAction());
        pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_FAIL, pool.getWhenExhaustedAction());
        pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
    }
}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java

public void testConstructors() throws Exception {
    {/*w  ww  .  j  a va2s. c o  m*/
        GenericObjectPool pool = new GenericObjectPool();
        assertConfiguration(new GenericObjectPool.Config(), pool);
    }
    {
        GenericObjectPool pool = new GenericObjectPool(new SimpleFactory());
        assertConfiguration(new GenericObjectPool.Config(), pool);
    }
    {
        GenericObjectPool.Config expected = new GenericObjectPool.Config();
        expected.maxActive = 2;
        expected.maxIdle = 3;
        expected.maxWait = 5L;
        expected.minEvictableIdleTimeMillis = 7L;
        expected.numTestsPerEvictionRun = 9;
        expected.testOnBorrow = true;
        expected.testOnReturn = true;
        expected.testWhileIdle = true;
        expected.timeBetweenEvictionRunsMillis = 11L;
        expected.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        GenericObjectPool pool = new GenericObjectPool(null, expected);
        assertConfiguration(expected, pool);
    }
    {
        GenericObjectPool.Config expected = new GenericObjectPool.Config();
        expected.maxActive = 2;
        GenericObjectPool pool = new GenericObjectPool(null, expected.maxActive);
        assertConfiguration(expected, pool);
    }
    {
        GenericObjectPool.Config expected = new GenericObjectPool.Config();
        expected.maxActive = 2;
        expected.maxWait = 5L;
        expected.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        GenericObjectPool pool = new GenericObjectPool(null, expected.maxActive, expected.whenExhaustedAction,
                expected.maxWait);
        assertConfiguration(expected, pool);
    }
    {
        GenericObjectPool.Config expected = new GenericObjectPool.Config();
        expected.maxActive = 2;
        expected.maxWait = 5L;
        expected.testOnBorrow = true;
        expected.testOnReturn = true;
        expected.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        GenericObjectPool pool = new GenericObjectPool(null, expected.maxActive, expected.whenExhaustedAction,
                expected.maxWait, expected.testOnBorrow, expected.testOnReturn);
        assertConfiguration(expected, pool);
    }
    {
        GenericObjectPool.Config expected = new GenericObjectPool.Config();
        expected.maxActive = 2;
        expected.maxIdle = 3;
        expected.maxWait = 5L;
        expected.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        GenericObjectPool pool = new GenericObjectPool(null, expected.maxActive, expected.whenExhaustedAction,
                expected.maxWait, expected.maxIdle);
        assertConfiguration(expected, pool);
    }
    {
        GenericObjectPool.Config expected = new GenericObjectPool.Config();
        expected.maxActive = 2;
        expected.maxIdle = 3;
        expected.maxWait = 5L;
        expected.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        expected.testOnBorrow = true;
        expected.testOnReturn = true;
        GenericObjectPool pool = new GenericObjectPool(null, expected.maxActive, expected.whenExhaustedAction,
                expected.maxWait, expected.maxIdle, expected.testOnBorrow, expected.testOnReturn);
        assertConfiguration(expected, pool);
    }
    {
        GenericObjectPool.Config expected = new GenericObjectPool.Config();
        expected.maxActive = 2;
        expected.maxIdle = 3;
        expected.maxWait = 5L;
        expected.minEvictableIdleTimeMillis = 7L;
        expected.numTestsPerEvictionRun = 9;
        expected.testOnBorrow = true;
        expected.testOnReturn = true;
        expected.testWhileIdle = true;
        expected.timeBetweenEvictionRunsMillis = 11L;
        expected.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        GenericObjectPool pool = new GenericObjectPool(null, expected.maxActive, expected.whenExhaustedAction,
                expected.maxWait, expected.maxIdle, expected.testOnBorrow, expected.testOnReturn,
                expected.timeBetweenEvictionRunsMillis, expected.numTestsPerEvictionRun,
                expected.minEvictableIdleTimeMillis, expected.testWhileIdle);
        assertConfiguration(expected, pool);
    }
    {
        GenericObjectPool.Config expected = new GenericObjectPool.Config();
        expected.maxActive = 2;
        expected.maxIdle = 3;
        expected.minIdle = 1;
        expected.maxWait = 5L;
        expected.minEvictableIdleTimeMillis = 7L;
        expected.numTestsPerEvictionRun = 9;
        expected.testOnBorrow = true;
        expected.testOnReturn = true;
        expected.testWhileIdle = true;
        expected.timeBetweenEvictionRunsMillis = 11L;
        expected.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        GenericObjectPool pool = new GenericObjectPool(null, expected.maxActive, expected.whenExhaustedAction,
                expected.maxWait, expected.maxIdle, expected.minIdle, expected.testOnBorrow,
                expected.testOnReturn, expected.timeBetweenEvictionRunsMillis, expected.numTestsPerEvictionRun,
                expected.minEvictableIdleTimeMillis, expected.testWhileIdle);
        assertConfiguration(expected, pool);
    }
}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericKeyedObjectPool.java

public void testConstructors() {

    // Make constructor arguments all different from defaults
    int maxActive = 1;
    int maxIdle = 2;
    long maxWait = 3;
    int minIdle = 4;
    int maxTotal = 5;
    long minEvictableIdleTimeMillis = 6;
    int numTestsPerEvictionRun = 7;
    boolean testOnBorrow = true;
    boolean testOnReturn = true;
    boolean testWhileIdle = true;
    long timeBetweenEvictionRunsMillis = 8;
    byte whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
    boolean lifo = false;

    GenericKeyedObjectPool pool = new GenericKeyedObjectPool();
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE, pool.getMaxActive());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_WAIT, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW, pool.getTestOnBorrow());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    GenericKeyedObjectPool.Config config = new GenericKeyedObjectPool.Config();
    config.lifo = lifo;//ww  w .  j a v  a2 s .  c o  m
    config.maxActive = maxActive;
    config.maxIdle = maxIdle;
    config.minIdle = minIdle;
    config.maxTotal = maxTotal;
    config.maxWait = maxWait;
    config.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
    config.numTestsPerEvictionRun = numTestsPerEvictionRun;
    config.testOnBorrow = testOnBorrow;
    config.testOnReturn = testOnReturn;
    config.testWhileIdle = testWhileIdle;
    config.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
    config.whenExhaustedAction = whenExhaustedAction;
    pool = new GenericKeyedObjectPool(null, config);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(minIdle, pool.getMinIdle());
    assertEquals(maxTotal, pool.getMaxTotal());
    assertEquals(minEvictableIdleTimeMillis, pool.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(testWhileIdle, pool.getTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(lifo, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_WAIT, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW, pool.getTestOnBorrow());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW, pool.getTestOnBorrow());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, testOnBorrow,
            testOnReturn);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW, pool.getTestOnBorrow());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle, testOnBorrow,
            testOnReturn);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle, testOnBorrow,
            testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis,
            testWhileIdle);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(minEvictableIdleTimeMillis, pool.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(testWhileIdle, pool.getTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal,
            testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
            minEvictableIdleTimeMillis, testWhileIdle);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(maxTotal, pool.getMaxTotal());
    assertEquals(minEvictableIdleTimeMillis, pool.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(testWhileIdle, pool.getTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal, minIdle,
            testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
            minEvictableIdleTimeMillis, testWhileIdle);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(minIdle, pool.getMinIdle());
    assertEquals(maxTotal, pool.getMaxTotal());
    assertEquals(minEvictableIdleTimeMillis, pool.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(testWhileIdle, pool.getTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal, minIdle,
            testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
            minEvictableIdleTimeMillis, testWhileIdle, lifo);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(minIdle, pool.getMinIdle());
    assertEquals(maxTotal, pool.getMaxTotal());
    assertEquals(minEvictableIdleTimeMillis, pool.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(testWhileIdle, pool.getTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(lifo, pool.getLifo());
}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java

public void testSetConfig() throws Exception {
    GenericObjectPool.Config expected = new GenericObjectPool.Config();
    GenericObjectPool pool = new GenericObjectPool();
    assertConfiguration(expected, pool);
    expected.maxActive = 2;/*from  ww w .j  av  a 2  s  . co m*/
    expected.maxIdle = 3;
    expected.maxWait = 5L;
    expected.minEvictableIdleTimeMillis = 7L;
    expected.numTestsPerEvictionRun = 9;
    expected.testOnBorrow = true;
    expected.testOnReturn = true;
    expected.testWhileIdle = true;
    expected.timeBetweenEvictionRunsMillis = 11L;
    expected.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
    pool.setConfig(expected);
    assertConfiguration(expected, pool);
}

From source file:org.apache.directory.fortress.core.ldap.LdapConnectionProvider.java

/**
 * Initialize the three connection pools using settings and coordinates contained in the config.
 *//*from w  ww  .ja  va  2s .co  m*/
private void init() {
    IS_SSL = (Config.getInstance().getProperty(GlobalIds.ENABLE_LDAP_SSL) != null
            && Config.getInstance().getProperty(GlobalIds.ENABLE_LDAP_SSL).equalsIgnoreCase("true")
            && Config.getInstance().getProperty(GlobalIds.TRUST_STORE) != null
            && Config.getInstance().getProperty(GlobalIds.TRUST_STORE_PW) != null);

    String host = Config.getInstance().getProperty(GlobalIds.LDAP_HOST, "localhost");
    int port = Config.getInstance().getInt(GlobalIds.LDAP_PORT, 389);
    int min = Config.getInstance().getInt(GlobalIds.LDAP_ADMIN_POOL_MIN, 1);
    int max = Config.getInstance().getInt(GlobalIds.LDAP_ADMIN_POOL_MAX, 10);
    int logmin = Config.getInstance().getInt(LDAP_LOG_POOL_MIN, 1);
    int logmax = Config.getInstance().getInt(LDAP_LOG_POOL_MAX, 10);
    LOG.info("LDAP POOL:  host=[{}], port=[{}], min=[{}], max=[{}]", host, port, min, max);

    LdapConnectionConfig config = new LdapConnectionConfig();
    config.setLdapHost(host);
    config.setLdapPort(port);
    config.setName(Config.getInstance().getProperty(GlobalIds.LDAP_ADMIN_POOL_UID, ""));

    config.setUseSsl(IS_SSL);
    //config.setTrustManagers( new NoVerificationTrustManager() );

    if (Config.getInstance().getBoolean(ENABLE_LDAP_STARTTLS, false)) {
        config.setUseTls(true);
    }

    if (IS_SSL && StringUtils.isNotEmpty(Config.getInstance().getProperty(GlobalIds.TRUST_STORE))
            && StringUtils.isNotEmpty(Config.getInstance().getProperty(GlobalIds.TRUST_STORE_PW))) {
        // validate certificates but allow self-signed certs if within this truststore:
        config.setTrustManagers(
                new LdapClientTrustStoreManager(Config.getInstance().getProperty(GlobalIds.TRUST_STORE),
                        Config.getInstance().getProperty(GlobalIds.TRUST_STORE_PW).toCharArray(), null, true));
    }

    String adminPw;
    if (EncryptUtil.isEnabled()) {
        adminPw = EncryptUtil.getInstance()
                .decrypt(Config.getInstance().getProperty(GlobalIds.LDAP_ADMIN_POOL_PW));
    } else {
        adminPw = Config.getInstance().getProperty(GlobalIds.LDAP_ADMIN_POOL_PW);
    }

    config.setCredentials(adminPw);
    try {
        List<String> listExOps = new ArrayList<>();
        listExOps.add("org.openldap.accelerator.impl.createSession.RbacCreateSessionFactory");
        listExOps.add("org.openldap.accelerator.impl.checkAccess.RbacCheckAccessFactory");
        listExOps.add("org.openldap.accelerator.impl.addRole.RbacAddRoleFactory");
        listExOps.add("org.openldap.accelerator.impl.dropRole.RbacDropRoleFactory");
        listExOps.add("org.openldap.accelerator.impl.deleteSession.RbacDeleteSessionFactory");
        listExOps.add("org.openldap.accelerator.impl.sessionRoles.RbacSessionRolesFactory");
        LdapApiService ldapApiService = new StandaloneLdapApiService(new ArrayList<String>(), listExOps);

        if (!LdapApiServiceFactory.isInitialized()) {
            LdapApiServiceFactory.initialize(ldapApiService);
        }
        config.setLdapApiService(ldapApiService);
    } catch (Exception ex) {
        String error = "Exception caught initializing Admin Pool: " + ex;
        throw new CfgRuntimeException(GlobalErrIds.FT_APACHE_LDAP_POOL_INIT_FAILED, error, ex);
    }

    PoolableObjectFactory<LdapConnection> poolFactory = new ValidatingPoolableLdapConnectionFactory(config);

    // Create the Admin pool
    adminPool = new LdapConnectionPool(poolFactory);
    adminPool.setTestOnBorrow(true);
    adminPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    adminPool.setMaxActive(max);
    adminPool.setMinIdle(min);
    adminPool.setMaxIdle(-1);
    //adminPool.setMaxWait( 0 );

    // Create the User pool
    userPool = new LdapConnectionPool(poolFactory);
    userPool.setTestOnBorrow(true);
    userPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    userPool.setMaxActive(max);
    userPool.setMinIdle(min);
    userPool.setMaxIdle(-1);

    // This pool of access log connections is used by {@link org.apache.directory.fortress.AuditMgr}.
    // To enable, set {@code log.admin.user} && {@code log.admin.pw} inside fortress.properties file:
    if (StringUtils.isNotEmpty(LDAP_LOG_POOL_UID) && StringUtils.isNotEmpty(LDAP_LOG_POOL_PW)) {
        // Initializing the log pool in static block requires static props set within fortress.properties.
        // To make this dynamic requires moving this code outside of static block AND storing the connection
        // metadata inside fortress config node (in ldap).
        LdapConnectionConfig logConfig = new LdapConnectionConfig();
        logConfig.setLdapHost(host);
        logConfig.setLdapPort(port);
        logConfig.setName(Config.getInstance().getProperty(GlobalIds.LDAP_ADMIN_POOL_UID, ""));

        logConfig.setUseSsl(IS_SSL);

        if (IS_SSL && StringUtils.isNotEmpty(Config.getInstance().getProperty(GlobalIds.TRUST_STORE))
                && StringUtils.isNotEmpty(Config.getInstance().getProperty(GlobalIds.TRUST_STORE_PW))) {
            // validate certificates but allow self-signed certs if within this truststore:
            logConfig.setTrustManagers(new LdapClientTrustStoreManager(
                    Config.getInstance().getProperty(GlobalIds.TRUST_STORE),
                    Config.getInstance().getProperty(GlobalIds.TRUST_STORE_PW).toCharArray(), null, true));
        }

        logConfig.setName(Config.getInstance().getProperty(LDAP_LOG_POOL_UID, ""));
        String logPw;
        if (EncryptUtil.isEnabled()) {
            logPw = EncryptUtil.getInstance().decrypt(Config.getInstance().getProperty(LDAP_LOG_POOL_PW));
        } else {
            logPw = Config.getInstance().getProperty(LDAP_LOG_POOL_PW);
        }
        logConfig.setCredentials(logPw);
        poolFactory = new ValidatingPoolableLdapConnectionFactory(logConfig);
        logPool = new LdapConnectionPool(poolFactory);
        logPool.setTestOnBorrow(true);
        logPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
        logPool.setMaxActive(logmax);
        logPool.setMinIdle(logmin);
    }
}

From source file:org.apache.wookie.beans.jcr.JCRPersistenceManager.java

/**
 * Initialize implementation with configuration.
 * /*from ww w .java  2 s .com*/
 * @param configuration configuration properties
 * @param initializeStore truncate and initialize persistent store
 */
public static void initialize(Configuration configuration, boolean initializeStore) {
    try {
        // configuration
        repositoryUser = configuration.getString(PERSISTENCE_MANAGER_USER_PROPERTY_NAME);
        repositoryPassword = configuration.getString(PERSISTENCE_MANAGER_PASSWORD_PROPERTY_NAME);
        repositoryWorkspace = configuration.getString(PERSISTENCE_MANAGER_WORKSPACE_PROPERTY_NAME);
        rootPath = configuration.getString(PERSISTENCE_MANAGER_ROOT_PATH_PROPERTY_NAME);
        for (Map.Entry<Class<? extends IBean>, Class<? extends IBean>> mapping : BEAN_INTERFACE_TO_CLASS_MAP
                .entrySet()) {
            Class<? extends IBean> beanClass = mapping.getValue();
            Class<? extends IBean> beanInterface = mapping.getKey();
            String name = beanInterface.getSimpleName();
            if (name.startsWith("I")) {
                name = name.substring(1);
            }
            if (!name.endsWith("s")) {
                name = name + "s";
            }
            String nodeRootPath = rootPath + "/" + name;
            beanClassNodeRootPaths.put(beanClass, nodeRootPath);
        }

        // create JCR credentials session pool
        PoolableObjectFactory sessionFactory = new BasePoolableObjectFactory() {
            /* (non-Javadoc)
             * @see org.apache.commons.pool.BasePoolableObjectFactory#passivateObject(java.lang.Object)
             */
            public void passivateObject(Object obj) throws Exception {
                // clear OCM object cache
                ((ObjectContentManagerImpl) obj).setRequestObjectCache(new RequestObjectCacheImpl());
            }

            /* (non-Javadoc)
             * @see org.apache.commons.pool.BasePoolableObjectFactory#makeObject()
             */
            public Object makeObject() throws Exception {
                // lookup JCR repository from context
                Context initialContext = new InitialContext();
                Repository repository = (Repository) initialContext
                        .lookup(WIDGET_REPOSITORY_JNDI_REPOSITORY_FULL_NAME);

                // create and login JCR session
                Credentials credentials = new SimpleCredentials(repositoryUser,
                        repositoryPassword.toCharArray());
                Session session = ((repositoryWorkspace != null)
                        ? repository.login(credentials, repositoryWorkspace)
                        : repository.login(credentials));

                // return session object content manager for session
                return new SessionObjectContentManagerImpl(session, new AnnotationMapperImpl(CLASS_LIST));
            }

            /* (non-Javadoc)
             * @see org.apache.commons.pool.BasePoolableObjectFactory#destroyObject(java.lang.Object)
             */
            public void destroyObject(Object obj) throws Exception {
                // logout and close object content manager and session
                ((ObjectContentManagerImpl) obj).logout();
            }
        };
        ocmPool = new GenericObjectPool(sessionFactory, 0, GenericObjectPool.WHEN_EXHAUSTED_GROW, 0, 5);
        ocmPool.setTimeBetweenEvictionRunsMillis(60000);
        ocmPool.setMinEvictableIdleTimeMillis(300000);

        // initialize persistent store
        if (initializeStore) {
            // borrow object content manager and initialization session from pool
            ObjectContentManager ocm = (ObjectContentManager) ocmPool.borrowObject();
            Session session = ocm.getSession();

            // initialize root path in repository

            // Jackrabbit/JCR 2.X
            //boolean rootPathNodeExists = session.nodeExists(rootPath);

            // Jackrabbit/JCR 1.X
            boolean rootPathNodeExists = session.itemExists(rootPath);

            if (rootPathNodeExists) {
                // delete nodes of root path node

                // Jackrabbit/JCR 2.X
                //Node rootNode = session.getNode(rootPath);

                // Jackrabbit/JCR 1.X
                Node rootNode = (Node) session.getItem(rootPath);

                NodeIterator nodesIter = rootNode.getNodes();
                while (nodesIter.hasNext()) {
                    nodesIter.nextNode().remove();
                }
            } else {
                // create unstructured node hierarchy
                int rootPathParentIndex = -1;
                int rootPathIndex = rootPath.indexOf('/', 1);
                while (rootPathIndex != -1) {
                    // Jackrabbit/JCR 2.X
                    //Node parentNode = session.getNode(rootPath.substring(0, ((rootPathParentIndex != -1) ? rootPathParentIndex : 1)));

                    // Jackrabbit/JCR 1.X
                    Node parentNode = (Node) session.getItem(
                            rootPath.substring(0, ((rootPathParentIndex != -1) ? rootPathParentIndex : 1)));

                    String nodeName = rootPath.substring(
                            ((rootPathParentIndex != -1) ? rootPathParentIndex + 1 : 1), rootPathIndex);
                    parentNode.addNode(nodeName, "nt:unstructured");
                    rootPathParentIndex = rootPathIndex;
                    rootPathIndex = rootPath.indexOf('/', rootPathIndex + 1);
                }

                // Jackrabbit/JCR 2.X
                //Node parentNode = session.getNode(rootPath.substring(0, ((rootPathParentIndex != -1) ? rootPathParentIndex : 1)));

                // Jackrabbit/JCR 1.X
                Node parentNode = (Node) session.getItem(
                        rootPath.substring(0, ((rootPathParentIndex != -1) ? rootPathParentIndex : 1)));

                String nodeName = rootPath
                        .substring(((rootPathParentIndex != -1) ? rootPathParentIndex + 1 : 1));
                parentNode.addNode(nodeName, "nt:unstructured");
            }
            // create bean class node root paths

            // Jackrabbit/JCR 2.X
            //Node rootNode = session.getNode(rootPath);

            // Jackrabbit/JCR 1.X
            Node rootNode = (Node) session.getItem(rootPath);

            for (String nodeRootPath : beanClassNodeRootPaths.values()) {
                String nodeName = nodeRootPath.substring(rootPath.length() + 1);
                rootNode.addNode(nodeName, "nt:unstructured");
            }
            session.save();

            // register/reregister repository node types
            NodeTypeManager nodeTypeManager = session.getWorkspace().getNodeTypeManager();
            InputStream nodeTypesCNDStream = JCRPersistenceManager.class
                    .getResourceAsStream("wookie-schema.cnd");
            if (nodeTypesCNDStream == null) {
                throw new IllegalArgumentException(
                        "Unable to load node types configuration: wookie-schema.cnd");
            }

            // Jackrabbit/JCR 2.X
            //Reader nodeTypesCNDReader = new InputStreamReader(nodeTypesCNDStream);
            //NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry();
            //ValueFactory valueFactory = session.getValueFactory();
            //CndImporter.registerNodeTypes(nodeTypesCNDReader, "wookie-schema.cnd", nodeTypeManager, namespaceRegistry, valueFactory, true);

            // Jackrabbit/JCR 1.X
            ((NodeTypeManagerImpl) nodeTypeManager).registerNodeTypes(nodeTypesCNDStream,
                    NodeTypeManagerImpl.TEXT_X_JCR_CND, true);

            // save session used to load node types
            session.save();
            logger.info("Persistent store initialized at " + rootPath);

            // return object content manager and initialization session to pool
            ocmPool.returnObject(ocm);
        }

        logger.info("Initialized");
    } catch (Exception e) {
        throw new RuntimeException("Unable to initialize: " + e, e);
    }
}