List of usage examples for org.apache.commons.pool.impl GenericKeyedObjectPool GenericKeyedObjectPool
public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive)
GenericKeyedObjectPool
using the specified values. From source file:com.smartwork.client.gsocket.CommonSocketPool.java
/** * Create a new <code>CommonSocketPool</code> using the specified values. * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects * if not <code>null</code>// w w w . j a v a2 s . co m * @param config a non-<code>null</code> {@link CommonSocketPool.Config} describing the configuration */ public CommonSocketPool(NetworkConfig networkConfig, GenericKeyedObjectPool.Config config) { pool = new GenericKeyedObjectPool(new CommonSocketFactory(networkConfig), config); }
From source file:com.btmatthews.atlas.jcr.impl.PooledSessionFactory.java
public PooledSessionFactory(final KeyedPoolableObjectFactory<String, Session> factory, GenericKeyedObjectPool.Config config) { objectPool = new GenericKeyedObjectPool<String, Session>(factory, config); }
From source file:com.seajas.search.contender.scripting.ScriptCache.java
/** * Default constructor.// w w w . j ava2 s. co m * * @param maximumEntries */ @Autowired public ScriptCache( @Value("${contender.project.script.cache.maximum.entries.per.script} ") final Integer maximumEntries) { pool = new GenericKeyedObjectPool<ModifierScript, ScriptCacheEntry>( new BaseKeyedPoolableObjectFactory<ModifierScript, ScriptCacheEntry>() { /** * {@inheritDoc} */ @Override public ScriptCacheEntry makeObject(final ModifierScript script) throws Exception { ScriptEngine engine = engineManager .getEngineByName(script.getScriptLanguage().toLowerCase()); if (engine instanceof Compilable) { CompiledScript compiledScript = ((Compilable) engine) .compile(script.getScriptContent()); return new ScriptCacheEntry(script.getModificationDate(), compiledScript); } else throw new Exception( String.format("The given script with ID %d of type %s cannot be compiled", script.getId(), script.getScriptLanguage())); } /** * {@inheritDoc} */ @Override public boolean validateObject(final ModifierScript script, final ScriptCacheEntry entry) { boolean result = entry.getModificationDate().equals(script.getModificationDate()); if (logger.isTraceEnabled()) logger.trace(String.format( (result ? "I" : "Not i") + "nvalidating pool entry for ID %d - modification date has changed", script.getId())); return result; } }, maximumEntries); pool.setMaxIdle(maximumEntries); pool.setTestOnBorrow(true); pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK); }
From source file:com.baifendian.swordfish.common.hive.service2.HiveService2Client.java
/** * hive //from w w w . j a v a 2 s.c om * * @return */ protected GenericKeyedObjectPool bulidClientPool() { GenericKeyedObjectPool.Config poolConfig = new GenericKeyedObjectPool.Config(); poolConfig.maxActive = maxActive; poolConfig.maxIdle = maxIdle; poolConfig.minIdle = minIdle; poolConfig.maxWait = maxWait; poolConfig.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; poolConfig.testWhileIdle = testWhileIdle; poolConfig.testOnBorrow = true; poolConfig.testOnReturn = true; HiveService2PoolFactory clientFactory = new HiveService2PoolFactory(); return new GenericKeyedObjectPool(clientFactory, poolConfig); }
From source file:ch.epfl.eagle.daemon.util.ThriftClientPool.java
public ThriftClientPool(MakerFactory<T> maker) { pool = new GenericKeyedObjectPool<InetSocketAddress, T>(new PoolFactory(maker), getPoolConfig()); try {/*w ww . j a v a 2 s. com*/ clientManager = new TAsyncClientManager(); } catch (IOException e) { LOG.fatal(e); } }
From source file:com.bfd.harpc.config.ClientConfig.java
/** * client/*from w ww . j av a2 s.c o m*/ * <p> * * @param classLoader * @param ifaceClass * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException */ @SuppressWarnings("unchecked") protected GenericKeyedObjectPool<ServerNode, T> bulidClientPool(ClassLoader classLoader, Class<?> ifaceClass) throws ClassNotFoundException, InstantiationException, IllegalAccessException { // poolConfig GenericKeyedObjectPool.Config poolConfig = new GenericKeyedObjectPool.Config(); poolConfig.maxActive = maxActive; poolConfig.maxIdle = maxIdle; poolConfig.minIdle = minIdle; poolConfig.maxWait = maxWait; poolConfig.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; poolConfig.testWhileIdle = testWhileIdle; if (StringUtils.equalsIgnoreCase(protocol, "thrift")) { // Client.Factory Class<TServiceClientFactory<TServiceClient>> fi = (Class<TServiceClientFactory<TServiceClient>>) classLoader .loadClass(findOutClassName() + "$Client$Factory"); TServiceClientFactory<TServiceClient> clientFactory = fi.newInstance(); TServiceClientPoolFactory<T> clientPool = new TServiceClientPoolFactory<T>(clientFactory, timeout); return new GenericKeyedObjectPool<ServerNode, T>(clientPool, poolConfig); } else if (StringUtils.equalsIgnoreCase(protocol, "avro")) { AvroClientPoolFactory<T> clientPool = new AvroClientPoolFactory<T>(timeout, ifaceClass); return new GenericKeyedObjectPool<ServerNode, T>(clientPool, poolConfig); } else { throw new RpcException(RpcException.CONFIG_EXCEPTION, "Unsupport protocal,please check the params 'protocal'!"); } }
From source file:com.servoy.extensions.plugins.rest_ws.RestWSPlugin.java
synchronized KeyedObjectPool getClientPool() { if (clientPool == null) { byte exchaustedAction; int poolSize; if (ApplicationServerRegistry.get().isDeveloperStartup()) { // in developer multiple clients do not work well with debugger poolSize = 1;/* w w w .j av a2s . co m*/ exchaustedAction = GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK; } else { try { poolSize = Integer.parseInt(application.getSettings() .getProperty(CLIENT_POOL_SIZE_PROPERTY, "" + CLIENT_POOL_SIZE_DEFAULT).trim()); } catch (NumberFormatException nfe) { poolSize = CLIENT_POOL_SIZE_DEFAULT; } String exchaustedActionCode = application.getSettings() .getProperty(CLIENT_POOL_EXCHAUSTED_ACTION_PROPERTY); if (exchaustedActionCode != null) exchaustedActionCode = exchaustedActionCode.trim(); if (ACTION_FAIL.equalsIgnoreCase(exchaustedActionCode)) { exchaustedAction = GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL; if (log.isDebugEnabled()) log.debug("Client pool, exchaustedAction=" + ACTION_FAIL); } else if (ACTION_GROW.equalsIgnoreCase(exchaustedActionCode)) { exchaustedAction = GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW; if (log.isDebugEnabled()) log.debug("Client pool, exchaustedAction=" + ACTION_GROW); } else { exchaustedAction = GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK; if (log.isDebugEnabled()) log.debug("Client pool, exchaustedAction=" + ACTION_BLOCK); } } if (log.isDebugEnabled()) log.debug("Creating client pool, maxSize=" + poolSize); clientPool = new GenericKeyedObjectPool(new BaseKeyedPoolableObjectFactory() { @Override public Object makeObject(Object key) throws Exception { if (log.isDebugEnabled()) log.debug("creating new session client for solution '" + key + '\''); String solutionName = (String) key; String[] solOpenArgs = SOLUTION_OPEN_METHOD_ARGS; String[] arr = solutionName.split(":"); if (arr.length == 2) { solutionName = arr[0]; solOpenArgs = Utils.arrayJoin(SOLUTION_OPEN_METHOD_ARGS, new String[] { "nodebug" }); } return HeadlessClientFactory.createHeadlessClient(solutionName, solOpenArgs); } @Override public boolean validateObject(Object key, Object obj) { IHeadlessClient client = ((IHeadlessClient) obj); if (client.getPluginAccess().isInDeveloper()) { String solutionName = (String) key; if (solutionName.contains(":")) solutionName = solutionName.split(":")[0]; if (!solutionName.equals(((IHeadlessClient) obj).getPluginAccess().getSolutionName())) { try { client.closeSolution(true); client.loadSolution(solutionName); } catch (Exception ex) { return false; } } } boolean valid = client.isValid(); if (log.isDebugEnabled()) log.debug("Validated session client for solution '" + key + "', valid = " + valid); return valid; } @Override public void destroyObject(Object key, Object obj) throws Exception { if (log.isDebugEnabled()) log.debug("Destroying session client for solution '" + key + "'"); IHeadlessClient client = ((IHeadlessClient) obj); try { client.shutDown(true); } catch (Exception e) { Debug.error(e); } } }, poolSize); clientPool.setTestOnBorrow(true); clientPool.setWhenExhaustedAction(exchaustedAction); clientPool.setMaxIdle(poolSize); // destroy objects when pool has grown } return clientPool; }
From source file:org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.java
/** * Create the {@link org.apache.commons.pool.KeyedObjectPool}, pooling * the {@link PersistenceBroker} instances - override this method to * implement your own pool and {@link org.apache.commons.pool.KeyedPoolableObjectFactory}. */// w ww . j a v a 2s . c om private GenericKeyedObjectPool createPool() { GenericKeyedObjectPool.Config conf = poolConfig.getKeyedObjectPoolConfig(); if (log.isDebugEnabled()) log.debug("PersistenceBroker pool will be setup with the following configuration " + ToStringBuilder.reflectionToString(conf, ToStringStyle.MULTI_LINE_STYLE)); GenericKeyedObjectPool pool = new GenericKeyedObjectPool(null, conf); pool.setFactory(new PersistenceBrokerFactoryDefaultImpl.PBKeyedPoolableObjectFactory(this, pool)); return pool; }
From source file:org.dspace.event.EventManager.java
private static 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 GenericKeyedObjectPool.Config(); poolConfig.maxActive = 100;//from ww w . jav a 2s . co m poolConfig.maxIdle = 5; poolConfig.maxTotal = 100; try { dispatcherFactory = new DispatcherPoolFactory(); dispatcherPool = PoolUtils .synchronizedPool(new GenericKeyedObjectPool(dispatcherFactory, poolConfig)); enumerateConsumers(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:org.mule.security.oauth.BaseOAuth2Manager.java
@Override public final void initialise() throws InitialisationException { super.initialise(); GenericKeyedObjectPool.Config config = new GenericKeyedObjectPool.Config(); config.testOnBorrow = true;// w w w . ja v a 2 s . com if (this.accessTokenObjectStore == null) { this.accessTokenObjectStore = muleContext.getRegistry() .lookupObject(MuleProperties.DEFAULT_USER_OBJECT_STORE_NAME); if (this.accessTokenObjectStore == null) { throw new InitialisationException(CoreMessages .createStaticMessage("There is no default user object store on this Mule instance."), this); } } this.accessTokenPoolFactory = this.createPoolFactory(this, this.accessTokenObjectStore); this.accessTokenPool = new GenericKeyedObjectPool<String, OAuth2Adapter>(accessTokenPoolFactory, config); if (defaultUnauthorizedConnector instanceof Initialisable) { ((Initialisable) defaultUnauthorizedConnector).initialise(); } if (this.httpUtil == null) { this.httpUtil = new HttpUtilImpl(); } if (this.oauthResponseParser == null) { this.oauthResponseParser = new DefaultOAuthResponseParser(); } if (this.refreshTokenManager == null) { try { this.refreshTokenManager = this.muleContext.getRegistry().lookupObject(RefreshTokenManager.class); } catch (RegistrationException e) { throw new InitialisationException(e, this); } } }