protected void initRedisConnectionListener(JedisPoolConfig poolConfig, String host, int port, int timeout) { String className = System.getProperty(RedisConnectionListener.class.getName()); if (className == null || className.length() == 0) { return; } Class<?> clazz; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { return; } try { redisConnectionListener = (RedisConnectionListener) clazz.newInstance(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } int maxActive = ((JedisPoolConfig) poolConfig).getMaxTotal(); // GenericObjectPool<Jedis> pool = this.getInternalPool(); redisConnectionListener.setPoolConfig(host, port, timeout, maxActive, super.internalPool); }
/** * Configures Jedis pool of connection. * * @param config * * @return configured Jedis pool of connection. */ static JedisPoolConfig configurePool(RedisConfiguration config) { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(Integer.parseInt(config.poolSize)); poolConfig.setMaxIdle(Math.min(poolConfig.getMaxIdle(), poolConfig.getMaxTotal())); poolConfig.setMinIdle(Math.min(poolConfig.getMinIdle(), poolConfig.getMaxIdle())); return poolConfig; }
((JedisPoolConfig)params.get(PropName.jedisPoolConfig)).getMaxTotal());
/** * Initialize the Redis connection pool */ private static void initializePool() { config.setMaxTotal(CMBProperties.getInstance().getRedisConnectionsMaxTotal()); config.setMaxIdle(-1); List<JedisShardInfo> shardInfos = new LinkedList<JedisShardInfo>(); String serverList = CMBProperties.getInstance().getRedisServerList(); if (serverList == null) { throw new RuntimeException("Redis server list not specified"); } String []arr = serverList.split(","); for (int i = 0; i < arr.length; i++) { String []hostPort = arr[i].trim().split(":"); JedisShardInfo shardInfo = null; if (hostPort.length != 2) { // use Redis default port if one wasn't specified shardInfo = new JedisShardInfo(hostPort[0].trim(), 6379, 4000); } else { shardInfo = new JedisShardInfo(hostPort[0].trim(), Integer.parseInt(hostPort[1].trim()), 4000); } shardInfos.add(shardInfo); } pool = new ShardedJedisPool(config, shardInfos); executor = Executors.newFixedThreadPool(CMBProperties.getInstance().getRedisFillerThreads()); logger.info("event=initialize_redis pools_size=" + shardInfos.size() + " max_total=" + config.getMaxTotal() + " server_list=" + serverList); }
private JedisPoolConfig checkPoolConfig() { JedisPoolConfig poolConfig = new JedisPoolConfig(); if (poolConfig.getMaxTotal() == 0) { poolConfig.setMaxTotal(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL); } if (poolConfig.getMinIdle() == 0) { poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MIN_IDLE); } if (poolConfig.getMaxWaitMillis() == 0) { poolConfig.setMaxWaitMillis(GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS); } return poolConfig; }
/** * Initialize the Redis connection pool */ private static void initializePool() { cfg.setMaxTotal(CMBProperties.getInstance().getRedisConnectionsMaxTotal()); cfg.setMaxIdle(-1); List<JedisShardInfo> shardInfos = new LinkedList<JedisShardInfo>(); String serverList = CMBProperties.getInstance().getRedisServerList(); if (serverList == null) { throw new RuntimeException("Redis server list not specified"); } String []arr = serverList.split(","); for (int i = 0; i < arr.length; i++) { String []hostPort = arr[i].trim().split(":"); JedisShardInfo shardInfo = null; if (hostPort.length != 2) { // use Redis default port if one wasn't specified shardInfo = new JedisShardInfo(hostPort[0].trim(), 6379, 4000); } else { shardInfo = new JedisShardInfo(hostPort[0].trim(), Integer.parseInt(hostPort[1].trim()), 4000); } shardInfos.add(shardInfo); } pool = new ShardedJedisPool(cfg, shardInfos); executor = Executors.newFixedThreadPool(CMBProperties.getInstance().getRedisFillerThreads()); revisibilityExecutor = Executors.newFixedThreadPool(CMBProperties.getInstance().getRedisRevisibleThreads()); logger.info("event=initialize_redis pools_size=" + shardInfos.size() + " max_total=" + cfg.getMaxTotal() + " server_list=" + serverList); }