List of usage examples for org.apache.commons.pool.impl StackObjectPool StackObjectPool
public StackObjectPool(final PoolableObjectFactory factory, final int maxIdle, final int initIdleCapacity)
From source file:com.github.chrishantha.microbenchmark.objectpool.StackObjectPoolBenchmark.java
@Override public void setupObjectPool() { objectPool = new StackObjectPool<>(new BasePoolableObjectFactory<TestObject>() { @Override/*from w w w.j av a2 s .c om*/ public TestObject makeObject() throws Exception { return new TestObject(true); } }, poolSize, poolSize); }
From source file:gov.nih.nci.firebird.proxy.PoolingHandler.java
/** * use a StackObjectPool./*from www .j a v a 2 s . c o m*/ * @param factory - the PoolableObjectFactory used to populate the pool * @param maxIdle - cap on the number of "sleeping" instances in the pool * @param initIdleCapacity - initial size of the pool (this specifies the size of the container, * it does not cause the pool to be pre-populated.) */ public PoolingHandler(PoolableObjectFactory<Object> factory, int maxIdle, int initIdleCapacity) { this(new StackObjectPool<Object>(factory, maxIdle, initIdleCapacity)); }
From source file:de.escidoc.core.common.business.fedora.FedoraUtility.java
/** * See Interface for functional description. * //from w w w .j av a 2 s . co m * @see InitializingBean #afterPropertiesSet() */ @Override public void afterPropertiesSet() throws IOException, MalformedURLException, ServiceException { this.fedoraClientPool = new StackObjectPool( PoolUtils.synchronizedPoolableFactory(new BasePoolableObjectFactory() { /** * See Interface for functional description. * * @return * @see BasePoolableObjectFactory #makeObject() */ @Override public Object makeObject() throws MalformedURLException { return new FedoraClient(FedoraUtility.this.fedoraUrl, FedoraUtility.this.fedoraUser, FedoraUtility.this.fedoraPassword); } }), MAX_IDLE, INIT_IDLE_CAPACITY); this.apiaPool = new StackObjectPool(PoolUtils.synchronizedPoolableFactory(new BasePoolableObjectFactory() { /** * See Interface for functional description. * * @return * @see BasePoolableObjectFactory #makeObject() */ @Override public Object makeObject() throws IOException, MalformedURLException, ServiceException { return new FedoraClient(FedoraUtility.this.fedoraUrl, FedoraUtility.this.fedoraUser, FedoraUtility.this.fedoraPassword).getAPIA(); } }), MAX_IDLE, INIT_IDLE_CAPACITY); this.apimPool = new StackObjectPool(new BasePoolableObjectFactory() { /** * See Interface for functional description. * * @return * @see BasePoolableObjectFactory #makeObject() */ @Override public Object makeObject() throws IOException, MalformedURLException, ServiceException { return new FedoraClient(FedoraUtility.this.fedoraUrl, FedoraUtility.this.fedoraUser, FedoraUtility.this.fedoraPassword).getAPIM(); } }, MAX_IDLE, INIT_IDLE_CAPACITY); this.syncRestQuery = this.fedoraUrl + "/risearch?flush=true"; }
From source file:org.codelabor.system.remoting.tcp.factories.SocketPoolTest.java
@Test public void testStackObjectPool() throws Exception { SocketPoolFactory socketPoolFactory = new SocketPoolFactory(); socketPoolFactory.setHost("localhost"); socketPoolFactory.setPort(8080);// w w w . j a va 2s . c o m StackObjectPool socketPool = new StackObjectPool(socketPoolFactory, 10, 5); Socket sockets[] = new Socket[10]; for (int i = 0; i < 10; i++) { sockets[i] = (Socket) socketPool.borrowObject(); System.out.println("borrowObject: " + sockets[i].hashCode()); System.out.println("active: " + socketPool.getNumActive() + ", idle: " + socketPool.getNumIdle()); } for (int i = 0; i < 10; i++) { System.out.println("returnbject: " + sockets[i].hashCode()); socketPool.returnObject(sockets[i]); sockets[i] = null; System.out.println("active: " + socketPool.getNumActive() + ", idle: " + socketPool.getNumIdle()); } // while (true) { // Thread.sleep(1000); // System.out.println("active: " + socketPool.getNumActive() // + ", idle: " + socketPool.getNumIdle()); // } }
From source file:org.mule.transport.amqp.AmqpConnector.java
public AmqpConnector(final MuleContext context) { super(context); receiveTransformer = new AmqpMessageToObject(); receiveTransformer.setMuleContext(context); final int maxIdle = 1; final int initIdleCapacity = 0; connectorConnectionPool = new StackObjectPool(new ConnectorConnectionPoolableObjectFactory(this), maxIdle, initIdleCapacity);/*w ww . j a v a 2 s . co m*/ }
From source file:org.opencms.db.jpa.CmsSqlManager.java
/** * Initialize the static part of the class.<p> * /*from ww w . j a v a2 s. c o m*/ * @param config the combined configuration of "opencms.properties" and the "persistence.xml" */ public static void init(CmsParameterConfiguration config) { if (!m_isInitialized) { m_isInitialized = true; String connProps = buildConnectionPropertiesValue(config, CmsDbPool.OPENCMS_DEFAULT_POOL_NAME); Properties systemProps = System.getProperties(); systemProps.setProperty(CmsPersistenceUnitConfiguration.ATTR_CONNECTION_PROPERTIES, connProps); m_persistenceFactory = Persistence.createEntityManagerFactory(JPA_PERSISTENCE_UNIT, systemProps); m_factoryTable.put(JPA_PERSISTENCE_UNIT, m_persistenceFactory); CmsPoolEntityManagerFactory entityMan = new CmsPoolEntityManagerFactory(m_persistenceFactory); int entityManagerPoolSize = config.getInteger(CmsDbPool.KEY_DATABASE_POOL + "." + CmsDbPool.OPENCMS_DEFAULT_POOL_NAME + "." + CmsDbPool.KEY_ENTITY_MANAGER_POOL_SIZE, DEFAULT_ENTITY_MANAGER_POOL_SIZE); m_openCmsEmPool = new StackObjectPool(entityMan, entityManagerPoolSize, 0); } }
From source file:org.wso2.carbon.apimgt.gateway.handlers.security.keys.APIKeyValidatorClientPool.java
private APIKeyValidatorClientPool() { String maxIdleClients = ServiceReferenceHolder.getInstance().getAPIManagerConfiguration() .getFirstProperty("APIKeyValidator.ConnectionPool.MaxIdle"); String initIdleCapacity = ServiceReferenceHolder.getInstance().getAPIManagerConfiguration() .getFirstProperty("APIKeyValidator.ConnectionPool.InitIdleCapacity"); int initIdleCapSize; if (StringUtils.isNotEmpty(maxIdleClients)) { maxIdle = Integer.parseInt(maxIdleClients); } else {//ww w .j av a 2s . co m maxIdle = 50; } if (StringUtils.isNotEmpty(initIdleCapacity)) { initIdleCapSize = Integer.parseInt(initIdleCapacity); } else { initIdleCapSize = 20; } log.debug("Initializing API key validator client pool"); clientPool = new StackObjectPool(new BasePoolableObjectFactory() { @Override public Object makeObject() throws Exception { log.debug("Initializing new APIKeyValidatorClient instance"); return new APIKeyValidatorClient(); } }, maxIdle, initIdleCapSize); }
From source file:org.wso2.carbon.apimgt.gateway.handlers.security.thrift.ThriftKeyValidatorClientPool.java
private ThriftKeyValidatorClientPool() { log.debug("Initializing thrift key validator client pool"); clientPool = new StackObjectPool(new BasePoolableObjectFactory() { @Override/* w w w . ja v a 2s . c o m*/ public Object makeObject() throws Exception { log.debug("Initializing new ThriftKeyValidatorClient instance"); return new ThriftKeyValidatorClient(); } }, 50, 20); }
From source file:org.wso2.carbon.apimgt.gateway.throttling.publisher.ThrottleDataPublisherPool.java
private ThrottleDataPublisherPool() { //Using stack object pool to handle high concurrency scenarios without droping any messages. //Tuning this pool is mandatory according to use cases. //A finite number of "sleeping" or idle instances is enforced, but when the pool is empty, new instances // are created to support the new load. Hence this following data stricture places no limit on the number of " // active" instance created by the pool, but is quite useful for re-using Objects without introducing // artificial limits. //Proper tuning is mandatory for good performance according to system load. ThrottleProperties.DataPublisherPool dataPublisherPoolConfiguration = ServiceReferenceHolder.getInstance() .getThrottleProperties().getDataPublisherPool(); clientPool = new StackObjectPool(new BasePoolableObjectFactory() { @Override/*w ww . j a v a 2 s. c om*/ public Object makeObject() throws Exception { if (log.isDebugEnabled()) { log.debug("Initializing new ThrottleDataPublisher instance"); } return new DataProcessAndPublishingAgent(); } }, dataPublisherPoolConfiguration.getMaxIdle(), dataPublisherPoolConfiguration.getInitIdleCapacity()); }
From source file:org.wso2.carbon.apimgt.keymgt.client.SubscriberKeyMgtClientPool.java
private SubscriberKeyMgtClientPool() { log.debug("Initializing API Key Management Client Pool"); clientPool = new StackObjectPool(new BasePoolableObjectFactory() { @Override//from ww w. j av a 2 s .co m public Object makeObject() throws Exception { log.debug("Initializing new SubscriberKeyMgtClient instance"); return new SubscriberKeyMgtClient(serverURL, username, password); } }, 20, 5); }