public DefaultChannelPool(// long maxIdleTime,// int maxConnectionTTL,// boolean sslConnectionPoolEnabled,// Timer nettyTimer) { this.sslConnectionPoolEnabled = sslConnectionPoolEnabled; this.maxIdleTime = maxIdleTime; this.maxConnectionTTL = maxConnectionTTL; maxConnectionTTLDisabled = maxConnectionTTL <= 0; this.nettyTimer = nettyTimer; maxIdleTimeDisabled = maxIdleTime <= 0; cleanerPeriod = Math.min(maxConnectionTTLDisabled ? Long.MAX_VALUE : maxConnectionTTL, maxIdleTimeDisabled ? Long.MAX_VALUE : maxIdleTime); if (!maxConnectionTTLDisabled || !maxIdleTimeDisabled) scheduleNewIdleChannelDetector(new IdleChannelDetector()); }
totalCount += partition.size(); List<IdleChannel> closedChannels = closeChannels(expiredChannels(partition, start));
private List<IdleChannel> expiredChannels(ConcurrentLinkedQueue<IdleChannel> partition, long now) { // lazy create List<IdleChannel> idleTimeoutChannels = null; for (IdleChannel idleChannel : partition) { if (isTTLExpired(idleChannel.channel, now) || isIdleTimeoutExpired(idleChannel, now) || !Channels.isChannelValid(idleChannel.channel)) { LOGGER.debug("Adding Candidate expired Channel {}", idleChannel.channel); if (idleTimeoutChannels == null) idleTimeoutChannels = new ArrayList<>(); idleTimeoutChannels.add(idleChannel); } } return idleTimeoutChannels != null ? idleTimeoutChannels : Collections.<IdleChannel> emptyList(); }
public void run(Timeout timeout) throws Exception { if (isClosed.get()) return; try { if (LOGGER.isDebugEnabled()) for (String key : poolsPerKey.keySet()) { LOGGER.debug("Entry count for : {} : {}", key, poolsPerKey.get(key).size()); } long start = millisTime(); int closedCount = 0; int totalCount = 0; for (ConcurrentLinkedQueue<IdleChannel> pool : poolsPerKey.values()) { // store in intermediate unsynchronized lists to minimize the impact on the ConcurrentLinkedQueue if (LOGGER.isDebugEnabled()) totalCount += pool.size(); List<IdleChannel> closedChannels = closeChannels(expiredChannels(pool, start)); pool.removeAll(closedChannels); int poolClosedCount = closedChannels.size(); closedCount += poolClosedCount; } long duration = millisTime() - start; LOGGER.debug("Closed {} connections out of {} in {}ms", closedCount, totalCount, duration); } catch (Throwable t) { LOGGER.error("uncaught exception!", t); } scheduleNewIdleChannelDetector(timeout.getTask()); } }
private final List<IdleChannel> closeChannels(List<IdleChannel> candidates) { // lazy create, only if we have a non-closeable channel List<IdleChannel> closedChannels = null; for (int i = 0; i < candidates.size(); i++) { IdleChannel idleChannel = candidates.get(i); if (!isChannelCloseable(idleChannel.channel)) if (closedChannels == null) { // first non closeable to be skipped, copy all previously skipped closeable channels closedChannels = new ArrayList<IdleChannel>(candidates.size()); for (int j = 0; j < i; j++) closedChannels.add(candidates.get(j)); } else { LOGGER.debug("Closing Idle Channel {}", idleChannel.channel); close(idleChannel.channel); if (closedChannels != null) { closedChannels.add(idleChannel); } } } return closedChannels != null ? closedChannels : candidates; }
private List<IdleChannel> expiredChannels(ConcurrentLinkedQueue<IdleChannel> pool, long now) { // lazy create List<IdleChannel> idleTimeoutChannels = null; for (IdleChannel idleChannel : pool) { if (isTTLExpired(idleChannel.channel, now) || isIdleTimeoutExpired(idleChannel, now) || !Channels.isChannelValid(idleChannel.channel)) { LOGGER.debug("Adding Candidate expired Channel {}", idleChannel.channel); if (idleTimeoutChannels == null) idleTimeoutChannels = new ArrayList<IdleChannel>(); idleTimeoutChannels.add(idleChannel); } } return idleTimeoutChannels != null ? idleTimeoutChannels : Collections.<IdleChannel> emptyList(); }
public DefaultChannelPool(// long maxIdleTime,// int maxConnectionTTL,// boolean sslConnectionPoolEnabled,// Timer nettyTimer) { this.sslConnectionPoolEnabled = sslConnectionPoolEnabled; this.maxIdleTime = maxIdleTime; this.maxConnectionTTL = maxConnectionTTL; maxConnectionTTLDisabled = maxConnectionTTL <= 0; this.nettyTimer = nettyTimer; maxIdleTimeDisabled = maxIdleTime <= 0; cleanerPeriod = Math.min(maxConnectionTTLDisabled ? Long.MAX_VALUE : maxConnectionTTL, maxIdleTimeDisabled ? Long.MAX_VALUE : maxIdleTime); if (!maxConnectionTTLDisabled || !maxIdleTimeDisabled) scheduleNewIdleChannelDetector(new IdleChannelDetector()); }