List of usage examples for io.netty.channel ChannelHandlerContext fireExceptionCaught
@Override ChannelHandlerContext fireExceptionCaught(Throwable cause);
From source file:io.gatling.http.client.impl.ChunkedInboundHttp2ToHttpAdapter.java
License:Apache License
@Override public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) { ctx.fireExceptionCaught(Http2Exception.streamError(streamId, Http2Error.valueOf(errorCode), "HTTP/2 to HTTP layer caught stream reset")); }
From source file:io.grpc.netty.WriteBufferingAndExceptionHandlerTest.java
License:Apache License
@Test public void uncaughtException_closeAtMostOnce() throws Exception { final AtomicInteger closes = new AtomicInteger(); WriteBufferingAndExceptionHandler handler = new WriteBufferingAndExceptionHandler( new ChannelDuplexHandler() { @Override//from w w w. j av a 2 s. c o m public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { closes.getAndIncrement(); // Simulates a loop between this handler and the WriteBufferingAndExceptionHandler. ctx.fireExceptionCaught(Status.ABORTED.withDescription("zap").asRuntimeException()); super.close(ctx, promise); } }); LocalAddress addr = new LocalAddress("local"); ChannelFuture cf = new Bootstrap().channel(LocalChannel.class).handler(handler).group(group).register(); chan = cf.channel(); cf.sync(); ChannelFuture sf = new ServerBootstrap().channel(LocalServerChannel.class) .childHandler(new ChannelHandlerAdapter() { }).group(group).bind(addr); server = sf.channel(); sf.sync(); chan.connect(addr).sync(); chan.close().sync(); assertEquals(1, closes.get()); }
From source file:io.hekate.network.netty.NettyClientHandshakeHandler.java
License:Apache License
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { ctx.fireExceptionCaught(new ConnectException("Got disconnected on handshake [channel=" + id + ']')); }
From source file:io.hekate.network.netty.NettyClientHandshakeHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { if (trace) {/*from ww w . j av a 2 s.c o m*/ log.trace("Received handshake response [from={}, message={}]", id, msg); } NetworkProtocol handshakeMsg = (NetworkProtocol) msg; if (handshakeMsg.type() == NetworkProtocol.Type.HANDSHAKE_REJECT) { HandshakeReject reject = (HandshakeReject) handshakeMsg; String reason = reject.reason(); if (debug) { log.debug("Server rejected connection [to={}, reason={}]", id, reason); } ctx.fireExceptionCaught(new ConnectException(reason)); } else { HandshakeAccept accept = (HandshakeAccept) handshakeMsg; // Unregister self from the pipeline (handshake is a one time event). ctx.pipeline().remove(this); // Fire handshake event. ctx.fireUserEventTriggered(new NettyClientHandshakeEvent(accept)); } }
From source file:io.hekate.network.netty.NettyClientTimeoutHandler.java
License:Apache License
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof NettyClientHandshakeEvent) { NettyClientHandshakeEvent handshake = (NettyClientHandshakeEvent) evt; handshakeDone = true;/* w w w. j a va2 s.c om*/ // Unregister connect timeout handler. if (ctx.pipeline().get(CONNECT_TIMEOUT_HANDLER_ID) != null) { ctx.pipeline().remove(CONNECT_TIMEOUT_HANDLER_ID); } // Register heartbeat handler. mayBeRegisterHeartbeatHandler(handshake, ctx); super.userEventTriggered(ctx, evt); } else if (evt instanceof AutoReadChangeEvent) { if (evt == AutoReadChangeEvent.PAUSE) { // Completely ignore read timeouts. ignoreTimeouts = -1; } else { // Ignore next timeout. ignoreTimeouts = 1; } super.userEventTriggered(ctx, evt); } else if (evt instanceof IdleStateEvent) { IdleStateEvent idle = (IdleStateEvent) evt; if (idle.state() == IdleState.WRITER_IDLE) { if (hbFlushed) { // Make sure that we don't push multiple heartbeats to the network buffer simultaneously. // Need to perform this check since remote peer can hang and stop reading // while this channel will still be trying to put more and more heartbeats on its send buffer. hbFlushed = false; ctx.writeAndFlush(Heartbeat.INSTANCE).addListener(hbOnFlush); } } else { // Reader idle. // Ignore if auto-reading was disabled since in such case we will not read any heartbeats. if (ignoreTimeouts != -1 && ctx.channel().config().isAutoRead()) { // Check if timeout should be ignored. if (ignoreTimeouts > 0) { // Decrement the counter of ignored timeouts. ignoreTimeouts--; } else { if (handshakeDone) { ctx.fireExceptionCaught( new SocketTimeoutException("Timeout while reading data from " + id)); } else { ctx.fireExceptionCaught( new ConnectTimeoutException("Timeout while connecting to " + id)); } } } } } else { super.userEventTriggered(ctx, evt); } }
From source file:io.moquette.server.netty.BugSnagErrorsHandler.java
License:Open Source License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { bugsnag.notify(cause);/*from ww w. j a v a 2 s.com*/ ctx.fireExceptionCaught(cause); }
From source file:io.moquette.server.netty.NettyMQTTHandler__.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object message) { AbstractMessage msg = (AbstractMessage) message; LOG.info("Received a message of type {}", Utils.msgType2String(msg.getMessageType())); try {/* ww w.j a v a 2 s . com*/ switch (msg.getMessageType()) { case CONNECT: m_processor.processConnect(ctx.channel(), (ConnectMessage) msg); break; case SUBSCRIBE: //MODLOG: reject subscription requests //m_processor.processSubscribe(ctx.channel(), (SubscribeMessage) msg); SubAckMessage reject = ProtocolProcessor__ .prepareRejectSubscriptionResponse((SubscribeMessage) msg); ctx.channel().writeAndFlush(reject); break; case UNSUBSCRIBE: //MODLOG: there is no real unsubscribe action here //m_processor.processUnsubscribe(ctx.channel(), (UnsubscribeMessage) msg); UnsubAckMessage dummy = new UnsubAckMessage(); dummy.setMessageID(((UnsubscribeMessage) msg).getMessageID()); ctx.channel().writeAndFlush(dummy); break; case PUBLISH: m_processor.processPublish(ctx.channel(), (PublishMessage) msg); break; case PUBREC: m_processor.processPubRec(ctx.channel(), (PubRecMessage) msg); break; case PUBCOMP: m_processor.processPubComp(ctx.channel(), (PubCompMessage) msg); break; case PUBREL: m_processor.processPubRel(ctx.channel(), (PubRelMessage) msg); break; case DISCONNECT: m_processor.processDisconnect(ctx.channel()); break; case PUBACK: m_processor.processPubAck(ctx.channel(), (PubAckMessage) msg); break; case PINGREQ: PingRespMessage pingResp = new PingRespMessage(); ctx.writeAndFlush(pingResp); break; } } catch (Exception ex) { LOG.error("Bad error in processing the message", ex); ctx.fireExceptionCaught(ex); } }
From source file:io.netty.example.ocsp.OcspClientExample.java
License:Apache License
private static ChannelInitializer<Channel> newClientHandler(final ReferenceCountedOpenSslContext context, final String host, final Promise<FullHttpResponse> promise) { return new ChannelInitializer<Channel>() { @Override//w w w .j a v a2s . c o m protected void initChannel(Channel ch) throws Exception { SslHandler sslHandler = context.newHandler(ch.alloc()); ReferenceCountedOpenSslEngine engine = (ReferenceCountedOpenSslEngine) sslHandler.engine(); ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(sslHandler); pipeline.addLast(new ExampleOcspClientHandler(engine)); pipeline.addLast(new HttpClientCodec()); pipeline.addLast(new HttpObjectAggregator(1024 * 1024)); pipeline.addLast(new HttpClientHandler(host, promise)); } @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { if (!promise.isDone()) { promise.tryFailure(new IllegalStateException("Connection closed and Promise was not done.")); } ctx.fireChannelInactive(); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (!promise.tryFailure(cause)) { ctx.fireExceptionCaught(cause); } } }; }
From source file:jazmin.server.msg.codec.json.JSONDecoder.java
License:Open Source License
private void fail(final ChannelHandlerContext ctx, String length) { ctx.fireExceptionCaught(new TooLongFrameException( "frame length (" + length + ") exceeds the allowed maximum (" + maxLength + ')')); }
From source file:nats.codec.AbstractFrameDecoder.java
License:Open Source License
protected void throwTooLongFrameException(ChannelHandlerContext ctx) { ctx.fireExceptionCaught(new TooLongFrameException("message size exceeds " + maxMessageSize)); }