@Override public void enableRecv() { if (throttled.compareAndSet(true, false)) { if (LOG.isDebugEnabled()) { LOG.debug("Sending unthrottle event {}", this); } channel.pipeline().fireUserEventTriggered(AutoReadEvent.ENABLE); } }
/** * Note that the netty implementation ignores the <code>waitDisableRecv</code> * parameter and is always asynchronous. * @param waitDisableRecv ignored by this implementation. */ @Override public void disableRecv(boolean waitDisableRecv) { if (throttled.compareAndSet(false, true)) { if (LOG.isDebugEnabled()) { LOG.debug("Throttling - disabling recv {}", this); } channel.pipeline().fireUserEventTriggered(AutoReadEvent.DISABLE); } }
protected static boolean fireCompleteEventIfNotAlready(ChannelHandlerContext ctx, CompleteReason reason) { // Only allow this method to run once per request. Attribute<State> attr = ctx.channel().attr(ATTR_STATE); State state = attr.get(); if (state == null || state != State.STARTED) return false; attr.set(State.COMPLETED); HttpRequest request = ctx.channel().attr(ATTR_HTTP_REQ).get(); HttpResponse response = ctx.channel().attr(ATTR_HTTP_RESP).get(); // Cleanup channel attributes. ctx.channel().attr(ATTR_HTTP_REQ).set(null); ctx.channel().attr(ATTR_HTTP_RESP).set(null); // Fire the event to whole pipeline. ctx.pipeline().fireUserEventTriggered(new CompleteEvent(reason, request, response)); return true; }
private void closeOutboundBufferForShutdown( ChannelPipeline pipeline, ChannelOutboundBuffer buffer, Throwable cause) { buffer.failFlushed(cause, false); buffer.close(cause, true); pipeline.fireUserEventTriggered(ChannelOutputShutdownEvent.INSTANCE); }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { if (maxConnections > 0) { int currentCount = connections.getAndIncrement(); if (currentCount + 1 > maxConnections) { LOG.warn("Throttling incoming connection as above configured max connections threshold of " + maxConnections); Channel channel = ctx.channel(); channel.attr(ATTR_CH_THROTTLED).set(Boolean.TRUE); CurrentPassport.fromChannel(channel).add(PassportState.SERVER_CH_THROTTLING); channel.close(); ctx.pipeline().fireUserEventTriggered(CONNECTION_THROTTLED_EVENT); } } super.channelActive(ctx); }
private void closeOutboundBufferForShutdown( ChannelPipeline pipeline, ChannelOutboundBuffer buffer, Throwable cause) { buffer.failFlushed(cause, false); buffer.close(cause, true); pipeline.fireUserEventTriggered(ChannelOutputShutdownEvent.INSTANCE); }
private void closeOnRead(ChannelPipeline pipeline) { if (!isInputShutdown0()) { if (isAllowHalfClosure(config())) { shutdownInput(); pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { close(voidPromise()); } } else { inputClosedSeenErrorOnRead = true; pipeline.fireUserEventTriggered(ChannelInputShutdownReadComplete.INSTANCE); } }
private void closeOnRead(ChannelPipeline pipeline) { if (isOpen()) { if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) { shutdownInput(); pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { unsafe().close(unsafe().voidPromise()); } pipeline.fireUserEventTriggered(ChannelInputShutdownReadComplete.INSTANCE); } }
private void closeOutboundBufferForShutdown( ChannelPipeline pipeline, ChannelOutboundBuffer buffer, Throwable cause) { buffer.failFlushed(cause, false); buffer.close(cause, true); pipeline.fireUserEventTriggered(ChannelOutputShutdownEvent.INSTANCE); }
private void closeOnRead(ChannelPipeline pipeline) { if (!isInputShutdown0()) { if (isAllowHalfClosure(config())) { shutdownInput(); pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { close(voidPromise()); } } else { inputClosedSeenErrorOnRead = true; pipeline.fireUserEventTriggered(ChannelInputShutdownReadComplete.INSTANCE); } }
private void fireEventAndClose(Object evt) { pipeline().fireUserEventTriggered(evt); close(voidPromise()); }
private void fireEventAndClose(Object evt) { pipeline().fireUserEventTriggered(evt); close(voidPromise()); }
private void closeOnRead(ChannelPipeline pipeline) { if (isOpen()) { if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) { shutdownInput(); pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { unsafe().close(unsafe().voidPromise()); } pipeline.fireUserEventTriggered(ChannelInputShutdownReadComplete.INSTANCE); } }
protected static boolean fireCompleteEventIfNotAlready(ChannelHandlerContext ctx, CompleteReason reason) { // Only allow this method to run once per request. Attribute<State> attr = ctx.channel().attr(ATTR_STATE); State state = attr.get(); if (state == null || state != State.STARTED) return false; attr.set(State.COMPLETED); HttpRequest request = ctx.channel().attr(ATTR_HTTP_REQ).get(); HttpResponse response = ctx.channel().attr(ATTR_HTTP_RESP).get(); // Cleanup channel attributes. ctx.channel().attr(ATTR_HTTP_REQ).set(null); ctx.channel().attr(ATTR_HTTP_RESP).set(null); // Fire the event to whole pipeline. ctx.pipeline().fireUserEventTriggered(new CompleteEvent(reason, request, response)); return true; }
private void fireEventAndClose(Object evt) { pipeline().fireUserEventTriggered(evt); close(voidPromise()); }
@Override public void requestMore() { if (isConnected() && !isClosed()) { if (!channel.config().isAutoRead()) { channel.pipeline().fireUserEventTriggered(EnableAutoRead.INSTANCE); } } } }
private void closeOnRead(ChannelPipeline pipeline) { if (isOpen()) { if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) { shutdownInput(); pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { unsafe().close(unsafe().voidPromise()); } pipeline.fireUserEventTriggered(ChannelInputShutdownReadComplete.INSTANCE); } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { if (maxConnections > 0) { int currentCount = connections.getAndIncrement(); if (currentCount + 1 > maxConnections) { LOG.warn("Throttling incoming connection as above configured max connections threshold of " + maxConnections); Channel channel = ctx.channel(); channel.attr(ATTR_CH_THROTTLED).set(Boolean.TRUE); CurrentPassport.fromChannel(channel).add(PassportState.SERVER_CH_THROTTLING); channel.close(); ctx.pipeline().fireUserEventTriggered(CONNECTION_THROTTLED_EVENT); } } super.channelActive(ctx); }
protected static boolean fireStartEvent(ChannelHandlerContext ctx, HttpRequest request) { // Only allow this method to run once per request. Channel channel = ctx.channel(); Attribute<State> attr = channel.attr(ATTR_STATE); State state = attr.get(); if (state == State.STARTED) { // This could potentially happen if a bad client sends a 2nd request on the same connection // without waiting for the response from the first. And we don't support HTTP Pipelining. LOG.error("Received a http request on connection where we already have a request being processed. " + "Closing the connection now. channel = " + channel.id().asLongText()); channel.close(); ctx.pipeline().fireUserEventTriggered(new RejectedPipeliningEvent()); return false; } channel.attr(ATTR_STATE).set(State.STARTED); channel.attr(ATTR_HTTP_REQ).set(request); ctx.pipeline().fireUserEventTriggered(new StartEvent(request)); return true; }
@Override public boolean visit(Http2FrameStream stream) { final int streamId = stream.id(); final DefaultHttp2StreamChannel childChannel = ((Http2MultiplexCodecStream) stream).channel; if (streamId > goAwayFrame.lastStreamId() && connection().local().isValidStreamId(streamId)) { childChannel.pipeline().fireUserEventTriggered(goAwayFrame.retainedDuplicate()); } return true; } });