コード例 #1
0
  public static ZKPool getZkPool(String zkAddr) throws PlatformException {
    if (pools.get(zkAddr) == null) {
      synchronized (LOCK) {
        if (pools.get(zkAddr) == null) {
          GenericObjectPoolConfig config = new GenericObjectPoolConfig();
          config.setMaxTotal(total);
          config.setTestOnBorrow(false);
          config.setMinIdle(10);
          int timeOut = 2000;
          if (StringUtils.isBlank(zkAddr)) {
            throw new PlatformException(
                ZkErrorCodeConstants.NO_PARSE_ZK_INFO,
                "zkAddr can not be null,and its format is ip:port");
          }

          if (!StringUtils.isBlank(zkTimeout)) {
            timeOut = Integer.parseInt(zkTimeout);
          }

          ZKPool zkPool = new ZKPool(config, zkAddr, timeOut);
          pools.put(zkAddr, zkPool);
        }
      }
    }

    return pools.get(zkAddr);
  }
コード例 #2
0
 {
   super.setMaxIdle(6);
   super.setMaxTotal(40);
   super.setMinIdle(1);
   super.setTimeBetweenEvictionRunsMillis(1000L * 60L * 10L);
   super.setNumTestsPerEvictionRun(10);
   super.setMinEvictableIdleTimeMillis(1000L * 60L * 5L);
 }
コード例 #3
0
ファイル: JedisClusterTest.java プロジェクト: TruSphere/jedis
 @Test(expected = JedisConnectionException.class)
 public void testIfPoolConfigAppliesToClusterPools() {
   GenericObjectPoolConfig config = new GenericObjectPoolConfig();
   config.setMaxTotal(0);
   config.setMaxWaitMillis(2000);
   Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
   jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
   JedisCluster jc = new JedisCluster(jedisClusterNode, config);
   jc.set("52", "poolTestValue");
 }
コード例 #4
0
  @Test
  public void testReturnResource() {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
    assertNotNull(client);
    pool.returnResource(client);
    assertNotNull(pool.getResource());
    client.close();
  }
コード例 #5
0
  @Test
  public void testGetResourcePoolExhausted() {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
    assertNotNull(client);
    try {
      pool.getResource();
      fail("PoolException should be thrown when pool exhausted");
    } catch (PoolException e) {
    } finally {
      client.close();
    }
  }
コード例 #6
0
ファイル: Client.java プロジェクト: zhengzhiyuan/rpcframework
  public synchronized void init() {
    if (status != 0) {
      throw new RuntimeException("client has inited");
    } else {
      status = 1;
    }

    // 配置基本属性
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setTestOnBorrow(true);
    poolConfig.setJmxEnabled(true);
    poolConfig.setMaxTotal(maxTotal);
    poolConfig.setMaxIdle(maxIdle);
    poolConfig.setMinIdle(minIdle);
    poolConfig.setTimeBetweenEvictionRunsMillis(1000 * 60 * 5);
    poolConfig.setNumTestsPerEvictionRun(10);
    AbandonedConfig abandonedConfig = new AbandonedConfig();

    ConnectionPoolFactory factory = new ConnectionPoolFactory(servers, soTimeout, ioMode);
    pool = new GenericObjectPool<Connection>(factory, poolConfig, abandonedConfig);
  }
コード例 #7
0
  @Test
  public void testReturnBrokenResource() {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
    assertNotNull(client);
    pool.returnBrokenResource(client);
    RedisAsyncConnection<byte[], byte[]> client2 = pool.getResource();
    assertNotSame(client, client2);
    try {
      client.ping();
      fail("Broken resouce connection should be closed");
    } catch (RedisException e) {
    } finally {
      client.close();
      client2.close();
    }
  }