Java源码示例:org.apache.commons.pool.PoolableObjectFactory
示例1
/**
* Constructor that accepts the type of pool, the connector, and the capacity
*
* @param capacity
* @param cxn
* @param type
*/
public ResourceQueue(int capacity, Connector cxn, byte type) {
Preconditions.checkNotNull(cxn);
Preconditions.checkArgument(capacity > 0);
this.type = type;
PoolableObjectFactory<AccumuloResource> factory = new AccumuloResourceFactory(cxn);
this.scannerPool = new GenericObjectPool<AccumuloResource>(factory);
// set the max capacity
this.scannerPool.setMaxActive(capacity);
// amount of time to wait for a connection
this.scannerPool.setMaxWait(5000);
// block
this.scannerPool.setWhenExhaustedAction(type);
}
示例2
/**
* Adds the given resource factory.
* @param resourceFactory The {@link ResourceFactory} to add.
* @exception Exception error populating the pool
*/
public void addResourceFactory(
final ResourceFactory<T> resourceFactory) throws Exception {
final PoolableObjectFactory<T> factory =
new PoolableResourceFactory<T>(resourceFactory);
final GenericObjectPool<T> pool = new GenericObjectPool<T>(factory);
final int instances = resourceFactory.getInstances();
pool.setMinIdle(instances);
pool.setMaxActive(instances);
pool.setMaxIdle(instances);
pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL);
final String type = resourceFactory.getType();
pools.put(type, pool);
LOGGER.info("loading " + instances + " instance(s) of type '" + type
+ "'");
for (int i = 0; i < instances; i++) {
pool.addObject();
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("...resources loaded.");
}
}
示例3
/**
* 需要一个工厂来制造池中的对象
*/
@Override
public void setFactory(PoolableObjectFactory<FTPClient> factory)
throws IllegalStateException, UnsupportedOperationException {
}
示例4
@Autowired
public FirefoxDriverObjectPool(PoolableObjectFactory pof) {
super(pof);
}
示例5
/**
* Creates a new instance of Pool.
*
* @param poolConfig
* @param factory
*/
public Pool(final GenericObjectPool.Config poolConfig, PoolableObjectFactory factory) {
this.internalPool = new GenericObjectPool(factory, poolConfig);
}