org.jboss.netty.channel.ExceptionEvent Java Examples

The following examples show how to use org.jboss.netty.channel.ExceptionEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShuffleHandler.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  } else if (cause instanceof IOException) {
    if (cause instanceof ClosedChannelException) {
      LOG.debug("Ignoring closed channel error", cause);
      return;
    }
    String message = String.valueOf(cause.getMessage());
    if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
      LOG.debug("Ignoring client socket close", cause);
      return;
    }
  }

  LOG.error("Shuffle error: ", cause);
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
Example #2
Source File: NettyAsyncHttpProvider.java    From ck with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
		throws Exception {
	Channel ch = e.getChannel();
	Throwable cause = e.getCause();

	if (log.isDebugEnabled())
		log.debug("I/O Exception during read or doConnect: ", cause);
	if (ctx.getAttachment() instanceof NettyResponseFuture<?>) {
		NettyResponseFuture<?> future = (NettyResponseFuture<?>) ctx.getAttachment();

		if (future!= null){
			future.getAsyncHandler().onThrowable(cause);
		}
	}

	if (log.isDebugEnabled()){
		log.debug(e);
		log.debug(ch);
	}
}
 
Example #3
Source File: ShuffleHandler.java    From tez with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  } else if (cause instanceof IOException) {
    if (cause instanceof ClosedChannelException) {
      LOG.debug("Ignoring closed channel error", cause);
      return;
    }
    String message = String.valueOf(cause.getMessage());
    if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
      LOG.debug("Ignoring client socket close", cause);
      return;
    }
  }

  LOG.error("Shuffle error: ", cause);
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
Example #4
Source File: UdpWorker.java    From parallec with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {

    if (!hasCaughtException) {
        hasCaughtException = true;

        String errMsg = e.getCause().toString();
        logger.debug("UDP Handler exceptionCaught: {} . ", errMsg);
        e.getChannel().close();

        int statusCodeInt = 1;
        String statusCode = statusCodeInt + " FAILURE";

        udpWorker.onComplete(udpWorker.responseSb.toString(), true,
                errMsg, errMsg, statusCode, statusCodeInt);
    }
}
 
Example #5
Source File: TcpWorker.java    From parallec with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    
    if(!hasCaughtException){
        hasCaughtException=true;
        e.getChannel().close();
        String errMsg = e.getCause().getLocalizedMessage();
        logger.debug("TCP Handler exceptionCaught: {} . ", errMsg);
        
        int statusCodeInt = 1;
        String statusCode = statusCodeInt + " FAILURE";
        
        tcpWorker.onComplete(tcpWorker.responseSb.toString(), true, 
                errMsg, errMsg, statusCode, statusCodeInt);
        
    }
}
 
Example #6
Source File: ShuffleHandler.java    From RDFS with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  }

  LOG.error("Shuffle error: ", cause);
  shuffleMetrics.failedOutput();
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
Example #7
Source File: IsisChannelHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    if (e.getCause() instanceof ReadTimeoutException) {
        log.debug("Disconnecting device {} due to read timeout", e.getChannel().getRemoteAddress());
        return;
    } else if (e.getCause() instanceof ClosedChannelException) {
        log.debug("Channel for ISIS {} already closed", e.getChannel().getRemoteAddress());
    } else if (e.getCause() instanceof IOException) {
        log.debug("Disconnecting ISIS {} due to IO Error: {}", e.getChannel().getRemoteAddress(),
                  e.getCause().getMessage());
    } else if (e.getCause() instanceof IsisParseException) {
        IsisParseException errMsg = (IsisParseException) e.getCause();
        byte errorCode = errMsg.errorCode();
        byte errorSubCode = errMsg.errorSubCode();
        log.debug("Error while parsing message from ISIS {}, ErrorCode {}",
                  e.getChannel().getRemoteAddress(), errorCode);
    } else if (e.getCause() instanceof RejectedExecutionException) {
        log.debug("Could not process message: queue full");
    } else {
        log.debug("Error while processing message from ISIS {}, {}",
                  e.getChannel().getRemoteAddress(), e.getCause().getMessage());
    }
}
 
Example #8
Source File: ClientIOHandler.java    From nfs-client-java with Apache License 2.0 6 votes vote down vote up
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Throwable cause = e.getCause();

    // do not print exception if it is BindException.
    // we are trying to search available port below 1024. It is not good to
    // print a flood
    // of error logs during the searching.
    if (cause instanceof java.net.BindException) {
        return;
    }

    LOG.error("Exception on connection to " + getRemoteAddress(), e.getCause());

    // close the channel unless we are connecting and it is
    // NotYetConnectedException
    if (!((cause instanceof NotYetConnectedException)
            && _connection.getConnectionState().equals(Connection.State.CONNECTING))) {
        ctx.getChannel().close();
    }
}
 
