List of usage examples for io.netty.channel ChannelHandlerContext fireUserEventTriggered
@Override ChannelHandlerContext fireUserEventTriggered(Object evt);
From source file:com.alibaba.dubbo.remoting.transport.netty4.NettyHandler.java
License:Apache License
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object o) throws Exception { ctx.fireUserEventTriggered(o); }
From source file:com.barchart.netty.common.pipeline.WebSocketConnectedNotifier.java
License:BSD License
@Override public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) throws Exception { if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE || evt == WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE) { ctx.fireChannelActive();/*from w w w . j av a 2 s . c o m*/ ctx.fireUserEventTriggered(evt); for (final Object msg : messages) ctx.fireChannelRead(msg); messages.clear(); ctx.pipeline().remove(this); } else { ctx.fireUserEventTriggered(evt); } }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueFeatureHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, FullBinaryMemcacheResponse msg) throws Exception { List<ServerFeatures> supported = new ArrayList<ServerFeatures>(); ResponseStatus responseStatus = ResponseStatusConverter.fromBinary(msg.getStatus()); if (responseStatus.isSuccess()) { while (msg.content().isReadable()) { supported.add(ServerFeatures.fromValue(msg.content().readShort())); }/*from w w w . ja v a 2 s .c o m*/ } else { LOGGER.debug("HELLO Negotiation did not succeed ({}).", responseStatus); } LOGGER.debug("Negotiated supported features: {}", supported); ctx.fireUserEventTriggered(new ServerFeaturesEvent(supported)); originalPromise.setSuccess(); ctx.pipeline().remove(this); ctx.fireChannelActive(); }
From source file:com.farsunset.cim.sdk.android.filter.CIMLoggingHandler.java
License:Apache License
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (debug && evt instanceof IdleStateEvent) { Log.d(TAG, String.format("IDLE %s" + getSessionInfo(ctx.channel()), ((IdleStateEvent) evt).state().toString())); }//from w w w . j a v a2s .co m ctx.fireUserEventTriggered(evt); }
From source file:com.github.nettybook.ch0.LoggingHandler.java
License:Apache License
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "USER_EVENT", evt)); }/*from ww w. j a va 2 s. c o m*/ ctx.fireUserEventTriggered(evt); }
From source file:com.github.sparkfy.network.server.TransportChannelHandler.java
License:Apache License
/** Triggered based on events from an {@link io.netty.handler.timeout.IdleStateHandler}. */ @Override/*from w ww .j a va2 s . c o m*/ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { IdleStateEvent e = (IdleStateEvent) evt; // See class comment for timeout semantics. In addition to ensuring we only timeout while // there are outstanding requests, we also do a secondary consistency check to ensure // there's no race between the idle timeout and incrementing the numOutstandingRequests // (see SPARK-7003). // // To avoid a race between TransportClientFactory.createClient() and this code which could // result in an inactive client being returned, this needs to run in a synchronized block. synchronized (this) { boolean isActuallyOverdue = System.nanoTime() - responseHandler.getTimeOfLastRequestNs() > requestTimeoutNs; if (e.state() == IdleState.ALL_IDLE && isActuallyOverdue) { if (responseHandler.numOutstandingRequests() > 0) { String address = NettyUtils.getRemoteAddress(ctx.channel()); logger.error("Connection to {} has been quiet for {} ms while there are outstanding " + "requests. Assuming connection is dead; please adjust spark.network.timeout if this " + "is wrong.", address, requestTimeoutNs / 1000 / 1000); client.timeOut(); ctx.close(); } else if (closeIdleConnections) { // While CloseIdleConnections is enable, we also close idle connection client.timeOut(); ctx.close(); } } } } ctx.fireUserEventTriggered(evt); }
From source file:com.linecorp.armeria.client.http.Http1ResponseDecoder.java
License:Apache License
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { ctx.fireUserEventTriggered(evt); }
From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java
License:Apache License
/** * @see <a href="https://http2.github.io/http2-spec/#discover-https">HTTP/2 specification</a> *//*from ww w. j av a2s .c o m*/ private void configureAsHttps(Channel ch) { final ChannelPipeline p = ch.pipeline(); final SslHandler sslHandler = sslCtx.newHandler(ch.alloc()); p.addLast(sslHandler); p.addLast(new ChannelInboundHandlerAdapter() { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (!(evt instanceof SslHandshakeCompletionEvent)) { ctx.fireUserEventTriggered(evt); return; } final SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt; if (!handshakeEvent.isSuccess()) { // The connection will be closed automatically by SslHandler. return; } final SessionProtocol protocol; if (isHttp2Protocol(sslHandler)) { if (httpPreference == HttpPreference.HTTP1_REQUIRED) { finishWithNegotiationFailure(ctx, H1, H2, "unexpected protocol negotiation result"); return; } addBeforeSessionHandler(p, newHttp2ConnectionHandler(ch)); protocol = H2; } else { if (httpPreference != HttpPreference.HTTP1_REQUIRED) { SessionProtocolNegotiationCache.setUnsupported(ctx.channel().remoteAddress(), H2); } if (httpPreference == HttpPreference.HTTP2_REQUIRED) { finishWithNegotiationFailure(ctx, H2, H1, "unexpected protocol negotiation result"); return; } addBeforeSessionHandler(p, newHttp1Codec()); protocol = H1; } finishSuccessfully(p, protocol); p.remove(this); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { Exceptions.logIfUnexpected(logger, ctx.channel(), cause); ctx.close(); } }); }
From source file:com.linecorp.armeria.client.HttpClientPipelineConfigurator.java
License:Apache License
/** * See <a href="https://http2.github.io/http2-spec/#discover-https">HTTP/2 specification</a>. */// ww w .j a va2 s .c o m private void configureAsHttps(Channel ch, InetSocketAddress remoteAddr) { assert sslCtx != null; final ChannelPipeline p = ch.pipeline(); final SslHandler sslHandler = sslCtx.newHandler(ch.alloc(), remoteAddr.getHostString(), remoteAddr.getPort()); p.addLast(sslHandler); p.addLast(TrafficLoggingHandler.CLIENT); p.addLast(new ChannelInboundHandlerAdapter() { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (!(evt instanceof SslHandshakeCompletionEvent)) { ctx.fireUserEventTriggered(evt); return; } final SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt; if (!handshakeEvent.isSuccess()) { // The connection will be closed automatically by SslHandler. return; } final SessionProtocol protocol; if (isHttp2Protocol(sslHandler)) { if (httpPreference == HttpPreference.HTTP1_REQUIRED) { finishWithNegotiationFailure(ctx, H1, H2, "unexpected protocol negotiation result"); return; } addBeforeSessionHandler(p, newHttp2ConnectionHandler(ch)); protocol = H2; } else { if (httpPreference != HttpPreference.HTTP1_REQUIRED) { SessionProtocolNegotiationCache.setUnsupported(ctx.channel().remoteAddress(), H2); } if (httpPreference == HttpPreference.HTTP2_REQUIRED) { finishWithNegotiationFailure(ctx, H2, H1, "unexpected protocol negotiation result"); return; } addBeforeSessionHandler(p, newHttp1Codec(clientFactory.maxHttp1InitialLineLength(), clientFactory.maxHttp1HeaderSize(), clientFactory.maxHttp1ChunkSize())); protocol = H1; } finishSuccessfully(p, protocol); p.remove(this); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { Exceptions.logIfUnexpected(logger, ctx.channel(), cause); ctx.close(); } }); }
From source file:com.linecorp.armeria.client.HttpConfigurator.java
License:Apache License
private void configureAsHttps(Channel ch) { ChannelPipeline pipeline = ch.pipeline(); SslHandler sslHandler = sslCtx.newHandler(ch.alloc()); pipeline.addLast(sslHandler);/*from w ww. j a v a 2 s.c o m*/ pipeline.addLast(new ChannelInboundHandlerAdapter() { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (!(evt instanceof SslHandshakeCompletionEvent)) { ctx.fireUserEventTriggered(evt); return; } final SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt; if (!handshakeEvent.isSuccess()) { // The connection will be closed automatically by SslHandler. return; } final SessionProtocol protocol; if (isHttp2Protocol(sslHandler)) { if (httpPreference == HttpPreference.HTTP1_REQUIRED) { finishWithNegotiationFailure(ctx, H1, H2, "unexpected protocol negotiation result"); return; } addBeforeSessionHandler(pipeline, newHttp2ConnectionHandler(ch)); protocol = H2; } else { if (httpPreference != HttpPreference.HTTP1_REQUIRED) { SessionProtocolNegotiationCache.setUnsupported(ctx.channel().remoteAddress(), H2); } if (httpPreference == HttpPreference.HTTP2_REQUIRED) { finishWithNegotiationFailure(ctx, H2, H1, "unexpected protocol negotiation result"); return; } addBeforeSessionHandler(pipeline, newHttp1Codec()); protocol = H1; } finishSuccessfully(pipeline, protocol); pipeline.remove(this); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { Exceptions.logIfUnexpected(logger, ctx.channel(), null, cause); ctx.close(); } }); }