本文整理汇总了Java中org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig类的典型用法代码示例。如果您正苦于以下问题:Java GenericKeyedObjectPoolConfig类的具体用法?Java GenericKeyedObjectPoolConfig怎么用?Java GenericKeyedObjectPoolConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericKeyedObjectPoolConfig类属于org.apache.commons.pool2.impl包,在下文中一共展示了GenericKeyedObjectPoolConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ClientSelector
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public ClientSelector(String servers, int loadBalance, ConnectionValidator validator, GenericKeyedObjectPoolConfig poolConfig, FailoverStrategy strategy, int connTimeout, String backupServers, int serviceLevel) {
this.failoverChecker = new FailoverChecker(validator, strategy, serviceLevel);
this.poolProvider = new DefaultThriftConnectionPool(new ThriftConnectionFactory(failoverChecker, connTimeout), poolConfig);
failoverChecker.setConnectionPool(poolProvider);
failoverChecker.setServerList(ThriftServer.parse(servers));
if (StringUtils.isNotEmpty(backupServers)) {
failoverChecker.setBackupServerList(ThriftServer.parse(backupServers));
} else{
failoverChecker.setBackupServerList(new ArrayList<ThriftServer>());
}
failoverChecker.startChecking();
}
示例2: initialize
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的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");
}
示例3: createEventPool
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
private KeyedObjectPool<Event.Type, Event> createEventPool() {
final CoreConfigure cfg = CoreConfigure.getInstance();
if (cfg.isEventPoolEnable()) {
final GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotalPerKey(cfg.getEventPoolMaxTotalPerEvent());
poolConfig.setMinIdlePerKey(cfg.getEventPoolMinIdlePerEvent());
poolConfig.setMaxIdlePerKey(cfg.getEventPoolMaxIdlePerEvent());
poolConfig.setMaxTotal(cfg.getEventPoolMaxTotal());
logger.info("enable event-pool[per-key-idle-min={};per-key-idle-max={};per-key-max={};total={};]",
cfg.getEventPoolMinIdlePerEvent(),
cfg.getEventPoolMaxIdlePerEvent(),
cfg.getEventPoolMaxTotalPerEvent(),
cfg.getEventPoolMaxTotal()
);
return new GenericKeyedObjectPool<Event.Type, Event>(new EventFactory(), poolConfig);
} else {
logger.info("disable event-pool.");
return null;
}
}
示例4: init
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
@Before
public void init() throws InterruptedException {
this.appKey = "proxytest" + NumUtil.nextNum();
ServiceFactoryTest serviceFactoryTest = new ServiceFactoryTest();
ServerArgs serverArgs = serviceFactoryTest.getServerArgs(this.appKey, "127.0.0.1", NumUtil.nextPort());
ZkRegistry zkRegistry = serviceFactoryTest.getZkRegistry();
serverArgs.setRegistrys(ImmutableList.of(zkRegistry));
ThriftServerPublisher publisher = new ThriftServerPublisher(serverArgs);
Thread thread = new Thread(publisher::init);
thread.setDaemon(true);
thread.start();
TimeUnit.MILLISECONDS.sleep(400);
poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotal(MAX_CONN);
poolConfig.setMaxTotalPerKey(MAX_CONN);
poolConfig.setMaxIdlePerKey(MAX_CONN);
poolConfig.setMinIdlePerKey(MIN_CONN);
poolConfig.setTestOnBorrow(true);
poolConfig.setMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setSoftMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setJmxEnabled(false);
}
示例5: init
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
@Before
public void init() throws InterruptedException {
ServiceFactoryTest serviceFactoryTest = new ServiceFactoryTest();
ServerArgs serverArgs = serviceFactoryTest.getServerArgs(appKey, "127.0.0.1", port);
ThriftServerPublisher publisher = new ThriftServerPublisher(serverArgs);
Thread thread = new Thread(publisher::init);
thread.setDaemon(true);
thread.start();
TimeUnit.MILLISECONDS.sleep(400);
poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotal(MAX_CONN);
poolConfig.setMaxTotalPerKey(MAX_CONN);
poolConfig.setMaxIdlePerKey(MAX_CONN);
poolConfig.setMinIdlePerKey(MIN_CONN);
poolConfig.setTestOnBorrow(true);
poolConfig.setMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setSoftMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setJmxEnabled(false);
}
示例6: getFastdfsClient
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
public static FastdfsClient getFastdfsClient(){
if (fastdfsClient == null) {
synchronized (FastdfsClient.class) {
if (fastdfsClient == null) {
try {
config = new FastdfsClientConfig(configFile);
} catch (ConfigurationException e) {
logger.warn("Load fastdfs config failed.",e);
}
int connectTimeout = config.getConnectTimeout();
int networkTimeout = config.getNetworkTimeout();
TrackerClientFactory trackerClientFactory = new TrackerClientFactory(connectTimeout, networkTimeout);
StorageClientFactory storageClientFactory = new StorageClientFactory(connectTimeout, networkTimeout);
GenericKeyedObjectPoolConfig trackerClientPoolConfig = config.getTrackerClientPoolConfig();
GenericKeyedObjectPoolConfig storageClientPoolConfig = config.getStorageClientPoolConfig();
GenericKeyedObjectPool<String,TrackerClient> trackerClientPool = new GenericKeyedObjectPool<String,TrackerClient>(trackerClientFactory, trackerClientPoolConfig);
GenericKeyedObjectPool<String,StorageClient> storageClientPool = new GenericKeyedObjectPool<String,StorageClient>(storageClientFactory, storageClientPoolConfig);
List<String> trackerAddrs = config.getTrackerAddrs();
fastdfsClient = new FastdfsClientImpl(trackerAddrs,trackerClientPool,storageClientPool);
}
}
}
return fastdfsClient;
}
示例7: test
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
@Test
public void test() {
PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(500, 500);
GenericKeyedObjectPoolConfig conf = new GenericKeyedObjectPoolConfig();
conf.setMaxTotal(20);
ConnectionPool connectionPool = new ConnectionPool(pooledConnectionFactory, conf);
Set<String> trackerSet = new HashSet<String>();
trackerSet.add("192.168.10.128:22122");
DefaultCommandExecutor connectionManager = new DefaultCommandExecutor(trackerSet, connectionPool);
connectionManager.dumpPoolInfo();
GetStorageNodeCommand command = new GetStorageNodeCommand();
StorageNode storageNode = connectionManager.execute(command);
logger.info(storageNode.toString());
connectionManager.dumpPoolInfo();
connectionPool.close();
}
示例8: getPool
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
private synchronized GenericKeyedObjectPool<String, Script> getPool() {
if (pool == null) {
GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotalPerKey(-1);
poolConfig.setMaxIdlePerKey(globalConfig.getGroovyEvaluationPoolMaxIdle());
pool = new GenericKeyedObjectPool<>(
new BaseKeyedPooledObjectFactory<String, Script>() {
@Override
public Script create(String key) throws Exception {
return createScript(key);
}
@Override
public PooledObject<Script> wrap(Script value) {
return new DefaultPooledObject<>(value);
}
},
poolConfig
);
}
return pool;
}
示例9: initializeAPNSConnectionPool
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
public void initializeAPNSConnectionPool() {
MMXConfiguration configuration = MMXConfiguration.getConfiguration();
int maxObjectsPerKey = configuration.getInt(MMXConfigKeys.APNS_POOL_MAX_CONNECTIONS_PER_APP, MMXServerConstants.APNS_POOL_MAX_CONNECTIONS_PER_APP);
int maxIdleObjectsPerKey = configuration.getInt(MMXConfigKeys.APNS_POOL_MAX_IDLE_CONNECTIONS_PER_APP, MMXServerConstants.APNS_POOL_MAX_IDLE_CONNECTIONS_PER_APP);
int ttlForIdleObjectsInMinutes = configuration.getInt(MMXConfigKeys.APNS_POOL_IDLE_TTL_MINUTES, MMXServerConstants.APNS_POOL_IDLE_TTL_MINUTES);
int maxTotal = configuration.getInt(MMXConfigKeys.APNS_POOL_MAX_TOTAL_CONNECTIONS, MMXServerConstants.APNS_POOL_MAX_TOTAL_CONNECTIONS);
Log.info("Configuring APNS Connection pool with following values: maxObjects:{}, maxObjectsPerKey:{}, " +
"maxIdleObjectsPerKey:{}, ttlForIdleObjectsInMinutes:{}", maxTotal, maxObjectsPerKey, maxIdleObjectsPerKey, ttlForIdleObjectsInMinutes);
GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
config.setMaxTotalPerKey(maxObjectsPerKey);
config.setMaxTotal(maxTotal);
config.setMaxIdlePerKey(maxIdleObjectsPerKey);
config.setMinEvictableIdleTimeMillis(ttlForIdleObjectsInMinutes * 60 * 1000L);
APNSConnectionPoolImpl.initialize(config);
}
示例10: SshPool
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
/**
* create Ssh Pool
* @param config
* @param poolConfig
*/
public SshPool(final SshConfig config,
final GenericKeyedObjectPoolConfig poolConfig) {
this.config = config;
this.pool = AccessController.doPrivileged(
new PrivilegedAction<GenericKeyedObjectPool<SshConfig, Session>>() {
@Override
public GenericKeyedObjectPool<SshConfig, Session> run() {
try {
return new GenericKeyedObjectPool<>(
new SshPoolFactory(), poolConfig);
} catch (final Exception e) {
throw new SshPoolException("could not init pool.",
e);
}
}
});
}
示例11: getColorSpacePoolConfig
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
public GenericKeyedObjectPoolConfig getColorSpacePoolConfig() {
GenericKeyedObjectPoolConfig result = new GenericKeyedObjectPoolConfig();
if (colorSpacePoolMaxTotal != null) {
result.setMaxTotal(colorSpacePoolMaxTotal);
}
if (colorSpacePoolMaxPerKey != null) {
result.setMaxTotalPerKey(colorSpacePoolMaxPerKey);
}
if (colorSpacePoolMaxIdlePerKey != null) {
result.setMaxIdlePerKey(colorSpacePoolMaxIdlePerKey);
}
if (colorSpacePoolMinIdlePerKey != null) {
result.setMinIdlePerKey(colorSpacePoolMinIdlePerKey);
}
if (colorSpacePoolMaxWait != null) {
result.setMaxWaitMillis(colorSpacePoolMaxWait);
}
if (colorSpacePoolMinEvictableIdleTime != null) {
result.setMinEvictableIdleTimeMillis(colorSpacePoolMinEvictableIdleTime);
}
if (colorSpacePoolSoftMinEvictableIdleTime != null) {
result.setSoftMinEvictableIdleTimeMillis(colorSpacePoolSoftMinEvictableIdleTime);
}
if (colorSpacePoolTimeBetweenEvictionRuns != null) {
result.setTimeBetweenEvictionRunsMillis(colorSpacePoolTimeBetweenEvictionRuns);
}
if (colorSpacePoolBlockWhenExhausted != null) {
result.setBlockWhenExhausted(colorSpacePoolBlockWhenExhausted);
}
return result;
}
示例12: getChannelPool
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
@Bean
public GenericKeyedObjectPool<ChannelSessionKey, Channel> getChannelPool(final SshConfig sshConfig) throws JSchException {
final GenericKeyedObjectPoolConfig genericKeyedObjectPoolConfig = new GenericKeyedObjectPoolConfig();
genericKeyedObjectPoolConfig.setMaxTotalPerKey(10);
genericKeyedObjectPoolConfig.setBlockWhenExhausted(true);
return new GenericKeyedObjectPool(new KeyedPooledJschChannelFactory(sshConfig.getJschBuilder().build()));
}
示例13: checkAndInit
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
private void checkAndInit() {
if (this.servers == null || StringUtils.isEmpty(this.servers)) {
throw new ValidationException("servers can not be null or empty.");
}
if (!checkLoadBalance()) {
this.loadBalance = Constant.LoadBalance.RANDOM;
}
if (this.validator == null) {
this.validator = new ConnectionValidator() {
@Override
public boolean isValid(TTransport object) {
return object.isOpen();
}
};
}
if (this.poolConfig == null) {
this.poolConfig = new GenericKeyedObjectPoolConfig();
}
if (this.failoverStrategy == null) {
this.failoverStrategy = new FailoverStrategy<>();
}
if (this.connTimeout == 0) {
this.connTimeout = DEFAULT_CONN_TIMEOUT;
}
if (!checkServiceLevel()) {
this.serviceLevel = Constant.ServiceLevel.NOT_EMPTY;
}
}
示例14: TrpcClientPoolImpl
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public TrpcClientPoolImpl(GenericKeyedObjectPoolConfig config, boolean async) {
Function<ThriftServerInfo, AbstractTrpcClient> creater;
if (async) {
creater = AsyncTrpcClient::new;
} else {
creater = BlockTrpcClient::new;
}
connections = new GenericKeyedObjectPool(new TrpcClientFactory<>(creater), config);
}
示例15: ClientArgs
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入依赖的package包/类
@Builder
public ClientArgs(GenericKeyedObjectPoolConfig poolConfig, List<AbstractMonitor> monitors, List<String> serviceInterfaces, String serviceInterface, String localAppKey, String remoteAppKey, String ipPorts, int timeout, boolean async) {
this.poolConfig = poolConfig;
this.monitors = monitors;
this.serviceInterfaces = serviceInterfaces;
this.serviceInterface = serviceInterface;
this.localAppKey = localAppKey;
this.remoteAppKey = remoteAppKey;
this.ipPorts = ipPorts;
this.timeout = timeout;
this.async = async;
afterPropertiesSet();
}