當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。