當前位置: 首頁>>代碼示例>>Java>>正文


Java GenericObjectPool.borrowObject方法代碼示例

本文整理匯總了Java中org.apache.commons.pool2.impl.GenericObjectPool.borrowObject方法的典型用法代碼示例。如果您正苦於以下問題:Java GenericObjectPool.borrowObject方法的具體用法?Java GenericObjectPool.borrowObject怎麽用?Java GenericObjectPool.borrowObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.pool2.impl.GenericObjectPool的用法示例。


在下文中一共展示了GenericObjectPool.borrowObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: send

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
@Override
public RpcResponse send(RpcRequest request) throws Exception {
	// client pool
   	GenericObjectPool<MinaClientPoolProxy> clientPool = MinaClientPool.getPool(serverAddress, request.getClassName(), serializer);
   	// client proxy
   	MinaClientPoolProxy clientPoolProxy = null;
	try {
		// future init
		RpcCallbackFuture future = new RpcCallbackFuture(request);
		RpcCallbackFuture.futurePool.put(request.getRequestId(), future);
		
		// rpc invoke
		clientPoolProxy = clientPool.borrowObject();
		clientPoolProxy.send(request);
		
		// future get
		return future.get(timeoutMillis);
	} catch (Exception e) {
		logger.error("", e);
		throw e;
	} finally{
		RpcCallbackFuture.futurePool.remove(request.getRequestId());
		clientPool.returnObject(clientPoolProxy);
	}
	
}
 
開發者ID:xuxueli,項目名稱:xxl-rpc,代碼行數:27,代碼來源:MinaClient.java

示例3: genericPoolUsingWrappingShouldPropagateExceptionsCorrectly

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
@Test
public void genericPoolUsingWrappingShouldPropagateExceptionsCorrectly() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig());

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();
    sync.set(key, value);

    try {
        sync.hgetall(key);
        fail("Missing RedisCommandExecutionException");
    } catch (RedisCommandExecutionException e) {
        assertThat(e).hasMessageContaining("WRONGTYPE");
    }

    sync.close();
    pool.close();
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:21,代碼來源:ConnectionPoolSupportTest.java

示例4: wrappedConnectionShouldUseWrappers

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
@Test
public void wrappedConnectionShouldUseWrappers() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig());

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();

    assertThat(connection).isInstanceOf(StatefulRedisConnection.class).isNotInstanceOf(
            StatefulRedisClusterConnectionImpl.class);
    assertThat(Proxy.isProxyClass(connection.getClass())).isTrue();

    assertThat(sync).isInstanceOf(RedisCommands.class);
    assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isNotInstanceOf(RedisAsyncCommandsImpl.class);
    assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isNotInstanceOf(
            RedisReactiveCommandsImpl.class);
    assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class)
            .isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection);

    sync.close();
    pool.close();
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:24,代碼來源:ConnectionPoolSupportTest.java

示例5: wrappedMasterSlaveConnectionShouldUseWrappers

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
@Test
public void wrappedMasterSlaveConnectionShouldUseWrappers() throws Exception {

    GenericObjectPool<StatefulRedisMasterSlaveConnection<String, String>> pool = ConnectionPoolSupport
            .createGenericObjectPool(() -> MasterSlave.connect(client, new StringCodec(), RedisURI.create(host, port)),
                    new GenericObjectPoolConfig());

    StatefulRedisMasterSlaveConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();

    assertThat(connection).isInstanceOf(StatefulRedisMasterSlaveConnection.class);
    assertThat(Proxy.isProxyClass(connection.getClass())).isTrue();

    assertThat(sync).isInstanceOf(RedisCommands.class);
    assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isNotInstanceOf(RedisAsyncCommandsImpl.class);
    assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isNotInstanceOf(
            RedisReactiveCommandsImpl.class);
    assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class)
            .isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection);

    sync.close();
    pool.close();
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:24,代碼來源:ConnectionPoolSupportTest.java

示例6: plainConnectionShouldNotUseWrappers

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
@Test
public void plainConnectionShouldNotUseWrappers() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig(), false);

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();

    assertThat(connection).isInstanceOf(StatefulRedisConnection.class).isNotInstanceOf(
            StatefulRedisClusterConnectionImpl.class);
    assertThat(Proxy.isProxyClass(connection.getClass())).isFalse();

    assertThat(sync).isInstanceOf(RedisCommands.class);
    assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isInstanceOf(RedisAsyncCommandsImpl.class);
    assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isInstanceOf(
            RedisReactiveCommandsImpl.class);
    assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class).isInstanceOf(
            StatefulRedisConnectionImpl.class);

    pool.returnObject(connection);
    pool.close();
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:24,代碼來源:ConnectionPoolSupportTest.java

示例7: wrappedObjectClosedAfterReturn

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
@Test
public void wrappedObjectClosedAfterReturn() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig(), true);

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();
    sync.ping();
    sync.close();

    try {
        connection.isMulti();
        fail("Missing RedisException");
    } catch (RedisException e) {
        assertThat(e).hasMessageContaining("deallocated");
    }

    pool.close();
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:21,代碼來源:ConnectionPoolSupportTest.java

示例8: tryWithResourcesReturnsConnectionToPool

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
@Test
public void tryWithResourcesReturnsConnectionToPool() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig());

    StatefulRedisConnection<String, String> usedConnection = null;
    try (StatefulRedisConnection<String, String> connection = pool.borrowObject()) {

        RedisCommands<String, String> sync = connection.sync();
        sync.ping();

        usedConnection = connection;
    }

    try {
        usedConnection.isMulti();
        fail("Missing RedisException");
    } catch (RedisException e) {
        assertThat(e).hasMessageContaining("deallocated");
    }

    pool.close();
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:25,代碼來源:ConnectionPoolSupportTest.java

