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


Java GenericObjectPool类代码示例

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


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

示例1: JedisPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public JedisPool(final String host) {
	URI uri = URI.create(host);
	if (JedisURIHelper.isValid(uri)) {
		String h = uri.getHost();
		int port = uri.getPort();
		String password = JedisURIHelper.getPassword(uri);
		int database = JedisURIHelper.getDBIndex(uri);
		boolean ssl = uri.getScheme().equals("rediss");
		this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(h, port, Protocol.DEFAULT_TIMEOUT,
				Protocol.DEFAULT_TIMEOUT, password, database, null, ssl, null, null, null),
				new GenericObjectPoolConfig());
	} else {
		this.internalPool = new GenericObjectPool<Jedis>(
				new JedisFactory(host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT,
						null, Protocol.DEFAULT_DATABASE, null, false, null, null, null),
				new GenericObjectPoolConfig());
	}
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:19,代码来源:JedisPool.java

示例2: JaRedisPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public JaRedisPool(final String host) {
    URI uri = URI.create(host);
    if (JedisURIHelper.isValid(uri)) {
        String h = uri.getHost();
        int port = uri.getPort();
        String password = JedisURIHelper.getPassword(uri);
        int database = JedisURIHelper.getDBIndex(uri);
        this.internalPool = new GenericObjectPool<>(new JaRedisFactory(h, port,
                Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null),
                new GenericObjectPoolConfig());
    } else {
        this.internalPool = new GenericObjectPool<>(new JaRedisFactory(host,
                Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
                Protocol.DEFAULT_DATABASE, null), new GenericObjectPoolConfig());
    }
}
 
开发者ID:YanXs,项目名称:nighthawk,代码行数:17,代码来源:JaRedisPool.java

示例3: DrawGuess

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
@Autowired
public DrawGuess(ApplicationContext context,
                 ApiResponseFactory apiResponseFactory, DrawWordMapper mapper) {
    this.apiResponsePool = new GenericObjectPool<>(apiResponseFactory);
    this.mapper = mapper;
    HashMap<Integer, RequestHandler> handlers = new HashMap<>();
    String[] beans = context.getBeanNamesForAnnotation(DrawGuessEventHandler.class);
    for (String bean : beans) {
        RequestHandler handler = context.getBean(bean, RequestHandler.class);
        DrawGuessEventHandler annotation = handler.getClass().getAnnotation(DrawGuessEventHandler.class);
        DrawCode[] value = annotation.value();
        for (DrawCode drawCode : value) {
            handlers.put(drawCode.getCode(), handler);
        }
    }
    setRequestHandlers(handlers);
}
 
开发者ID:csdbianhua,项目名称:telemarket-skittle-alley,代码行数:18,代码来源:DrawGuess.java

示例4: DefaultSessionPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public DefaultSessionPool(final ConnectionService connect, final X509TrustManager trust, final X509KeyManager key,
                          final VaultRegistry registry, final Cache<Path> cache, final TranscriptListener transcript,
                          final Host bookmark) {
    this.connect = connect;
    this.registry = registry;
    this.cache = cache;
    this.bookmark = bookmark;
    this.transcript = transcript;
    final GenericObjectPoolConfig configuration = new GenericObjectPoolConfig();
    configuration.setJmxEnabled(false);
    configuration.setEvictionPolicyClassName(CustomPoolEvictionPolicy.class.getName());
    configuration.setBlockWhenExhausted(true);
    configuration.setMaxWaitMillis(BORROW_MAX_WAIT_INTERVAL);
    this.pool = new GenericObjectPool<Session>(new PooledSessionFactory(connect, trust, key, cache, bookmark, registry), configuration);
    final AbandonedConfig abandon = new AbandonedConfig();
    abandon.setUseUsageTracking(true);
    this.pool.setAbandonedConfig(abandon);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:19,代码来源:DefaultSessionPool.java

示例5: JedisPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public JedisPool(final String host) {
  URI uri = URI.create(host);
  if (JedisURIHelper.isValid(uri)) {
    String h = uri.getHost();
    int port = uri.getPort();
    String password = JedisURIHelper.getPassword(uri);
    int database = JedisURIHelper.getDBIndex(uri);
    this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(h, port,
        Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null),
        new GenericObjectPoolConfig());
  } else {
    this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(host,
        Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
        Protocol.DEFAULT_DATABASE, null), new GenericObjectPoolConfig());
  }
}
 
