All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rpc.turbo.transport.server.rpc.codec.ResponseEncoder Maven / Gradle / Ivy

The newest version!
package rpc.turbo.transport.server.rpc.codec;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import rpc.turbo.protocol.Response;
import rpc.turbo.serialization.Serializer;

public class ResponseEncoder extends MessageToByteEncoder {
	private static final Log logger = LogFactory.getLog(ResponseEncoder.class);

	private final Serializer serializer;

	public ResponseEncoder(Serializer serializer) {
		this.serializer = serializer;
	}

	protected void encode(ChannelHandlerContext ctx, Response response, ByteBuf buffer) throws Exception {
		serializer.writeResponse(buffer, response);
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		if (logger.isErrorEnabled()) {
			logger.error("Exception caught on " + ctx.channel(), cause);
		}

		ctx.channel().close();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy