当前位置: 首页>>代码示例>>Java>>正文


Java KeyedObjectPool类代码示例

本文整理汇总了Java中org.apache.commons.pool.KeyedObjectPool的典型用法代码示例。如果您正苦于以下问题:Java KeyedObjectPool类的具体用法?Java KeyedObjectPool怎么用?Java KeyedObjectPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeyedObjectPool类属于org.apache.commons.pool包,在下文中一共展示了KeyedObjectPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPoolWithNullFactory

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
public void testPoolWithNullFactory() throws Exception {
    KeyedObjectPool pool = new StackKeyedObjectPool(10);
    for(int i=0;i<10;i++) {
        pool.returnObject("X",new Integer(i));
    }
    for(int j=0;j<3;j++) {
        Integer[] borrowed = new Integer[10];
        BitSet found = new BitSet();
        for(int i=0;i<10;i++) {
            borrowed[i] = (Integer)(pool.borrowObject("X"));
            assertNotNull(borrowed);
            assertTrue(!found.get(borrowed[i].intValue()));
            found.set(borrowed[i].intValue());
        }
        for(int i=0;i<10;i++) {
            pool.returnObject("X",borrowed[i]);
        }
    }
    pool.invalidateObject("X",pool.borrowObject("X"));
    pool.invalidateObject("X",pool.borrowObject("X"));
    pool.clear("X");
    pool.clear();
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:24,代码来源:TestStackKeyedObjectPool.java

示例2: openCache

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
public V openCache(K key) throws KeyedCacheException {
	V result = null;
	try {
		KeyedObjectPool<K, V> keyedObjectPool = keyedObjectPoolHolder.get();
		if (keyedObjectPool == null) {
			keyedObjectPool = keyedObjectPoolFactory.createPool();
			keyedObjectPoolHolder.set(keyedObjectPool);
		}
		//
		result = keyedObjectPool.borrowObject(key);
	} catch (Exception ex) {
		throw new KeyedCacheException("Could not open Cache", ex);
	}
	return result;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:16,代码来源:KeyedCacheFactorySupporter.java

示例3: closeCache

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
public void closeCache(K key, V obj) {
	try {
		KeyedObjectPool<K, V> keyedObjectPool = keyedObjectPoolHolder.get();
		keyedObjectPoolHolder.set(null);
		if (keyedObjectPool != null) {
			//
			keyedObjectPool.returnObject(key, obj);
		}
	} catch (Exception ex) {
		throw new KeyedCacheException("Could not close Cache", ex);
	}
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:13,代码来源:KeyedCacheFactorySupporter.java

示例4: wrapConnection

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
protected PreparedStatementCachingConnection wrapConnection(Connection realConnection) {
	// can't initialize the following variable in the constructor because the prepared statement cache size won't be available
	if (_stmtPoolFactory == null) {
		_stmtPoolFactory = createStatementPoolFactory();
	}
	
       KeyedObjectPool stmtpool = _stmtPoolFactory.createPool();
       PreparedStatementCachingConnection wrappedConnection = new PreparedStatementCachingConnection(realConnection, stmtpool);
       
       stmtpool.setFactory(wrappedConnection);
       return wrappedConnection;
}
 
开发者ID:kuali,项目名称:rice,代码行数:13,代码来源:RiceXADataSource.java

示例5: PoolablePreparedStatement

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
/**
 * Constructor
 * @param stmt my underlying {@link PreparedStatement}
 * @param key my key" as used by {@link KeyedObjectPool}
 * @param pool the {@link KeyedObjectPool} from which I was obtained.
 * @param conn the {@link Connection} from which I was created
 */
public PoolablePreparedStatement(PreparedStatement stmt, Object key, KeyedObjectPool pool, Connection conn) {
    super((DelegatingConnection) conn, stmt);
    _pool = pool;
    _key = key;

    // Remove from trace now because this statement will be 
    // added by the activate method.
    if(_conn != null) {
        _conn.removeTrace(this);
    }
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:19,代码来源:PoolablePreparedStatement.java

示例6: PooledConnectionImpl

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
/**
 * Wrap the real connection.
 * @param connection the connection to be wrapped
 * @param pool the pool to use
 */
PooledConnectionImpl(Connection connection, KeyedObjectPool pool) {
    this.connection = connection;
    if (connection instanceof DelegatingConnection) {
        this.delegatingConnection = (DelegatingConnection) connection;
    } else {
        this.delegatingConnection = new DelegatingConnection(connection);
    }
    eventListeners = new Vector();
    isClosed = false;
    if (pool != null) {
        pstmtPool = pool;
        pstmtPool.setFactory(this);            
    }
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:20,代码来源:PooledConnectionImpl.java

示例7: PoolableCallableStatement

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @param stmt the underlying {@link CallableStatement}
 * @param key the key for this statement in the {@link KeyedObjectPool}
 * @param pool the {@link KeyedObjectPool} from which this CallableStatement was obtained
 * @param conn the {@link Connection} that created this CallableStatement
 */
public PoolableCallableStatement(CallableStatement stmt, Object key, KeyedObjectPool pool, Connection conn) {
    super((DelegatingConnection)conn, stmt);
    _pool = pool;
    _key = key;

    // Remove from trace now because this statement will be 
    // added by the activate method.
    if(_conn != null) {
        _conn.removeTrace(this);
    }
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:20,代码来源:PoolableCallableStatement.java

示例8: makeObject

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
public Object makeObject() throws Exception {
    Connection conn = _connFactory.createConnection();
    if (conn == null) {
        throw new IllegalStateException("Connection factory returned null from createConnection");
    }
    initializeConnection(conn);
    if(null != _stmtPoolFactory) {
        KeyedObjectPool stmtpool = _stmtPoolFactory.createPool();
        conn = new PoolingConnection(conn,stmtpool);
        stmtpool.setFactory((PoolingConnection)conn);
    }
    return new PoolableConnection(conn,_pool,_config);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:14,代码来源:PoolableConnectionFactory.java

示例9: testBorrowFromEmptyPoolWithNullFactory

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
public void testBorrowFromEmptyPoolWithNullFactory() throws Exception {
    KeyedObjectPool pool = new StackKeyedObjectPool();
    try {
        pool.borrowObject("x");
        fail("Expected NoSuchElementException");
    } catch(NoSuchElementException e) {
        // expected
    }
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:10,代码来源:TestStackKeyedObjectPool.java

示例10: testSetFactory

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
public void testSetFactory() throws Exception {
    KeyedObjectPool pool = new StackKeyedObjectPool();
    try {
        pool.borrowObject("x");
        fail("Expected NoSuchElementException");
    } catch(NoSuchElementException e) {
        // expected
    }
    pool.setFactory(new SimpleFactory());
    Object obj = pool.borrowObject("x");
    assertNotNull(obj);
    pool.returnObject("x",obj);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:14,代码来源:TestStackKeyedObjectPool.java

示例11: testCantResetFactoryWithActiveObjects

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
public void testCantResetFactoryWithActiveObjects() throws Exception {
    KeyedObjectPool pool = new StackKeyedObjectPool();
    pool.setFactory(new SimpleFactory());
    Object obj = pool.borrowObject("x");
    assertNotNull(obj);

    try {
        pool.setFactory(new SimpleFactory());
        fail("Expected IllegalStateException");
    } catch(IllegalStateException e) {
        // expected
    }
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:14,代码来源:TestStackKeyedObjectPool.java

示例12: DelegatingContext

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
/**
 * Create a new delegating context for the specified pool, context and context type.
 * 
 * @param keyedObjectPool The pool the delegate context was checked out from.
 * @param delegateContext The context to delegate operations to.
 * @param dirContextType The type of context, used as a key for the pool.
 * @throws IllegalArgumentException if any of the arguments are null
 */
public DelegatingContext(KeyedObjectPool keyedObjectPool, Context delegateContext, DirContextType dirContextType) {
    Assert.notNull(keyedObjectPool, "keyedObjectPool may not be null");
    Assert.notNull(delegateContext, "delegateContext may not be null");
    Assert.notNull(dirContextType, "dirContextType may not be null");
    
    this.keyedObjectPool = keyedObjectPool;
    this.delegateContext = delegateContext;
    this.dirContextType = dirContextType;
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:18,代码来源:DelegatingContext.java

示例13: setUp

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    contextMock = mock(Context.class);
    dirContextMock = mock(DirContext.class);
    ldapContextMock = mock(LdapContext.class);
    keyedObjectPoolMock = mock(KeyedObjectPool.class);
    contextSourceMock = mock(ContextSource.class);
    dirContextValidatorMock = mock(DirContextValidator.class);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:10,代码来源:AbstractPoolTestCase.java

示例14: PoolablePersistenceBroker

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
public PoolablePersistenceBroker(PersistenceBrokerInternal broker, KeyedObjectPool pool)
{
    super(broker);
    this.pool = pool;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:6,代码来源:PoolablePersistenceBroker.java

示例15: PBKeyedPoolableObjectFactory

import org.apache.commons.pool.KeyedObjectPool; //导入依赖的package包/类
public PBKeyedPoolableObjectFactory(PersistenceBrokerFactoryDefaultImpl pbf, KeyedObjectPool pool)
{
    this.pbf = pbf;
    this.pool = pool;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:6,代码来源:PersistenceBrokerFactoryDefaultImpl.java


注:本文中的org.apache.commons.pool.KeyedObjectPool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。