Use ChannelInboundStreamHandlerAdapter in EchoClientHandler

This commit is contained in:
Trustin Lee 2012-05-31 09:04:19 -07:00
parent 2a63acef4d
commit 3584da2dad

View File

@ -17,10 +17,8 @@ package io.netty.example.echo;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBuffers;
import io.netty.channel.ChannelBufferHolder;
import io.netty.channel.ChannelBufferHolders;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInboundHandlerContext;
import io.netty.channel.ChannelInboundStreamHandlerAdapter;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -30,7 +28,7 @@ import java.util.logging.Logger;
* traffic between the echo client and server by sending the first message to
* the server.
*/
public class EchoClientHandler extends ChannelInboundHandlerAdapter<Byte> {
public class EchoClientHandler extends ChannelInboundStreamHandlerAdapter {
private static final Logger logger = Logger.getLogger(
EchoClientHandler.class.getName());
@ -50,23 +48,16 @@ public class EchoClientHandler extends ChannelInboundHandlerAdapter<Byte> {
}
}
@Override
public ChannelBufferHolder<Byte> newInboundBuffer(ChannelInboundHandlerContext<Byte> ctx) {
return ChannelBufferHolders.byteBuffer();
}
@Override
public void channelActive(ChannelInboundHandlerContext<Byte> ctx) {
ctx.write(firstMessage);
}
@Override
public void inboundBufferUpdated(ChannelInboundHandlerContext<Byte> ctx) {
ChannelBuffer in = ctx.inbound().byteBuffer();
public void inboundBufferUpdated(ChannelInboundHandlerContext<Byte> ctx, ChannelBuffer in) {
ChannelBuffer out = ctx.nextOutboundByteBuffer();
out.discardReadBytes();
out.writeBytes(in);
in.discardReadBytes();
ctx.flush();
}