当前位置: 首页>>代码示例>>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;未经允许,请勿转载。