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


Java KeyedPooledObjectFactory类代码示例

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


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

示例1: initialize

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
/**
 * Lifecycle method. Initializes the pool using the supplied KeyedPooledObjectFactory and the configuration.
 * @param factory
 * @param configuration
 * @throws java.lang.IllegalStateException if the pool instance has already been initialized.
 */
public static void initialize(KeyedPooledObjectFactory<APNSConnectionKey, APNSConnection> factory,
    GenericKeyedObjectPoolConfig configuration) {
  if (initialized.get()) {
    throw new IllegalStateException("Can't initialize multiple times");
  }
  instance.connectionPool = new GenericKeyedObjectPool<APNSConnectionKey, APNSConnection>(
      factory, configuration);
  instance.connectionPool.setMaxWaitMillis(1000L * getIntProperty(
      MMXConfigKeys.APNS_POOL_WAIT_SECONDS,
      MMXServerConstants.APNS_POOL_WAIT_SECONDS));
  initialized.set(true);
  LOGGER.info("APNS Connection pool is initialized");
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:20,代码来源:APNSConnectionPoolImpl.java

示例2: GenericKeyedObjectPool

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
/**
 * Create a new <code>GenericKeyedObjectPool</code> using a specific
 * configuration.
 *
 * @param factory the factory to be used to create entries
 * @param config    The configuration to use for this pool instance. The
 *                  configuration is used by value. Subsequent changes to
 *                  the configuration object will not be reflected in the
 *                  pool.
 */
public GenericKeyedObjectPool(final KeyedPooledObjectFactory<K,T> factory,
        final GenericKeyedObjectPoolConfig config) {

    super(config, ONAME_BASE, config.getJmxNamePrefix());

    if (factory == null) {
        jmxUnregister(); // tidy up
        throw new IllegalArgumentException("factory may not be null");
    }
    this.factory = factory;
    this.fairness = config.getFairness();

    setConfig(config);

    startEvictor(getTimeBetweenEvictionRunsMillis());
}
 
开发者ID:apache,项目名称:commons-pool,代码行数:27,代码来源:GenericKeyedObjectPool.java

示例3: initPool

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
private void initPool(KeyedPooledObjectFactory<K, T> factory, final GenericKeyedObjectPoolConfig config) {

		if (this.internalPool != null) {
			try {
				closeInternalPool();
			} catch (Exception e) {/**/}
		}
		this.internalPool = new GenericKeyedObjectPool<K, T>(factory, config);
	}
 
开发者ID:adohe,项目名称:jSocketPool,代码行数:10,代码来源:KeyedPool.java

示例4: setUp

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
@Before
public void setUp() {
    final GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
    config.setMaxTotal(3);

    final KeyedPooledObjectFactory<String, TestObject> factory =
            new TestKeyedObjectFactory();

    final KeyedObjectPool<String,TestObject> innerPool =
            new GenericKeyedObjectPool<>(
                    factory, config);

    pool = new ProxiedKeyedObjectPool<>(innerPool, getproxySource());
}
 
开发者ID:apache,项目名称:commons-pool,代码行数:15,代码来源:BaseTestProxiedKeyedObjectPool.java

示例5: makeEmptyPool

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
@Override
protected KeyedObjectPool<Object,Object> makeEmptyPool(final int mincapacity) {
    final KeyedPooledObjectFactory<Object,Object> perKeyFactory =
            new SimplePerKeyFactory();
    final GenericKeyedObjectPool<Object,Object> perKeyPool =
        new GenericKeyedObjectPool<>(perKeyFactory);
    perKeyPool.setMaxTotalPerKey(mincapacity);
    perKeyPool.setMaxIdlePerKey(mincapacity);
    return perKeyPool;
}
 
开发者ID:apache,项目名称:commons-pool,代码行数:11,代码来源:TestGenericKeyedObjectPool.java

示例6: FdfsKeyedObjectPool

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
public FdfsKeyedObjectPool(KeyedPooledObjectFactory<InetSocketAddress, T> factory,
        GenericKeyedObjectPoolConfig config) {

    super(factory, config);

    if (config.getTestWhileIdle()
            && config.getTimeBetweenEvictionRunsMillis() != GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS
            && config.getTimeBetweenEvictionRunsMillis() < config.getMinEvictableIdleTimeMillis()) {

        this.setTimeBetweenEvictionRunsMillis(config.getTimeBetweenEvictionRunsMillis());
    }
}
 
开发者ID:fanyunfeng,项目名称:jfdfslib,代码行数:13,代码来源:FdfsKeyedObjectPool.java

示例7: initConnectionsPool

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
public void initConnectionsPool() {
    if (this.connectionsPool == null) {
        final GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
        poolConfig.setJmxEnabled(false);
        this.connectionsPool = new GenericKeyedObjectPool<PooledConnectionKey, PooledConnection>(
            new KeyedPooledObjectFactory<PooledConnectionKey, PooledConnection>() {
                @Override
                public PooledObject<PooledConnection> makeObject(PooledConnectionKey connectionKey) throws Exception {
                    Connection delegate = createProviderConnection(connectionKey);

                    PooledConnection connection = createPooledConnection(delegate);
                    connection.setIdleTimeout(getIdleTimeout());
                    connection.setExpiryTimeout(getExpiryTimeout());
                    connection.setMaximumActiveSessionPerConnection(getMaximumActiveSessionPerConnection());
                    connection.setBlockIfSessionPoolIsFull(isBlockIfSessionPoolIsFull());
                    if (isBlockIfSessionPoolIsFull() && getBlockIfSessionPoolIsFullTimeout() > 0) {
                        connection.setBlockIfSessionPoolIsFullTimeout(getBlockIfSessionPoolIsFullTimeout());
                    }
                    connection.setUseAnonymousProducers(isUseAnonymousProducers());
                    connection.setReconnectOnException(isReconnectOnException());

                    LOG.trace("Created new connection: {}", connection);

                    JmsPoolConnectionFactory.this.mostRecentlyCreated.set(connection);

                    return new DefaultPooledObject<PooledConnection>(connection);
                }

                @Override
                public void destroyObject(PooledConnectionKey connectionKey, PooledObject<PooledConnection> pooledObject) throws Exception {
                    PooledConnection connection = pooledObject.getObject();
                    try {
                        LOG.trace("Destroying connection: {}", connection);
                        connection.close();
                    } catch (Exception e) {
                        LOG.warn("Close connection failed for connection: " + connection + ". This exception will be ignored.",e);
                    }
                }

                @Override
                public boolean validateObject(PooledConnectionKey connectionKey, PooledObject<PooledConnection> pooledObject) {
                    PooledConnection connection = pooledObject.getObject();
                    if (connection != null && connection.expiredCheck()) {
                        LOG.trace("Connection has expired: {} and will be destroyed", connection);
                        return false;
                    }

                    return true;
                }

                @Override
                public void activateObject(PooledConnectionKey connectionKey, PooledObject<PooledConnection> pooledObject) throws Exception {
                }

                @Override
                public void passivateObject(PooledConnectionKey connectionKey, PooledObject<PooledConnection> pooledObject) throws Exception {
                }

            }, poolConfig);

        // Set max idle (not max active) since our connections always idle in the pool.
        this.connectionsPool.setMaxIdlePerKey(DEFAULT_MAX_CONNECTIONS);
        this.connectionsPool.setLifo(false);

        // We always want our validate method to control when idle objects are evicted.
        this.connectionsPool.setTestOnBorrow(true);
        this.connectionsPool.setTestWhileIdle(true);
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:70,代码来源:JmsPoolConnectionFactory.java

示例8: DefaultThriftConnectionPool

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
public DefaultThriftConnectionPool(KeyedPooledObjectFactory<ThriftServer, TTransport> factory, GenericKeyedObjectPoolConfig config) {
	connections = new GenericKeyedObjectPool<>(factory, config);
}
 
开发者ID:cyfonly,项目名称:ThriftJ,代码行数:4,代码来源:DefaultThriftConnectionPool.java

示例9: ConnectionPool

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
/**
 * 默认构造函数
 */
public ConnectionPool(KeyedPooledObjectFactory<InetSocketAddress, Connection> factory, GenericKeyedObjectPoolConfig config) {
    super(factory, config);
}
 
开发者ID:Lzw2016,项目名称:fastdfs-java-client,代码行数:7,代码来源:ConnectionPool.java

示例10: HBaseKeyedResourcePoolDefault

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
public HBaseKeyedResourcePoolDefault(final KeyedPooledObjectFactory<K, R> factory, final GenericKeyedObjectPoolConfig config) {
    super(factory, config);
}
 
开发者ID:LiaisonTechnologies,项目名称:shachi,代码行数:4,代码来源:HBaseKeyedResourcePoolDefault.java

示例11: WhereClauseListenerPool

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
public WhereClauseListenerPool(KeyedPooledObjectFactory<String, WhereClauseListener> factory)
{
    super(factory);
}
 
开发者ID:daedafusion,项目名称:knowledge,代码行数:5,代码来源:WhereClauseListenerPool.java

示例12: testConstructors

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
@Test(timeout=60000)
public void testConstructors() throws Exception {

    // Make constructor arguments all different from defaults
    final int maxTotalPerKey = 1;
    final int minIdle = 2;
    final long maxWait = 3;
    final int maxIdle = 4;
    final int maxTotal = 5;
    final long minEvictableIdleTimeMillis = 6;
    final int numTestsPerEvictionRun = 7;
    final boolean testOnBorrow = true;
    final boolean testOnReturn = true;
    final boolean testWhileIdle = true;
    final long timeBetweenEvictionRunsMillis = 8;
    final boolean blockWhenExhausted = false;
    final boolean lifo = false;
    final KeyedPooledObjectFactory<Object, Object> dummyFactory = new DummyFactory();

    try (GenericKeyedObjectPool<Object, Object> objPool = new GenericKeyedObjectPool<>(dummyFactory)) {
        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY, objPool.getMaxTotalPerKey());
        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY, objPool.getMaxIdlePerKey());
        assertEquals(BaseObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS, objPool.getMaxWaitMillis());
        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE_PER_KEY, objPool.getMinIdlePerKey());
        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, objPool.getMaxTotal());
        assertEquals(BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                objPool.getMinEvictableIdleTimeMillis());
        assertEquals(BaseObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, objPool.getNumTestsPerEvictionRun());
        assertEquals(Boolean.valueOf(BaseObjectPoolConfig.DEFAULT_TEST_ON_BORROW),
                Boolean.valueOf(objPool.getTestOnBorrow()));
        assertEquals(Boolean.valueOf(BaseObjectPoolConfig.DEFAULT_TEST_ON_RETURN),
                Boolean.valueOf(objPool.getTestOnReturn()));
        assertEquals(Boolean.valueOf(BaseObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE),
                Boolean.valueOf(objPool.getTestWhileIdle()));
        assertEquals(BaseObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                objPool.getTimeBetweenEvictionRunsMillis());
        assertEquals(Boolean.valueOf(BaseObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED),
                Boolean.valueOf(objPool.getBlockWhenExhausted()));
        assertEquals(Boolean.valueOf(BaseObjectPoolConfig.DEFAULT_LIFO), Boolean.valueOf(objPool.getLifo()));
    }

    final GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
    config.setLifo(lifo);
    config.setMaxTotalPerKey(maxTotalPerKey);
    config.setMaxIdlePerKey(maxIdle);
    config.setMinIdlePerKey(minIdle);
    config.setMaxTotal(maxTotal);
    config.setMaxWaitMillis(maxWait);
    config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    config.setTestOnBorrow(testOnBorrow);
    config.setTestOnReturn(testOnReturn);
    config.setTestWhileIdle(testWhileIdle);
    config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    config.setBlockWhenExhausted(blockWhenExhausted);
    try (GenericKeyedObjectPool<Object, Object> objPool = new GenericKeyedObjectPool<>(dummyFactory, config)) {
        assertEquals(maxTotalPerKey, objPool.getMaxTotalPerKey());
        assertEquals(maxIdle, objPool.getMaxIdlePerKey());
        assertEquals(maxWait, objPool.getMaxWaitMillis());
        assertEquals(minIdle, objPool.getMinIdlePerKey());
        assertEquals(maxTotal, objPool.getMaxTotal());
        assertEquals(minEvictableIdleTimeMillis, objPool.getMinEvictableIdleTimeMillis());
        assertEquals(numTestsPerEvictionRun, objPool.getNumTestsPerEvictionRun());
        assertEquals(Boolean.valueOf(testOnBorrow), Boolean.valueOf(objPool.getTestOnBorrow()));
        assertEquals(Boolean.valueOf(testOnReturn), Boolean.valueOf(objPool.getTestOnReturn()));
        assertEquals(Boolean.valueOf(testWhileIdle), Boolean.valueOf(objPool.getTestWhileIdle()));
        assertEquals(timeBetweenEvictionRunsMillis, objPool.getTimeBetweenEvictionRunsMillis());
        assertEquals(Boolean.valueOf(blockWhenExhausted), Boolean.valueOf(objPool.getBlockWhenExhausted()));
        assertEquals(Boolean.valueOf(lifo), Boolean.valueOf(objPool.getLifo()));
    }
}
 
