Java Code Examples for org.jboss.netty.channel.ExceptionEvent

The following examples show how to use org.jboss.netty.channel.ExceptionEvent. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: hadoop   Source File: ShuffleHandler.java    License: 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 Project: big-c   Source File: ShuffleHandler.java    License: 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 3
Source Project: nfs-client-java   Source File: ClientIOHandler.java    License: 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 4
Source Project: parallec   Source File: TcpWorker.java    License: 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 5
Source Project: parallec   Source File: UdpWorker.java    License: 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 6
Source Project: ck   Source File: NettyAsyncHttpProvider.java    License: 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 7
Source Project: tez   Source File: ShuffleHandler.java    License: 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 8
Source Project: onos   Source File: OspfInterfaceChannelHandler.java    License: 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 9
Source Project: onos   Source File: IsisChannelHandler.java    License: 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 10
Source Project: RDFS   Source File: ShuffleHandler.java    License: 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 11
Source Project: dubbo-2.6.5   Source File: NettyHandler.java    License: 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 Project: jstorm   Source File: StormServerHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    // removeFailureCounter(e.getChannel());
    if (e.getChannel() != null) {
        LOG.info("Channel occur exception {}, cause={}", e.getChannel().getRemoteAddress(), e.getCause());
    }

    server.closeChannel(e.getChannel());
}
 
Example 13
Source Project: voyage   Source File: NettyRpcServerHandler.java    License: 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 14
Source Project: Elasticsearch   Source File: NettyTransport.java    License: 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 15
Source Project: dubbox   Source File: NettyHandler.java    License: 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 16
Source Project: dubbox-hystrix   Source File: NettyHandler.java    License: 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 Project: hadoop   Source File: TestDelegationTokenRemoteFetcher.java    License: 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 18
Source Project: phoenix-omid   Source File: TSOChannelHandler.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    if (e.getCause() instanceof ClosedChannelException) {
        LOG.warn("ClosedChannelException caught. Cause: ", e.getCause());
        return;
    }
    LOG.warn("Unexpected exception from downstream. Closing channel {} {}", ctx.getChannel(), e.getCause());
    ctx.getChannel().close();
}
 
Example 19
Source Project: phoenix-omid   Source File: TSOClientRaw.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    LOG.info("Exception received", e.getCause());
    try {
        SettableFuture<Response> future = responseQueue.take();
        future.setException(e.getCause());
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        LOG.warn("Interrupted handling exception", ie);
    }
}
 
Example 20
Source Project: phoenix-omid   Source File: ProgrammableTSOServer.java    License: 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 21
Source Project: big-c   Source File: TestDelegationTokenRemoteFetcher.java    License: 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 22
Source Project: dubbo3   Source File: NettyHandler.java    License: 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 Project: ikasoa   Source File: NettyDispatcher.java    License: 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 Project: dubbox   Source File: NettyHandler.java    License: 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 Project: anima   Source File: NettyHandler.java    License: 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 26
Source Project: TrendrrNSQClient   Source File: NSQHandler.java    License: 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 27
Source Project: dubbox   Source File: NettyHandler.java    License: 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 28
Source Project: jstorm   Source File: StormClientHandler.java    License: 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();
    }
}
 
Example 29
Source Project: pinpoint   Source File: PinpointServerAcceptor.java    License: 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 30
Source Project: onos   Source File: OspfInterfaceChannelHandlerTest.java    License: 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()));
}