Java Code Examples for io.netty.channel.ChannelHandlerContext.close()

The following are Jave code examples for showing how to use close() of the io.netty.channel.ChannelHandlerContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: j1st-mqtt   File: SyncRedisHandler.java   View Source Code Vote up 6 votes
protected void onPubAck(ChannelHandlerContext ctx, MqttMessage msg) {
    if (!this.connected) {
        logger.debug("Protocol violation: Client {} must first sent a CONNECT message, now received PUBACK message, disconnect the client", this.clientId);
        ctx.close();
        return;
    }

    logger.debug("Message received: Received PUBACK message from client {} user {}", this.clientId, this.userName);

    MqttPacketIdVariableHeader variable = (MqttPacketIdVariableHeader) msg.variableHeader();
    int packetId = variable.packetId();

    // In the QoS 1 delivery protocol, the Sender
    // MUST treat the PUBLISH Packet as “unacknowledged” until it has received the corresponding
    // PUBACK packet from the receiver.
    logger.trace("Remove in-flight: Remove in-flight PUBLISH message {} for client {}", packetId, this.clientId);
    this.redis.removeInFlightMessage(this.clientId, packetId);
}
 
Example 2
Project: fastdfs-spring-boot   File: FastdfsHandler.java   View Source Code Vote up 6 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    ctx.close();

    Throwable error = translateException(cause);
    if (null != operation) {
        operation.caught(error);
        return;
    }

    // idle timeout.
    if (error instanceof FastdfsTimeoutException) {
        LOG.debug(error.getMessage(), error);
        return;
    }

    LOG.error(error.getMessage(), error);
}
 
Example 3
Project: graphiak   File: AuthHandler.java   View Source Code Vote up 5 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
        throws Exception {

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("userEventTriggered: {}", evt.getClass().getName());
    }

    // if the channel has been idle, close it
    if (evt == IdleStateEvent.FIRST_READER_IDLE_STATE_EVENT) {
        LOGGER.warn("No data received on channel, closing");
        ctx.close();
    }
}
 
Example 4
Project: rskj   File: FrameCodecHandler.java   View Source Code Vote up 5 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (channel.isDiscoveryMode()) {
        loggerNet.debug("FrameCodec failed: ", cause);
    } else {
        if (cause instanceof IOException) {
            loggerNet.info("FrameCodec failed: " + ctx.channel().remoteAddress() + "(" + cause.getMessage() + ")");
            loggerNet.debug("FrameCodec failed: " + ctx.channel().remoteAddress(), cause);
        } else {
            loggerNet.error("FrameCodec failed: ", cause);
        }
    }
    ctx.close();
}
 
Example 5
Project: happylifeplat-transaction   File: AbstractMessageDecoder.java   View Source Code Vote up 5 votes
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
    if (in.readableBytes() < AbstractMessageDecoder.MESSAGE_LENGTH) {
        return;
    }

    in.markReaderIndex();
    int messageLength = in.readInt();

    if (messageLength < 0) {
        ctx.close();
    }

    if (in.readableBytes() < messageLength) {
        in.resetReaderIndex();
    } else {
        byte[] messageBody = new byte[messageLength];
        in.readBytes(messageBody);

        try {
            Object obj = util.decode(messageBody);
            out.add(obj);
        } catch (IOException ex) {
            Logger.getLogger(AbstractMessageDecoder.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
 
Example 6
Project: dremio-oss   File: RpcExceptionHandler.java   View Source Code Vote up 5 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  if(!ctx.channel().isOpen() || cause.getMessage().equals("Connection reset by peer")){
    logger.warn("Exception occurred with closed channel.  Connection: {}", connection.getName(), cause);
    return;
  }else{
    logger.error("Exception in RPC communication.  Connection: {}.  Closing connection.", connection.getName(), cause);
    ctx.close();
  }
}
 
Example 7
Project: nitmproxy   File: TlsHandler.java   View Source Code Vote up 5 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    LOGGER.error("{} : exceptionCaught, message is {}", connectionInfo.toString(client), cause.getMessage());

    outboundChannel.close();
    ctx.close();
}
 
Example 8
Project: athena   File: MessageDecoder.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext context, Throwable cause) {
    log.error("Exception inside channel handling pipeline.", cause);
    context.close();
}
 