开发者ID:x7-framework,项目名称:x7,代码行数:17,代码来源:JedisPool.java

示例6: setupObjectPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
@Override
public void setupObjectPool() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(poolSize);

    objectPool = new GenericObjectPool<>(new BasePooledObjectFactory<TestObject>() {
        @Override
        public TestObject create() throws Exception {
            return new TestObject(true);
        }

        @Override
        public PooledObject<TestObject> wrap(TestObject testObject) {
            return new DefaultPooledObject<>(testObject);
        }
    }, config);
}
 
开发者ID:chrishantha,项目名称:microbenchmarks,代码行数:18,代码来源:CommonsPool2GenericObjectPoolBenchmark.java

示例7: ensureClient

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
protected synchronized void ensureClient() throws SQLException {
    if (client == null) {
        ClientConfiguration clientConfiguration = new ClientConfiguration(properties);
        LOGGER.log(Level.SEVERE, "Booting HerdDB Client, url:" + url + ", properties:" + properties + " clientConfig " + clientConfiguration);
        clientConfiguration.readJdbcUrl(url);
        client = new HDBClient(clientConfiguration);
    }
    if (pool == null) {
        if (properties.containsKey("maxActive")) {
            this.maxActive = Integer.parseInt(properties.get("maxActive").toString());
        }
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        config.setBlockWhenExhausted(true);
        config.setMaxTotal(maxActive);
        config.setMaxIdle(maxActive);
        config.setMinIdle(maxActive / 2);
        config.setJmxNamePrefix("HerdDBClient");
        pool = new GenericObjectPool<>(new ConnectionsFactory(), config);
    }
}
 
开发者ID:diennea,项目名称:herddb,代码行数:21,代码来源:BasicHerdDBDataSource.java

示例8: setPoolConfig

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
@Override
public void setPoolConfig(String host, int port, int timeout, int maxPoolSize, GenericObjectPool<Jedis> pool) {
	this.host = host;
	this.port = port;

	// System.err.println("setPoolConfig host:" + host + " port:" + port + " maxPoolSize:" + maxPoolSize);
	connectionInfo = new ConnectionInfo();
	connectionInfo.setPort(port);
	connectionInfo.setHost(host);// 是否要解析成IP?
	connectionInfo.setMaxPoolSize(maxPoolSize);

	connectionInfo.setContent("");
	connectionInfo.setType("Redis");

	connectionInfo.setPool(pool);

	connectionMonitorService.add(connectionInfo);
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:19,代码来源:RedisConnectionListenerImpl.java

示例9: getSocketPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public static SocketPool getSocketPool(String host , int port) {
	String key = host+":"+port;
	SocketPool pool = socketPoolMap.get(key);
	if(pool==null) {
		lock.lock();
		pool = socketPoolMap.get(key);
		if(pool==null) {
			pool = new SocketPool(host,port);
			GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
			poolConfig.setMaxTotal(10);
			GenericObjectPool<SocketConnection> objectPool = new GenericObjectPool<SocketConnection>(pool,poolConfig);
			
			pool.setObjectPool(objectPool);
			
			socketPoolMap.put(key, pool);
		}
		lock.unlock();
	}
	return pool;
}
 
开发者ID:beijing-penguin,项目名称:raft-java,代码行数:21,代码来源:RaftUtils.java

示例10: build

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
@SuppressWarnings("unused")
public RethinkDBPool build() {
    ConnectionFactory factory = new ConnectionFactory(hostname, port, username, password, database);


    GenericObjectPoolConfig config = this.config;
    if (config == null) {
        config = new GenericObjectPoolConfig();
        config.setMaxTotal(maxConnections);
        config.setMinIdle(minFreeConnections);
        config.setMaxIdle(maxFreeConnections);
    }

    GenericObjectPool<Connection> pool = new GenericObjectPool<>(factory, config);
    return new RethinkDBPool(pool, timeout);
}
 
开发者ID:foxylion,项目名称:rethinkdb-orm-java,代码行数:17,代码来源:RethinkDBPoolBuilder.java

示例11: JedisPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public JedisPool(final String host) {
  URI uri = URI.create(host);
  if (JedisURIHelper.isValid(uri)) {
    String h = uri.getHost();
    int port = uri.getPort();
    String password = JedisURIHelper.getPassword(uri);
    int database = JedisURIHelper.getDBIndex(uri);
    this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(h, port,
        Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null),
        new GenericObjectPoolConfig());
    this.host = h;
    this.port = port;
  } else {
    this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(host,
        Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
        Protocol.DEFAULT_DATABASE, null), new GenericObjectPoolConfig());
      this.host = host;
      this.port = Protocol.DEFAULT_PORT;
  }
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:21,代码来源:JedisPool.java