Example #9
Source File: ShuffleHandler.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  } else if (cause instanceof IOException) {
    if (cause instanceof ClosedChannelException) {
      LOG.debug("Ignoring closed channel error", cause);
      return;
    }
    String message = String.valueOf(cause.getMessage());
    if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
      LOG.debug("Ignoring client socket close", cause);
      return;
    }
  }

  LOG.error("Shuffle error: ", cause);
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
Example #10
Source File: OspfInterfaceChannelHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    log.debug("[exceptionCaught]: " + e.toString());
    if (e.getCause() instanceof ReadTimeoutException) {
        log.debug("Disconnecting device {} due to read timeout", e.getChannel().getRemoteAddress());
        return;
    } else if (e.getCause() instanceof ClosedChannelException) {
        log.debug("Channel for OSPF {} already closed", e.getChannel().getRemoteAddress());
    } else if (e.getCause() instanceof IOException) {
        log.debug("Disconnecting OSPF {} due to IO Error: {}", e.getChannel().getRemoteAddress(),
                  e.getCause().getMessage());
    } else if (e.getCause() instanceof OspfParseException) {
        OspfParseException errMsg = (OspfParseException) e.getCause();
        byte errorCode = errMsg.errorCode();
        byte errorSubCode = errMsg.errorSubCode();
        log.debug("Error while parsing message from OSPF {}, ErrorCode {}",
                  e.getChannel().getRemoteAddress(), errorCode);
    } else if (e.getCause() instanceof RejectedExecutionException) {
        log.debug("Could not process message: queue full");
    } else {
        log.debug("Error while processing message from OSPF {}, {}",
                  e.getChannel().getRemoteAddress(), e.getCause().getMessage());
    }
}
 
Example #11
Source File: NettyHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        handler.caught(channel, e.getCause());
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example #12
Source File: TestDelegationTokenRemoteFetcher.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();

  if (LOG.isDebugEnabled())
    LOG.debug(cause.getMessage());
  ch.close().addListener(ChannelFutureListener.CLOSE);
}
 
Example #13
Source File: BgpChannelHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {

    log.error("[exceptionCaught]: " + e.toString());

    if (e.getCause() instanceof ClosedChannelException) {
        bgpController.activeSessionExceptionAdd(peerAddr, e.getCause().toString());
        log.debug("Channel for bgp {} already closed", getPeerInfoString());
    } else if (e.getCause() instanceof IOException) {
        log.error("Disconnecting peer {} due to IO Error: {}", getPeerInfoString(), e.getCause().getMessage());
        bgpController.closedSessionExceptionAdd(peerAddr, e.getCause().toString());
        if (log.isDebugEnabled()) {
            // still print stack trace if debug is enabled
            log.debug("StackTrace for previous Exception: ", e.getCause());
        }
        stopSessionTimers();
        ctx.getChannel().close();
    } else if (e.getCause() instanceof BgpParseException) {
        byte[] data = new byte[] {};
        BgpParseException errMsg = (BgpParseException) e.getCause();
        byte errorCode = errMsg.getErrorCode();
        byte errorSubCode = errMsg.getErrorSubCode();
        bgpController.activeSessionExceptionAdd(peerAddr, e.getCause().toString());
        ChannelBuffer tempCb = errMsg.getData();
        if (tempCb != null) {
            int dataLength = tempCb.readableBytes();
            data = new byte[dataLength];
            tempCb.readBytes(data, 0, dataLength);
        }
        sendNotification(errorCode, errorSubCode, data);
    } else if (e.getCause() instanceof RejectedExecutionException) {
        log.warn("Could not process message: queue full");
        bgpController.activeSessionExceptionAdd(peerAddr, e.getCause().toString());
    } else {
        stopSessionTimers();
        log.error("Error while processing message from peer " + getPeerInfoString() + "state " + this.state);
        bgpController.closedSessionExceptionAdd(peerAddr, e.getCause().toString());
        ctx.getChannel().close();
    }
}
 
Example #14
Source File: ProgrammableTSOServer.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    if (e.getCause() instanceof ClosedChannelException) {
        return;
    }
    LOG.warn("TSOHandler: Unexpected exception from downstream.", e.getCause());
    Channels.close(e.getChannel());
}
 
Example #15
Source File: NettyRpcServerHandler.java    From voyage with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
		throws Exception {
	RpcRequest request = (RpcRequest) ctx.getAttachment();
	if (e.getCause() instanceof ReadTimeoutException) {
		// The connection was OK but there was no traffic for last period.
		logger.warn("Disconnecting due to no inbound traffic");
	} else {
		logger.error("", e);
	}
	e.getChannel().close().awaitUninterruptibly();
}
 
