private void flushPartition(Object partitionKey, ConcurrentLinkedQueue<IdleChannel> partition) { if (partition != null) { partitions.remove(partitionKey); for (IdleChannel idleChannel : partition) close(idleChannel.channel); } }
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()); }
@Override public void flushPartition(Object partitionKey) { flushPartition(partitionKey, partitions.get(partitionKey)); }
public boolean offer(Channel channel, String poolKey) { if (isClosed.get() || (!sslConnectionPoolEnabled && poolKey.startsWith("https"))) return false; long now = millisTime(); if (isTTLExpired(channel, now)) return false; boolean added = getPoolForKey(poolKey).add(new IdleChannel(channel, now)); if (added) channelId2Creation.putIfAbsent(channel.getId(), new ChannelCreation(now, poolKey)); return added; }
channelPool = new DefaultChannelPool(config, nettyTimer); } else if (channelPool == null) { channelPool = new NoopChannelPool();
public boolean offer(Channel channel, Object partitionKey) { if (isClosed.get() || (!sslConnectionPoolEnabled && channel.getPipeline().get(SslHandler.class) != null)) return false; long now = millisTime(); if (isTTLExpired(channel, now)) return false; boolean added = partitions.computeIfAbsent(partitionKey, PARTITION_COMPUTER).add(new IdleChannel(channel, now)); if (added) channelId2Creation.putIfAbsent(channel.getId(), new ChannelCreation(now, partitionKey)); return added; }
channelPool = new DefaultChannelPool(config, nettyTimer); } else if (channelPool == null) { channelPool = new NoopChannelPool();
@Override public void destroy() { if (isClosed.getAndSet(true)) return; for (ConcurrentLinkedQueue<IdleChannel> partition : partitions.values()) { for (IdleChannel idleChannel : partition) close(idleChannel.channel); } partitions.clear(); channelId2Creation.clear(); }
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()); }
@Override public void flushPartitions(ChannelPoolPartitionSelector selector) { for (Map.Entry<Object, ConcurrentLinkedQueue<IdleChannel>> partitionsEntry : partitions.entrySet()) { Object partitionKey = partitionsEntry.getKey(); if (selector.select(partitionKey)) flushPartition(partitionKey, partitionsEntry.getValue()); } } }
@Override public void destroy() { if (isClosed.getAndSet(true)) return; for (ConcurrentLinkedQueue<IdleChannel> pool : poolsPerKey.values()) { for (IdleChannel idleChannel : pool) close(idleChannel.channel); } poolsPerKey.clear(); channelId2Creation.clear(); }