private void flushPartition(Object partitionKey, ConcurrentLinkedQueue<IdleChannel> partition) { if (partition != null) { partitions.remove(partitionKey); for (IdleChannel idleChannel : partition) close(idleChannel.channel); } }
@Override public void flushPartition(Object partitionKey) { flushPartition(partitionKey, partitions.get(partitionKey)); }
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()); }
/** * {@inheritDoc} */ public boolean offer(Channel channel, Object partitionKey) { if (isClosed.get() || (!sslConnectionPoolEnabled && channel.pipeline().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(channelId(channel), new ChannelCreation(now, partitionKey)); 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; }
private boolean isTTLExpired(Channel channel, long now) { if (maxConnectionTTLDisabled) return false; ChannelCreation creation = channelId2Creation.get(channelId(channel)); return creation != null && now - creation.creationTime >= maxConnectionTTL; }
/** * {@inheritDoc} */ public Channel poll(Object partitionKey) { IdleChannel idleChannel = null; ConcurrentLinkedQueue<IdleChannel> partition = partitions.get(partitionKey); if (partition != null) { while (idleChannel == null) { idleChannel = partition.poll(); if (idleChannel == null) // pool is empty break; else if (isRemotelyClosed(idleChannel.channel)) { idleChannel = null; LOGGER.trace("Channel not connected or not opened, probably remotely closed!"); } } } return idleChannel != null ? idleChannel.channel : null; }
/** * {@inheritDoc} */ public boolean offer(Channel channel, Object partitionKey) { if (isClosed.get() || (!sslConnectionPoolEnabled && channel.pipeline().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(channelId(channel), new ChannelCreation(now, partitionKey)); 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; }
private boolean isTTLExpired(Channel channel, long now) { if (maxConnectionTTLDisabled) return false; ChannelCreation creation = channelId2Creation.get(channelId(channel)); return creation != null && now - creation.creationTime >= maxConnectionTTL; }
/** * {@inheritDoc} */ public Channel poll(Object partitionKey) { IdleChannel idleChannel = null; ConcurrentLinkedQueue<IdleChannel> partition = partitions.get(partitionKey); if (partition != null) { while (idleChannel == null) { idleChannel = partition.poll(); if (idleChannel == null) // pool is empty break; else if (isRemotelyClosed(idleChannel.channel)) { idleChannel = null; LOGGER.trace("Channel not connected or not opened, probably remotely closed!"); } } } return idleChannel != null ? idleChannel.channel : null; }
private void flushPartition(Object partitionKey, ConcurrentLinkedQueue<IdleChannel> partition) { if (partition != null) { partitions.remove(partitionKey); for (IdleChannel idleChannel : partition) close(idleChannel.channel); } }
@Override public void flushPartition(Object partitionKey) { flushPartition(partitionKey, partitions.get(partitionKey)); }
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()); }
channelPool = new DefaultChannelPool(config, nettyTimer); } else if (channelPool == null) { channelPool = new NoopChannelPool();
/** * {@inheritDoc} */ public boolean removeAll(Channel channel) { ChannelCreation creation = channelId2Creation.remove(channelId(channel)); return !isClosed.get() && creation != null && partitions.get(creation.partitionKey).remove(channel); }
private void flushPartition(Object partitionKey, ConcurrentLinkedQueue<IdleChannel> partition) { if (partition != null) { partitions.remove(partitionKey); for (IdleChannel idleChannel : partition) close(idleChannel.channel); } }
@Override public void flushPartition(Object partitionKey) { flushPartition(partitionKey, partitions.get(partitionKey)); }