开发者ID:apache,项目名称:commons-pool,代码行数:72,代码来源:TestGenericKeyedObjectPool.java

示例13: FdfsConnectionPool

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
/**
 * 默认构造函数
 * 
 * @param factory
 * @param config
 */
@Autowired
public FdfsConnectionPool(KeyedPooledObjectFactory<InetSocketAddress, Connection> factory,
        GenericKeyedObjectPoolConfig config) {
    super(factory, config);
}
 
开发者ID:whatodo,项目名称:FastDFS_Client,代码行数:12,代码来源:FdfsConnectionPool.java

示例14: KeyedPool

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
/**
 * @param factory
 * @param config
 */
public KeyedPool(KeyedPooledObjectFactory<K, T> factory, final GenericKeyedObjectPoolConfig config) {
	initPool(factory, config);
}
 
开发者ID:adohe,项目名称:jSocketPool,代码行数:8,代码来源:KeyedPool.java

示例15: getFactory

import org.apache.commons.pool2.KeyedPooledObjectFactory; //导入依赖的package包/类
/**
 * Obtain a reference to the factory used to create, destroy and validate
 * the objects used by this pool.
 *
 * @return the factory
 */
public KeyedPooledObjectFactory<K, T> getFactory() {
    return factory;
}
 
开发者ID:apache,项目名称:commons-pool,代码行数:10,代码来源:GenericKeyedObjectPool.java


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