本文整理汇总了Java中org.apache.commons.pool.PoolableObjectFactory类的典型用法代码示例。如果您正苦于以下问题:Java PoolableObjectFactory类的具体用法?Java PoolableObjectFactory怎么用?Java PoolableObjectFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PoolableObjectFactory类属于org.apache.commons.pool包,在下文中一共展示了PoolableObjectFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: useBundleClasses
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
@Override
protected void useBundleClasses() throws Exception
{
new LdapNetworkConnection().close();
new SaslGssApiRequest();
new Krb5LoginConfiguration();
new AddFuture( new LdapNetworkConnection(), 2 );
new LdapConnectionTemplate( new LdapConnectionPool( new DefaultPoolableLdapConnectionFactory(
new LdapConnectionConfig() ) ) );
FilterBuilder.and( FilterBuilder.not( FilterBuilder.contains( "cn", "a", "b" ) ) ).toString();
// Test for DIRAPI-239
PoolableObjectFactory<LdapConnection> factory = new DefaultPoolableLdapConnectionFactory(
new LdapConnectionConfig() );
Config config = new Config();
LdapConnectionPool ldapConnectionPool = new LdapConnectionPool( factory, config );
ldapConnectionPool.getLdapApiService();
ldapConnectionPool.getTestOnBorrow();
}
示例2: DirContextPool
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
/**
* Er zeugt einen neuen Connectionpool.
*
* @param factory Die {@link PoolableObjectFactory}, die zum Erzeugen des Pools verwendet werden soll.
* @param uri Die URI, die für die Verbindungen im Pool verwendet soll.
* @param maxActive Die Zahl der maximal aktiven Verbindungen.
* @param maxIdle Die Zahl der maximalen Idle-Verbindungen.
* @param minIdle Die minimale Zahl der Idle-Verbindungen.
* @param whenExhaustedAction -
* @param maxWait -
* @param timeBetweenEvictionRuns -
* @param minEvictableIdleTime -
*/
public DirContextPool( PoolableObjectFactory<InitialDirContext> factory,
String uri,
int maxActive,
int maxIdle,
int minIdle,
byte whenExhaustedAction,
int maxWait,
long timeBetweenEvictionRuns,
long minEvictableIdleTime) {
super(factory);
setMaxActive(maxActive);
setMaxIdle(maxIdle);
setMinIdle(minIdle);
setWhenExhaustedAction(whenExhaustedAction);
setMaxWait(maxWait);
setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns);
setMinEvictableIdleTimeMillis(minEvictableIdleTime);
setTestOnBorrow(false);
setTestOnReturn(true);
setTestWhileIdle(false);
this.uri = uri;
}
示例3: setUp
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
protected void setUp() throws Exception {
mockFactory = new Mock(PoolableObjectFactory.class);
factory = (PoolableObjectFactory)mockFactory.proxy();
pool = new GenericObjectPool(factory,
1, // maxActive
GenericObjectPool.WHEN_EXHAUSTED_BLOCK, // whenExhaustedAction
60000, // maxWait (millis)
1, // maxIdle
true, // testOnBorrow
false // testOnReturn
);
super.setUp();
}
示例4: getConnection
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
public synchronized Connection getConnection(String nodeId) throws Exception {
GenericObjectPool<Connection> pool = poolMap.get(nodeId);
if (pool == null) {
PoolableObjectFactory<Connection> factory =
new SocketPoolFactory(nodeId, bufferSize, timeout);
pool = new GenericObjectPool<Connection>(factory);
pool.setMaxActive(maxActive);
pool.setMaxIdle(maxIdle);
pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
poolMap.put(nodeId, pool);
}
Connection con = pool.borrowObject();
con.setSoTimeout(timeout);
return con;
}
示例5: setFactory
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
/**
* Sets the {@link PoolableObjectFactory factory} this pool uses
* to create new instances. Trying to change
* the <code>factory</code> while there are borrowed objects will
* throw an {@link IllegalStateException}. If there are instances idle
* in the pool when this method is invoked, these will be destroyed
* using the original factory.
*
* @param factory the {@link PoolableObjectFactory} used to create new instances.
* @throws IllegalStateException when the factory cannot be set at this time
* @deprecated to be removed in version 2.0
*/
public void setFactory(PoolableObjectFactory factory) throws IllegalStateException {
List toDestroy = new ArrayList();
final PoolableObjectFactory oldFactory = _factory;
synchronized (this) {
assertOpen();
if(0 < getNumActive()) {
throw new IllegalStateException("Objects are already active");
} else {
toDestroy.addAll(_pool);
_numInternalProcessing = _numInternalProcessing + _pool._size;
_pool.clear();
}
_factory = factory;
}
destroy(toDestroy, oldFactory);
}
示例6: getNext
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
/**
* ��ȡ��һ��������������Ϣ ������ѯ��ʽ
*
* @return
*/
public synchronized PoolableObjectFactory getNext() {
if (currentConnectionIndex > factorys.size() - 1) {
currentConnectionIndex = 0;
}
PoolableObjectFactory temp = factorys.get(currentConnectionIndex);
currentConnectionIndex++;
return temp;
}
示例7: validateConnectionFactory
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
protected void validateConnectionFactory(PoolableObjectFactory<TTransport> poolableFactory) throws Exception {
TTransport ttransport = null;
try {
ttransport = poolableFactory.makeObject();
poolableFactory.activateObject(ttransport);
poolableFactory.passivateObject(ttransport);
} finally {
poolableFactory.destroyObject(ttransport);
}
}
示例8: setUpBeforeClass
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
pool = new SoftReferenceObjectPool<Object>(new PoolableObjectFactory<Object>() {
int counter;
public Object makeObject() throws Exception {
return String.valueOf(counter++);
}
@Override
public void destroyObject(Object paramT) throws Exception {
// TODO Auto-generated method stub
}
@Override
public boolean validateObject(Object paramT) {
return true;
}
@Override
public void activateObject(Object paramT) throws Exception {
// TODO Auto-generated method stub
}
@Override
public void passivateObject(Object paramT) throws Exception {
// TODO Auto-generated method stub
}
});
}
示例9: createConnectionPool
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
/**
* Create the pool for pooling the connections of the given connection descriptor.
* Override this method to implement your on {@link org.apache.commons.pool.ObjectPool}.
*/
public ObjectPool createConnectionPool(JdbcConnectionDescriptor jcd)
{
if (log.isDebugEnabled()) log.debug("createPool was called");
PoolableObjectFactory pof = new ConPoolFactory(this, jcd);
GenericObjectPool.Config conf = jcd.getConnectionPoolDescriptor().getObjectPoolConfig();
return (ObjectPool)new GenericObjectPool(pof, conf);
}
示例10: MemcachedConnectionsRoundRobinPool
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
public MemcachedConnectionsRoundRobinPool(PoolableObjectFactory factory,
int size, int timeBetweenKeepAliveRunsSecs) {
this._factory = factory;
this.size = size;
this.timeBetweenKeepAliveRunsSecs = timeBetweenKeepAliveRunsSecs;
fill();
createKeepAliveTimer();
log.info("Initialized.");
}
示例11: GenericObjectPool
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
/**
* Create a new <tt>GenericObjectPool</tt> using the specified values.
* @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
* @param config a non-<tt>null</tt> {@link GenericObjectPool.Config} describing my configuration
*/
public GenericObjectPool(PoolableObjectFactory factory, GenericObjectPool.Config config) {
this(factory, config.maxActive, config.whenExhaustedAction, config.maxWait, config.maxIdle, config.minIdle,
config.testOnBorrow, config.testOnReturn, config.timeBetweenEvictionRunsMillis,
config.numTestsPerEvictionRun, config.minEvictableIdleTimeMillis, config.testWhileIdle,
config.softMinEvictableIdleTimeMillis, config.lifo);
}
示例12: destroy
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
/**
* Private method to destroy all the objects in a collection using the
* supplied object factory. Assumes that objects in the collection are
* instances of ObjectTimestampPair and that the object instances that
* they wrap were created by the factory.
*
* @param c Collection of objects to destroy
* @param factory PoolableConnectionFactory used to destroy the objects
*/
private void destroy(Collection c, PoolableObjectFactory factory) {
for (Iterator it = c.iterator(); it.hasNext();) {
try {
factory.destroyObject(((ObjectTimestampPair)(it.next())).value);
} catch(Exception e) {
// ignore error, keep destroying the rest
} finally {
synchronized(this) {
_numInternalProcessing--;
}
allocate();
}
}
}
示例13: testInitIdleCapacityExceeded
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
/**
* Verifies that initIdleCapacity is not a hard limit, but maxIdle is.
*/
public void testInitIdleCapacityExceeded() throws Exception {
PoolableObjectFactory factory = new SimpleFactory();
ObjectPool pool = new StackObjectPool(factory, 2, 1);
pool.addObject();
pool.addObject();
assertEquals(2, pool.getNumIdle());
pool.close();
pool = new StackObjectPool(factory, 1, 2);
pool.addObject();
pool.addObject();
assertEquals(1, pool.getNumIdle());
}
示例14: FastObjectPool
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
public FastObjectPool(PoolableObjectFactory factory) {
this(factory, DEFAULT_MAX_SLEEPING, DEFAULT_INIT_SLEEPING_CAPACITY);
}
示例15: SharedSingletonObjectPool
import org.apache.commons.pool.PoolableObjectFactory; //导入依赖的package包/类
public SharedSingletonObjectPool(PoolableObjectFactory<T> factory) {
this.factory = factory;
}