Example 9
Project: happylifeplat-transaction   File: NettyClientMessageHandler.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    cause.printStackTrace();
    ctx.close();
}
 
Example 10
Project: karate   File: FeatureServerHandler.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    cause.printStackTrace();
    ctx.close();
}
 
Example 11
Project: message-broker   File: AmqpDecoder.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    LOGGER.warn("Exception while handling request", cause);
    currentState = State.BAD_MESSAGE;
    ctx.close();
}
 
Example 12
Project: AgentX   File: Socks5Handler.java   View Source Code Vote up 4 votes
@Override
public void channelRead0(ChannelHandlerContext ctx, SocksRequest request) throws Exception {
    switch (request.protocolVersion()) {
        case SOCKS4a:
            log.warn("\tBad Handshake! (socks version not supported: 4)");
            ctx.write(new SocksInitResponse(SocksAuthScheme.UNKNOWN));
            if (ctx.channel().isActive()) {
                ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
            }
            break;
        case SOCKS5:
            switch (request.requestType()) {
                case INIT:
                    ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
                    ctx.write(new SocksInitResponse(SocksAuthScheme.NO_AUTH));
                    break;
                case AUTH:
                    ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
                    ctx.write(new SocksAuthResponse(SocksAuthStatus.SUCCESS));
                    break;
                case CMD:
                    switch (((SocksCmdRequest) request).cmdType()) {
                        case UDP:
                            // udp relay only supports IPv4 in this version
                            if (((SocksCmdRequest) request).addressType() != SocksAddressType.IPv4) {
                                ctx.write(new SocksCmdResponse(SocksCmdStatus.ADDRESS_NOT_SUPPORTED, ((SocksCmdRequest) request).addressType()));
                                log.warn("\tBad Handshake! (UDP request addr_type not support: {})", ((SocksCmdRequest) request).addressType());
                                ctx.close();
                                break;
                            }
                        case CONNECT:
                            ctx.pipeline().addLast(new XConnectHandler()); // handover
                            ctx.pipeline().remove(this);
                            ctx.fireChannelRead(request);
                            break;
                        default:
                            ctx.close();
                            log.warn("\tBad Handshake! (command not support: {})", ((SocksCmdRequest) request).cmdType());
                    }
                    break;
                case UNKNOWN:
                    log.warn("\tBad Handshake! (unknown request type: {})", request.requestType());
            }
            break;
        case UNKNOWN:
            log.warn("\tBad Handshake! (unknown protocol version: {}", request.protocolVersion());
            ctx.close();
            break;
    }
}
 
Example 13
Project: angel   File: MatrixTransportServerHandler.java   View Source Code Vote up 4 votes
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
  LOG.error("catch a exception ", cause);
  ctx.close();
}
 
Example 14
Project: angel   File: MatrixTransportClientHandler.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
  cause.printStackTrace();
  ctx.close();
}
 
Example 15
Project: athena   File: OvsdbJsonRpcHandler.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext context, Throwable cause) {
    log.error("Exception inside channel handling pipeline.", cause);
    context.close();
}
 
Example 16
Project: redant   File: PreHandleInterceptor.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    ctx.close();
    logger.error("ctx close,cause:",cause);
}
 
Example 17
Project: redant   File: ControllerDispatcher.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    ctx.close();
    logger.error("ctx close,cause:",cause);
}
 
Example 18
Project: kcp-netty   File: EchoServerHandler.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    // Close the connection when an exception is raised.
    cause.printStackTrace();
    ctx.close();
}
 
Example 19
Project: push   File: ClientHandler.java   View Source Code Vote up 4 votes
/**
 * 发生异常时调用
 */
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
	System.err.println("与服务器断开连接:" + cause);
	ctx.close();
}
 
Example 20
Project: netty_op   File: TimeClientInHandler.java   View Source Code Vote up 3 votes
/**
 *@description 接收服务器的响应数据
 *@time 创建时间:2017年7月24日下午2:31:09
 *@param ctx
 *@param msg
 *@throws Exception
 *@author dzn
 */
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    System.out.println("接收到服务器的响应数据为 :" + msg.toString());
    ctx.channel().attr(AttributeKey.valueOf("mykey")).set(msg);
    ctx.close();
}