Example #16
Source File: NettyHandler.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        handler.caught(channel, e.getCause());
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example #17
Source File: NettyTransport.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    if (!lifecycle.started()) {
        // ignore
        return;
    }
    if (isCloseConnectionException(e.getCause())) {
        logger.trace("close connection exception caught on transport layer [{}], disconnecting from relevant node", e.getCause(), ctx.getChannel());
        // close the channel, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    } else if (isConnectException(e.getCause())) {
        logger.trace("connect exception caught on transport layer [{}]", e.getCause(), ctx.getChannel());
        // close the channel as safe measure, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    } else if (e.getCause() instanceof CancelledKeyException) {
        logger.trace("cancelled key exception caught on transport layer [{}], disconnecting from relevant node", e.getCause(), ctx.getChannel());
        // close the channel as safe measure, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    } else if (e.getCause() instanceof SizeHeaderFrameDecoder.HttpOnTransportException) {
        // in case we are able to return data, serialize the exception content and sent it back to the client
        if (ctx.getChannel().isOpen()) {
            ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(e.getCause().getMessage().getBytes(Charsets.UTF_8));
            ChannelFuture channelFuture = ctx.getChannel().write(buffer);
            channelFuture.addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    future.getChannel().close();
                }
            });
        }
    } else {
        logger.warn("exception caught on transport layer [{}], closing connection", e.getCause(), ctx.getChannel());
        // close the channel, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    }
}
 
Example #18
Source File: NetworkEventHandler.java    From android-netty with Apache License 2.0 5 votes vote down vote up
/** An exception is occurred! */
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
	LogByCodeLab.w(String.format("%s.exceptionCaught() Exception: %s", NetworkEventHandler.class.getSimpleName(), LogByCodeLab.getStringFromThrowable(e.getCause())));
	super.exceptionCaught(ctx, e);
	
	if(ctx.getChannel() != null && ctx.getChannel().isOpen()) {
		ctx.getChannel().close();
	} else {
		mService.scheduleToReconnect();
	}
}
 
Example #19
Source File: SessionHandler.java    From canal with Apache License 2.0 5 votes vote down vote up
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    logger.error("something goes wrong with channel:{}, exception={}",
        ctx.getChannel(),
        ExceptionUtils.getStackTrace(e.getCause()));

    ctx.getChannel().close();
}
 
Example #20
Source File: SessionHandler.java    From canal with Apache License 2.0 5 votes vote down vote up
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    logger.error("something goes wrong with channel:{}, exception={}",
        ctx.getChannel(),
        ExceptionUtils.getStackTrace(e.getCause()));

    ctx.getChannel().close();
}
 
Example #21
Source File: IsisChannelHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    controller = EasyMock.createNiceMock(Controller.class);
    isisProcess = EasyMock.createNiceMock(IsisProcess.class);
    channelHandlerContext = EasyMock.createNiceMock(ChannelHandlerContext.class);
    channelStateEvent = EasyMock.createNiceMock(ChannelStateEvent.class);
    exceptionEvent = EasyMock.createNiceMock(ExceptionEvent.class);
    messageEvent = EasyMock.createNiceMock(MessageEvent.class);
    isisMessage = EasyMock.createNiceMock(L1L2HelloPdu.class);
    isisMessage.setInterfaceIndex(2);
    isisChannelHandler = new IsisChannelHandler(controller, isisProcessList);
}
 
Example #22
Source File: NettyHandler.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        handler.caught(channel, e.getCause());
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example #23
Source File: NettyDispatcher.java    From ikasoa with MIT License 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
	// 捕获外部异常,并关闭通道
	closeChannel(ctx);
	// 写日志
	ctx.sendUpstream(e);
}
 
Example #24
Source File: NettyHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        handler.caught(channel, e.getCause());
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example #25
Source File: OspfInterfaceChannelHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests exceptionCaught() method.
 */
@Test(expected = Exception.class)
public void testExceptionCaught() throws Exception {
    channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
    ExceptionEvent exception = EasyMock.createMock(ExceptionEvent.class);
    ospfInterfaceChannelHandler.exceptionCaught(channelHandlerContext, exception);
    assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
 
Example #26
Source File: PinpointServerAcceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Channel channel = e.getChannel();
    final boolean accept = channelConnectedFilter.accept(channel);
    if (!accept) {
        return;
    } else {
        super.exceptionCaught(ctx, e);
    }
}
 
Example #27
Source File: NettyHandler.java    From anima with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(conf,ctx.getChannel(), handler);
    try {
        handler.caught(channel, e.getCause());
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example #28
Source File: NSQHandler.java    From TrendrrNSQClient with MIT License 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    log.warn("NSQHandler exception caught", e);

    e.getChannel().close();

    Connection con = (Connection)e.getChannel().getAttachment();
    if (con != null) {
        con._disconnected();
    } else {
        log.warn("No connection set for : " + e.getChannel());
    }
}
 
Example #29
Source File: NettyHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        handler.caught(channel, e.getCause());
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example #30
Source File: StormClientHandler.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.jboss.netty.channel.SimpleChannelUpstreamHandler#exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext,
 * org.jboss.netty.channel.ExceptionEvent)
 */
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent event) {
    Throwable cause = event.getCause();
    if (!being_closed.get()) {
        if (!(cause instanceof ConnectException)) {
            LOG.info("Connection failed:" + client.getRemoteAddr(), cause);
        }

        client.exceptionChannel(event.getChannel());
        client.reconnect();
    }
}