示例9: testBorrow

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
@Test
public void testBorrow() throws Exception {
    GenericObjectPool<Connection> pool = new GenericObjectPool<Connection>(new ConnectionFactory());
    Connection conn = pool.borrowObject();

    Assert.assertNotNull(conn);
}
 
開發者ID:huhuics,項目名稱:tauren,代碼行數:8,代碼來源:ConnectionPoolTest.java

示例10: getHandle

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
public INaviDriver getHandle() {
    try {
        int index = random.nextInt(pools.size());
        GenericObjectPool<INaviDriver> pool = pools.get(index);
        INaviDriver handle = pool.borrowObject();
        handle.setPool(pool);

        return handle;
    } catch (Exception e) {
        throw new NaviSystemException(e.getMessage(), NaviError.SYSERROR, e);
    }
}
 
開發者ID:sunguangran,項目名稱:navi,代碼行數:13,代碼來源:DefaultNaviDataSource.java

示例11: send

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
@Override
public RpcResponse send(RpcRequest request) throws Exception {
	// client pool	[tips03 : may save 35ms/100invoke if move it to constructor, but it is necessary. cause by ConcurrentHashMap.get]
       GenericObjectPool<NettyClientPoolProxy> clientPool = NettyClientPool.getPool(serverAddress, request.getClassName(), serializer);
       
       // client proxt
       NettyClientPoolProxy clientPoolProxy = null;
	try {
		// future init	[tips04 : may save 20ms/100invoke if remove and wait for channel instead, but it is necessary. cause by ConcurrentHashMap.get]
		RpcCallbackFuture future = new RpcCallbackFuture(request);
		RpcCallbackFuture.futurePool.put(request.getRequestId(), future);
		
		// rpc invoke
		clientPoolProxy = clientPool.borrowObject();
		clientPoolProxy.send(request);
		
		// future get
		return future.get(timeoutMillis);
	} catch (Exception e) {
		logger.error("", e);
		throw e;
	} finally{
		RpcCallbackFuture.futurePool.remove(request.getRequestId());
		clientPool.returnObject(clientPoolProxy);
	}
	
}
 
開發者ID:xuxueli,項目名稱:xxl-rpc,代碼行數:28,代碼來源:NettyClient.java

示例12: borrowClient

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
private HttpClient borrowClient() {
    GenericObjectPool<HttpClient> objectPool = createObjectPool();
    HttpClient httpClient;
    try {
        httpClient = objectPool.borrowObject(borrowMaxWaitMillis);
    } catch (Exception e) {
        throw new AtsdClientException("Could not borrow http client from pool", e);
    }
    return httpClient;
}
 
開發者ID:axibase,項目名稱:atsd-api-java,代碼行數:11,代碼來源:HttpClientManager.java

示例13: borrowClient

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
private TcpClient borrowClient() {
    GenericObjectPool<TcpClient> objectPool = createObjectPool();
    TcpClient tcpClient;
    try {
        tcpClient = objectPool.borrowObject(borrowMaxWaitMillis);
    } catch (Exception e) {
        throw new AtsdClientException("Could not borrow tcp client from pool", e);
    }
    return tcpClient;
}
 
開發者ID:axibase,項目名稱:atsd-api-java,代碼行數:11,代碼來源:TcpClientManager.java

示例14: TextCharDataParser

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
public TextCharDataParser(
    ProtoConfigurableEntity.Context context,
    String readerId,
    boolean collapseAllLines,
    boolean useCustomDelimiter,
    String customDelimiter,
    boolean includeCustomDelimiterInText,
    OverrunReader reader,
    long readerOffset,
    int maxObjectLen,
    String fieldTextName,
    String fieldTruncatedName,
    GenericObjectPool<StringBuilder> stringBuilderPool
) throws IOException {
  this.context = context;
  this.readerId = readerId;
  this.collapseAllLines = collapseAllLines;
  this.reader = (!collapseAllLines && useCustomDelimiter)?
      new OverrunCustomDelimiterReader(reader, maxObjectLen, customDelimiter, includeCustomDelimiterInText):
      new OverrunLineReader(reader, maxObjectLen);
  this.maxObjectLen = maxObjectLen;
  this.fieldTextName = fieldTextName;
  this.fieldTruncatedName = fieldTruncatedName;
  reader.setEnabled(false);
  IOUtils.skipFully(reader, readerOffset);
  reader.setEnabled(true);

  this.stringBuilderPool = stringBuilderPool;
  try {
    this.stringBuilder = stringBuilderPool.borrowObject();
    LOG.debug("Borrowed string builder from pool. Num Active {}, Num Idle {}", this.stringBuilderPool.getNumActive(), this.stringBuilderPool.getNumIdle());
  } catch (Exception e) {
    throw new IOException(Utils.format("Error borrowing string builder object from pool : {}", e.toString()), e);
  }

  recordIdSb = new StringBuilder(readerId.length() + 15);
  recordIdSb.append(readerId).append("::");
  recordIdOffset = recordIdSb.length();
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:40,代碼來源:TextCharDataParser.java

示例15: AutoReturnableObject

import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
public AutoReturnableObject(GenericObjectPool<T> pool) throws IOException {
  try {
    this.pool = pool;
    this.object = pool.borrowObject();
    this.returned = false;
  } catch (Exception exc) {
    throw new IOException(exc);
  }
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:10,代碼來源:AutoReturnableObject.java


注:本文中的org.apache.commons.pool2.impl.GenericObjectPool.borrowObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。