@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { IdleStateEvent idleEvt = (IdleStateEvent) evt; switch (idleEvt.state()) { case WRITER_IDLE: if (id2Call.isEmpty()) { if (LOG.isTraceEnabled()) { LOG.trace("shutdown connection to " + conn.remoteId().address + " because idle for a long time"); } // It may happen that there are still some pending calls in the event loop queue and // they will get a closed channel exception. But this is not a big deal as it rarely // rarely happens and the upper layer could retry immediately. conn.shutdown(); } break; default: LOG.warn("Unrecognized idle state " + idleEvt.state()); break; } } else if (evt instanceof CallEvent) { // just remove the call for now until we add other call event other than timeout and cancel. id2Call.remove(((CallEvent) evt).call.id); } else { ctx.fireUserEventTriggered(evt); } } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof BufferCallEvent) { BufferCallEvent bcEvt = (BufferCallBeforeInitHandler.BufferCallEvent) evt; switch (bcEvt.action) { case FLUSH: for (Call call : id2Call.values()) { ctx.write(call); } break; case FAIL: for (Call call : id2Call.values()) { call.setException(bcEvt.error); } break; } ctx.flush(); ctx.pipeline().remove(this); } else if (evt instanceof CallEvent) { // just remove the call for now until we add other call event other than timeout and cancel. id2Call.remove(((CallEvent) evt).call.id); } else { ctx.fireUserEventTriggered(evt); } } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { IdleStateEvent idleEvt = (IdleStateEvent) evt; switch (idleEvt.state()) { case WRITER_IDLE: if (id2Call.isEmpty()) { if (LOG.isTraceEnabled()) { LOG.trace("shutdown connection to " + conn.remoteId().address + " because idle for a long time"); } // It may happen that there are still some pending calls in the event loop queue and // they will get a closed channel exception. But this is not a big deal as it rarely // rarely happens and the upper layer could retry immediately. conn.shutdown(); } break; default: LOG.warn("Unrecognized idle state " + idleEvt.state()); break; } } else if (evt instanceof CallEvent) { // just remove the call for now until we add other call event other than timeout and cancel. id2Call.remove(((CallEvent) evt).call.id); } else { ctx.fireUserEventTriggered(evt); } } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof BufferCallEvent) { BufferCallEvent bcEvt = (BufferCallBeforeInitHandler.BufferCallEvent) evt; switch (bcEvt.action) { case FLUSH: for (Call call : id2Call.values()) { ctx.write(call); } break; case FAIL: for (Call call : id2Call.values()) { call.setException(bcEvt.error); } break; } ctx.flush(); ctx.pipeline().remove(this); } else if (evt instanceof CallEvent) { // just remove the call for now until we add other call event other than timeout and cancel. id2Call.remove(((CallEvent) evt).call.id); } else { ctx.fireUserEventTriggered(evt); } } }
@Override public ChannelHandlerContext fireUserEventTriggered(Object event) { ctx.fireUserEventTriggered(event); return this; }
void onUpgradeEvent(ChannelHandlerContext ctx, UpgradeEvent evt) { ctx.fireUserEventTriggered(evt); }
/** * Calls {@link ChannelHandlerContext#fireUserEventTriggered(Object)} to forward * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}. * * Sub-classes may override this method to change behavior. */ @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { ctx.fireUserEventTriggered(evt); }
/** * Is called when an {@link IdleStateEvent} should be fired. This implementation calls * {@link ChannelHandlerContext#fireUserEventTriggered(Object)}. */ protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception { ctx.fireUserEventTriggered(evt); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { ctx.fireUserEventTriggered(evt); }
void onHttp2StreamWritabilityChanged(ChannelHandlerContext ctx, Http2FrameStream stream, @SuppressWarnings("unused") boolean writable) { ctx.fireUserEventTriggered(Http2FrameStreamEvent.writabilityChanged(stream)); }
void onHttp2StreamStateChanged(ChannelHandlerContext ctx, Http2FrameStream stream) { ctx.fireUserEventTriggered(Http2FrameStreamEvent.stateChanged(stream)); }
private void notifyClosePromise(Throwable cause) { if (cause == null) { if (sslClosePromise.trySuccess(ctx.channel())) { ctx.fireUserEventTriggered(SslCloseCompletionEvent.SUCCESS); } } else { if (sslClosePromise.tryFailure(cause)) { ctx.fireUserEventTriggered(new SslCloseCompletionEvent(cause)); } } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "USER_EVENT", evt)); } ctx.fireUserEventTriggered(evt); }
static void notifyHandshakeFailure(ChannelHandlerContext ctx, Throwable cause) { // We have may haven written some parts of data before an exception was thrown so ensure we always flush. // See https://github.com/netty/netty/issues/3900#issuecomment-172481830 ctx.flush(); ctx.fireUserEventTriggered(new SslHandshakeCompletionEvent(cause)); ctx.close(); }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { ctx.fireExceptionCaught(future.cause()); } else { ctx.fireUserEventTriggered( WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_ISSUED); } } });
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { ctx.fireExceptionCaught(future.cause()); } else { // Kept for compatibility ctx.fireUserEventTriggered( WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE); ctx.fireUserEventTriggered( new WebSocketServerProtocolHandler.HandshakeComplete( req.uri(), req.headers(), handshaker.selectedSubprotocol())); } } });
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof SslHandshakeCompletionEvent) { ctx.pipeline().remove(this); SslHandshakeCompletionEvent event = (SslHandshakeCompletionEvent) evt; if (event.isSuccess() && !verify(ctx, engine)) { throw OCSP_VERIFICATION_EXCEPTION; } } ctx.fireUserEventTriggered(evt); } }
/** * Notify all the handshake futures about the successfully handshake */ private void setHandshakeSuccess() { handshakePromise.trySuccess(ctx.channel()); if (logger.isDebugEnabled()) { logger.debug("{} HANDSHAKEN: {}", ctx.channel(), engine.getSession().getCipherSuite()); } ctx.fireUserEventTriggered(SslHandshakeCompletionEvent.SUCCESS); if (readDuringHandshake && !ctx.channel().config().isAutoRead()) { readDuringHandshake = false; ctx.read(); } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof SslHandshakeCompletionEvent) { ctx.pipeline().remove(this); SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt; if (handshakeEvent.isSuccess()) { SslHandler sslHandler = ctx.pipeline().get(SslHandler.class); if (sslHandler == null) { throw new IllegalStateException("cannot find a SslHandler in the pipeline (required for " + "application-level protocol negotiation)"); } String protocol = sslHandler.applicationProtocol(); configurePipeline(ctx, protocol != null? protocol : fallbackProtocol); } else { handshakeFailure(ctx, handshakeEvent.cause()); } } ctx.fireUserEventTriggered(evt); }
@Override public void operationComplete(ChannelFuture future) throws Exception { try { if (future.isSuccess()) { // Perform the upgrade to the new protocol. sourceCodec.upgradeFrom(ctx); finalUpgradeCodec.upgradeTo(ctx, request); // Notify that the upgrade has occurred. Retain the event to offset // the release() in the finally block. ctx.fireUserEventTriggered(event.retain()); // Remove this handler from the pipeline. ctx.pipeline().remove(HttpServerUpgradeHandler.this); } else { future.channel().close(); } } finally { // Release the event if the upgrade event wasn't fired. event.release(); } } });