Example usage for io.netty.handler.codec EncoderException EncoderException

List of usage examples for io.netty.handler.codec EncoderException EncoderException

Introduction

In this page you can find the example usage for io.netty.handler.codec EncoderException EncoderException.

Prototype

public EncoderException(String message, Throwable cause) 

Source Link

Document

Creates a new instance.

Usage

From source file:com.lambdaworks.redis.protocol.CommandEncoder.java

License:Apache License

private void encode(ChannelHandlerContext ctx, ByteBuf out, RedisCommand<?, ?, ?> command) {

    try {/* www .  j av  a  2  s.  c om*/
        out.markWriterIndex();
        command.encode(out);
    } catch (RuntimeException e) {
        out.resetWriterIndex();
        command.completeExceptionally(new EncoderException(
                "Cannot encode command. Please close the connection as the connection state may be out of sync.",
                e));
    }

    if (debugEnabled) {
        logger.debug("{} writing command {}", logPrefix(ctx.channel()), command);
        if (traceEnabled) {
            logger.trace("{} Sent: {}", logPrefix(ctx.channel()),
                    out.toString(Charset.defaultCharset()).trim());
        }
    }
}