public boolean isOpen() { return channelPool.isOpen(); } }
public void removeAll(Channel connection) { channelPool.removeAll(connection); }
private void doClose() { openChannels.close(); channelPool.destroy(); }
public Channel poll(Uri uri, String virtualHost, ProxyServer proxy, ChannelPoolPartitioning connectionPoolPartitioning) { Object partitionKey = connectionPoolPartitioning.getPartitionKey(uri, virtualHost, proxy); return channelPool.poll(partitionKey); }
@Override public void flushChannelPoolPartitions(Predicate<Object> predicate) { getChannelPool().flushPartitions(predicate); }
public ClientStats getClientStats() { Map<String, Long> totalConnectionsPerHost = openChannels.stream().map(Channel::remoteAddress).filter(a -> a.getClass() == InetSocketAddress.class) .map(a -> (InetSocketAddress) a).map(InetSocketAddress::getHostName).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); Map<String, Long> idleConnectionsPerHost = channelPool.getIdleChannelCountPerHost(); Map<String, HostStats> statsPerHost = totalConnectionsPerHost.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> { final long totalConnectionCount = entry.getValue(); final long idleConnectionCount = idleConnectionsPerHost.getOrDefault(entry.getKey(), 0L); final long activeConnectionCount = totalConnectionCount - idleConnectionCount; return new HostStats(activeConnectionCount, idleConnectionCount); })); return new ClientStats(statsPerHost); }
public final void tryToOfferChannelToPool(Channel channel, AsyncHandler<?> asyncHandler, boolean keepAlive, Object partitionKey) { if (channel.isActive() && keepAlive) { LOGGER.debug("Adding key: {} for channel {}", partitionKey, channel); Channels.setDiscard(channel); try { asyncHandler.onConnectionOffer(channel); } catch (Exception e) { LOGGER.error("onConnectionOffer crashed", e); } if (!channelPool.offer(channel, partitionKey)) { // rejected by pool closeChannel(channel); } } else { // not offered closeChannel(channel); } }