List of usage examples for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_FAIL
byte WHEN_EXHAUSTED_FAIL
To view the source code for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_FAIL.
Click Source Link
From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericKeyedObjectPool.java
public void testMaxActiveZero() throws Exception { pool.setMaxActive(0);/* ww w. j a va 2s . co m*/ pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL); try { pool.borrowObject("a"); fail("Expected NoSuchElementException"); } catch (NoSuchElementException e) { // expected } }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericKeyedObjectPool.java
public void testMaxTotalZero() throws Exception { pool.setMaxTotal(0);/*w ww . j av a2 s. c o m*/ pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL); try { pool.borrowObject("a"); fail("Expected NoSuchElementException"); } catch (NoSuchElementException e) { // expected } }
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 va2s . co m .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 .jav a 2s .co 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.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:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java
public void testNegativeMaxActive() throws Exception { pool.setMaxActive(-1);//from w ww . j a v a 2 s . c om pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL); Object obj = pool.borrowObject(); assertEquals(getNthObject(0), obj); pool.returnObject(obj); }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java
public void testMaxActive() throws Exception { pool.setMaxActive(3);//from w ww.j a v a 2s.c o m pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL); pool.borrowObject(); pool.borrowObject(); pool.borrowObject(); try { pool.borrowObject(); fail("Expected NoSuchElementException"); } catch (NoSuchElementException e) { // expected } }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java
public void testMaxActiveZero() throws Exception { pool.setMaxActive(0);/* w w w. j a v a2s.co m*/ pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL); try { pool.borrowObject(); fail("Expected NoSuchElementException"); } catch (NoSuchElementException e) { // expected } }
From source file:ca.sqlpower.sqlobject.SQLDatabase.java
synchronized BaseObjectPool getConnectionPool() { if (connectionPool == null) { Config poolConfig = new GenericObjectPool.Config(); poolConfig.maxActive = 5;/*from ww w . j a v a2 s. c om*/ poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL; connectionPool = new GenericObjectPool(null, poolConfig); ConnectionFactory cf = new JDBCDSConnectionFactory(dataSource); new PoolableConnectionFactory(cf, connectionPool, null, null, false, true); } return connectionPool; }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java
public void testSettersAndGetters() throws Exception { GenericObjectPool pool = new GenericObjectPool(); {/*from w w w .j av a 2 s .co 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:org.apache.aries.transaction.jms.internal.ConnectionPool.java
/** * Configure whether the createSession method should block when there are no more idle sessions and the * pool already contains the maximum number of active sessions. If false the create method will fail * and throw an exception.//w w w . j a v a2 s . c om * * @param block * Indicates whether blocking should be used to wait for more space to create a session. */ public void setBlockIfSessionPoolIsFull(boolean block) { this.sessionPool.setWhenExhaustedAction( (block ? GenericObjectPool.WHEN_EXHAUSTED_BLOCK : GenericObjectPool.WHEN_EXHAUSTED_FAIL)); }