示例12: start

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
/**
 * This can be overriden to set pool size and borrow timeout
 * for each start/restart.
 * The super method must be called at the end of the overriding method.
 * @throws Exception
 */
public synchronized void start() throws Exception {
    if (pool==null) {
        pool = new GenericObjectPool<PooledConnection>(new MDWPoolFactory());
    }
    pool.setMaxTotal(pool_size);
    if (borrow_timeout<0) {
        pool.setBlockWhenExhausted(true);
        pool.setMaxWaitMillis(-1);
    } else if (borrow_timeout==0) {
        pool.setBlockWhenExhausted(false);
        pool.setMaxWaitMillis(0);
    } else {
        pool.setBlockWhenExhausted(true);
        pool.setMaxWaitMillis(borrow_timeout*1000);
    }
    setStarted(true);
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:24,代码来源:MDWConnectionPool.java

示例13: createPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
private ObjectPool<PoolableConnection> createPool(String connectionString) {
    // A ConnectionFactory that the pool will use to create Connections.
    ConnectionFactory connectionFactory =
            new DriverManagerConnectionFactory(connectionString, null);
    // PoolableConnectionFactory wraps the real Connections with the
    // classes that implement the pooling functionality.
    PoolableConnectionFactory poolableConnectionFactory =
            new PoolableConnectionFactory(connectionFactory, null);
    poolableConnectionFactory.setValidationQuery("SELECT 1");

    // Actual pool of connections.
    GenericObjectPool<PoolableConnection> connectionPool =
            new GenericObjectPool<>(poolableConnectionFactory);
    int connMax = getConfig()
            .getInt(OctopusConfiguration.MASTER_CONNECTION_POOL_MAX, 8);
    connectionPool.setMaxTotal(connMax);
    connectionPool.setTestOnBorrow(true);
    // Set the factory's pool property to the owning pool.
    poolableConnectionFactory.setPool(connectionPool);

    return connectionPool;
}
 
开发者ID:bitnine-oss,项目名称:octopus,代码行数:23,代码来源:ConnectionManager.java

示例14: initLocalBroker

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
private void initLocalBroker() throws ProvisioningException {
	if (this.isInternalQueue()) {
		this.broker = BrokerHolder.getInstance( cfgMgr, "local",this);
		
	} else {
		this.mpPool = new GenericObjectPool<MessageProducerHolder>(new PooledMessageProducerFactory(this.cfgMgr,this));
		this.mpPool.setMaxTotal(this.cfgMgr.getCfg().getProvisioning().getQueueConfig().getMaxProducers());
		this.cfgMgr.addThread(new StopableThread() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void stop() {
				mpPool.close();
				mpPool.clear();
				
			}
			
		});
	}
}
 
开发者ID:TremoloSecurity,项目名称:OpenUnison,代码行数:26,代码来源:ProvisioningEngineImpl.java

示例15: check

import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
@Override
protected Result check() throws Exception {

	GenericObjectPool<PoolableConnection> pool = (GenericObjectPool<PoolableConnection>) connectionPool;
	if (pool.getNumWaiters() > maxWaitingConnections) {
		return Result.unhealthy("Overloaded connection pool.  name="
				+ poolName + " nbrWaiters=" + pool.getNumWaiters());
	}

	PoolableConnectionFactory poolFactory = (PoolableConnectionFactory) pool
			.getFactory();
	PoolableConnection conn = null;
	try {
		conn = pool.borrowObject();
		poolFactory.validateConnection(conn);
	} catch (Exception e) {
		return Result
				.unhealthy("Database connection validation error.  error="
						+ ExceptionUtils.getStackTrace(e));
	} finally {
		DbUtils.closeQuietly(conn);
	}

	return Result.healthy();
}
 
开发者ID:Derek-Ashmore,项目名称:moneta,代码行数:26,代码来源:DbcpConnectionPoolHealthCheck.java


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