@Test public void testSynchronizedPoolKeyedObjectPool() throws Exception { try { PoolUtils.synchronizedPool((KeyedObjectPool<Object, Object>) null); fail("PoolUtils.synchronizedPool(KeyedObjectPool) must not allow a null pool."); } catch (final IllegalArgumentException iae) { // expected } final List<String> calledMethods = new ArrayList<>(); try (@SuppressWarnings("unchecked") final KeyedObjectPool<Object, Object> kop = createProxy(KeyedObjectPool.class, calledMethods)) { final KeyedObjectPool<Object, Object> skop = PoolUtils.synchronizedPool(kop); final List<String> expectedMethods = invokeEveryMethod(skop); assertEquals(expectedMethods, calledMethods); } // TODO: Anyone feel motivated to construct a test that verifies proper synchronization? }
/** * Constructor for OmimServices. Takes OMIM API keys from molgenis.properties and puts them in a pool. * * @param apiKeys * list of OMIM API keys from molgenis.properties */ @Autowired public OmimService(@Value("#{'${omim_key:@null}'.split(',')}") List<String> apiKeys) { // initialize a pool for OMIM keys to circulate them and protect them from over-use PooledOmimKeyFactory keyFactory = new PooledOmimKeyFactory(apiKeys); PooledObjectFactory<String> syncFactory = PoolUtils.synchronizedPooledFactory(keyFactory); GenericObjectPool<String> genericPool = new GenericObjectPool<String>(syncFactory); genericPool.setBlockWhenExhausted(true); genericPool.setLifo(false); genericPool.setMaxTotal(apiKeys.size()); pool = PoolUtils.synchronizedPool(genericPool); }
@Test public void testSynchronizedPoolObjectPool() throws Exception { try { PoolUtils.synchronizedPool((ObjectPool<Object>) null); fail("PoolUtils.synchronizedPool(ObjectPool) must not allow a null pool."); } catch (final IllegalArgumentException iae) { // expected } final List<String> calledMethods = new ArrayList<>(); try (@SuppressWarnings("unchecked") final ObjectPool<Object> op = createProxy(ObjectPool.class, calledMethods)) { final ObjectPool<Object> sop = PoolUtils.synchronizedPool(op); final List<String> expectedMethods = invokeEveryMethod(sop); assertEquals(expectedMethods, calledMethods); // TODO: Anyone feel motivated to construct a test that verifies proper synchronization? } }
private void initPool() { if (dispatcherPool == null) { // TODO EVENT Some of these pool configuration // parameters can live in dspace.cfg or a // separate configuration file // TODO EVENT Eviction parameters should be set poolConfig = new GenericKeyedObjectPoolConfig(); poolConfig.setMaxTotalPerKey(100); poolConfig.setMaxIdlePerKey(5); poolConfig.setMaxTotal(100); try { dispatcherFactory = new DispatcherPoolFactory(); dispatcherPool = PoolUtils .synchronizedPool(new GenericKeyedObjectPool( dispatcherFactory, poolConfig)); enumerateConsumers(); } catch (Exception e) { log.error("Could not initialize EventService dispatcher pool", e); } } }