public void drainChannelAndOffer(final Channel channel, final NettyResponseFuture<?> future, boolean keepAlive, Object partitionKey) { Channels.setAttribute(channel, newDrainCallback(future, channel, keepAlive, partitionKey)); }
public void flushChannelPoolPartition(String partitionId) { channelManager.flushPartition(partitionId); }
private void abortChannelPreemption() { if (channelPreempted) channelManager.abortChannelPreemption(partitionKey); }
public void preemptChannel(Object partitionKey) throws IOException { if (!channelPool.isOpen()) throw poolAlreadyClosed; if (!tryAcquireGlobal()) throw tooManyConnections; if (!tryAcquirePerHost(partitionKey)) { if (maxTotalConnectionsEnabled) freeChannels.release(); throw tooManyConnectionsPerHost; } }
public final void tryToOfferChannelToPool(Channel channel, boolean keepAlive, Object partitionKey) { if (channel.isConnected() && keepAlive && channel.isReadable()) { LOGGER.debug("Adding key: {} for channel {}", partitionKey, channel); Channels.setDiscard(channel); if (channelPool.offer(channel, partitionKey)) { if (maxConnectionsPerHostEnabled) channelId2PartitionKey.putIfAbsent(channel.getId(), partitionKey); } else { // rejected by pool closeChannel(channel); } } else { // not offered closeChannel(channel); } }
public void upgradeProtocol(ChannelPipeline pipeline, String scheme, String host, int port) throws IOException, GeneralSecurityException { if (pipeline.get(HTTP_HANDLER) != null) pipeline.remove(HTTP_HANDLER); if (isSecure(scheme)) if (isSslHandlerConfigured(pipeline)) { pipeline.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec()); } else { pipeline.addFirst(HTTP_HANDLER, newHttpClientCodec()); pipeline.addFirst(SSL_HANDLER, createSslHandler(host, port)); } else pipeline.addFirst(HTTP_HANDLER, newHttpClientCodec()); if (isWebSocket(scheme)) { pipeline.addAfter(HTTP_PROCESSOR, WS_PROCESSOR, wsProcessor); pipeline.remove(HTTP_PROCESSOR); } }
public void closeChannel(Channel channel) { // The channel may have already been removed from the future if a timeout occurred, and this method may be called just after. LOGGER.debug("Closing Channel {} ", channel); try { removeAll(channel); Channels.setDiscard(channel); Channels.silentlyCloseChannel(channel); } catch (Throwable t) { LOGGER.debug("Error closing a connection", t); } openChannels.remove(channel); }
public void verifyChannelPipeline(ChannelPipeline pipeline, String scheme) throws IOException, GeneralSecurityException { boolean sslHandlerConfigured = isSslHandlerConfigured(pipeline); if (isSecure(scheme)) { if (!sslHandlerConfigured) pipeline.addFirst(SSL_HANDLER, new SslInitializer(this)); } else if (sslHandlerConfigured) pipeline.remove(SSL_HANDLER); }
private void close(Channel channel) { // FIXME pity to have to do this here Channels.setDiscard(channel); channelId2Creation.remove(channel.getId()); Channels.silentlyCloseChannel(channel); }
private boolean tryAcquirePerHost(Object partitionKey) { return !maxConnectionsPerHostEnabled || getFreeConnectionsForHost(partitionKey).tryAcquire(); }
public void abort(Channel channel, NettyResponseFuture<?> future, Throwable t) { if (channel != null) channelManager.closeChannel(channel); if (!future.isDone()) { LOGGER.debug("Aborting Future {}\n", future); LOGGER.debug(t.getMessage(), t); future.abort(t); } }
/** * Return true if the {@link Future} can be recovered. There is some scenario where a connection can be closed by an * unexpected IOException, and in some situation we can recover from that exception. * * @return true if that {@link Future} cannot be recovered. */ public boolean canBeReplayed() { return !isDone() && canRetry() && !(Channels.isChannelValid(channel) && !uri.getScheme().equalsIgnoreCase("https")) && !isInAuth(); }
public static void setDiscard(Channel channel) { setAttribute(channel, DiscardEvent.INSTANCE); }
public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = pipeline(); pipeline.addLast(SSL_HANDLER, new SslInitializer(ChannelManager.this)); pipeline.addLast(HTTP_HANDLER, newHttpClientCodec()); pipeline.addLast(WS_PROCESSOR, wsProcessor); if (nettyConfig.getWssAdditionalPipelineInitializer() != null) nettyConfig.getWssAdditionalPipelineInitializer().initPipeline(pipeline); return pipeline; } });
public void flushChannelPoolPartitions(ChannelPoolPartitionSelector selector) { channelManager.flushPartitions(selector); } }
public void attachChannel(Channel channel, boolean reuseChannel) { // future could have been cancelled first if (isDone()) { Channels.silentlyCloseChannel(channel); } this.channel = channel; this.reuseChannel = reuseChannel; }
public void drainChannelAndOffer(final Channel channel, final NettyResponseFuture<?> future) { drainChannelAndOffer(channel, future, future.isKeepAlive(), future.getPartitionKey()); }
public void abortChannelPreemption(Object partitionKey) { if (maxTotalConnectionsEnabled) freeChannels.release(); if (maxConnectionsPerHostEnabled) getFreeConnectionsForHost(partitionKey).release(); }
public void handleUnexpectedClosedChannel(Channel channel, NettyResponseFuture<?> future) { if (future.isDone()) channelManager.closeChannel(channel); else if (!retry(future)) abort(channel, future, REMOTELY_CLOSED_EXCEPTION); }
private Channel getCachedChannel(NettyResponseFuture<?> future, Uri uri, ConnectionPoolPartitioning partitioning, ProxyServer proxyServer, AsyncHandler<?> asyncHandler) { if (future != null && future.reuseChannel() && Channels.isChannelValid(future.channel())) return future.channel(); else return pollAndVerifyCachedChannel(uri, proxyServer, partitioning, asyncHandler); }