diff --git a/transport/src/main/java/io/netty/channel/socket/nio2/AsyncServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncServerSocketChannel.java index 81cc8802e9..74a804a52a 100755 --- a/transport/src/main/java/io/netty/channel/socket/nio2/AsyncServerSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncServerSocketChannel.java @@ -121,7 +121,7 @@ public class AsyncServerSocketChannel extends AbstractAsyncChannel implements Se channel.javaChannel().accept(channel, this); // create the socket add it to the buffer and fire the event - channel.pipeline().inboundMessageBuffer().add(new AsyncSocketchannel(channel, null, ch)); + channel.pipeline().inboundMessageBuffer().add(new AsyncSocketChannel(channel, null, ch)); channel.pipeline().fireInboundBufferUpdated(); } diff --git a/transport/src/main/java/io/netty/channel/socket/nio2/AsyncSocketchannel.java b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncSocketchannel.java index 60da25504a..0308eaf9e4 100755 --- a/transport/src/main/java/io/netty/channel/socket/nio2/AsyncSocketchannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncSocketchannel.java @@ -32,11 +32,11 @@ import java.nio.channels.AsynchronousSocketChannel; import java.nio.channels.CompletionHandler; import java.util.concurrent.atomic.AtomicBoolean; -public class AsyncSocketchannel extends AbstractAsyncChannel { +public class AsyncSocketChannel extends AbstractAsyncChannel { - private static final CompletionHandler CONNECT_HANDLER = new ConnectHandler(); - private static final CompletionHandler READ_HANDLER = new ReadHandler(); - private static final CompletionHandler WRITE_HANDLER = new WriteHandler(); + private static final CompletionHandler CONNECT_HANDLER = new ConnectHandler(); + private static final CompletionHandler READ_HANDLER = new ReadHandler(); + private static final CompletionHandler WRITE_HANDLER = new WriteHandler(); private static final ChannelStateHandler READ_START_HANDLER = new ChannelStateHandlerAdapter() { @Override @@ -45,7 +45,7 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { super.channelActive(ctx); // once the channel is active, the first read is scheduled - AsyncSocketchannel.read((AsyncSocketchannel)ctx.channel()); + AsyncSocketChannel.read((AsyncSocketChannel)ctx.channel()); } finally { ctx.pipeline().remove(this); @@ -58,11 +58,11 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { private final AtomicBoolean flushing = new AtomicBoolean(false); private volatile AsyncSocketChannelConfig config; - public AsyncSocketchannel() { + public AsyncSocketChannel() { this(null, null, null); } - public AsyncSocketchannel(AsyncServerSocketChannel parent, Integer id, AsynchronousSocketChannel channel) { + public AsyncSocketChannel(AsyncServerSocketChannel parent, Integer id, AsynchronousSocketChannel channel) { super(parent, id); this.ch = channel; if (ch != null) { @@ -133,10 +133,10 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { } /** - * Trigger a read from the {@link AsyncSocketchannel} + * Trigger a read from the {@link AsyncSocketChannel} * */ - private static void read(AsyncSocketchannel channel) { + private static void read(AsyncSocketChannel channel) { ByteBuf byteBuf = channel.pipeline().inboundByteBuffer(); expandReadBuffer(byteBuf); @@ -189,10 +189,10 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { } - private static final class WriteHandler implements CompletionHandler { + private static final class WriteHandler implements CompletionHandler { @Override - public void completed(Integer result, AsyncSocketchannel channel) { + public void completed(Integer result, AsyncSocketChannel channel) { ByteBuf buf = channel.pipeline().outboundByteBuffer(); if (result > 0) { @@ -213,7 +213,7 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { } @Override - public void failed(Throwable cause, AsyncSocketchannel channel) { + public void failed(Throwable cause, AsyncSocketChannel channel) { ByteBuf buf = channel.pipeline().outboundByteBuffer(); if (!buf.readable()) { buf.discardReadBytes(); @@ -229,10 +229,10 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { } } - private static final class ReadHandler implements CompletionHandler { + private static final class ReadHandler implements CompletionHandler { @Override - public void completed(Integer result, AsyncSocketchannel channel) { + public void completed(Integer result, AsyncSocketChannel channel) { assert channel.eventLoop().inEventLoop(); final ChannelPipeline pipeline = channel.pipeline(); @@ -273,35 +273,35 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { channel.close(channel.unsafe().voidFuture()); } else { // start the next read - AsyncSocketchannel.read(channel); + AsyncSocketChannel.read(channel); } } } @Override - public void failed(Throwable t, AsyncSocketchannel channel) { + public void failed(Throwable t, AsyncSocketChannel channel) { channel.pipeline().fireExceptionCaught(t); if (t instanceof IOException) { channel.close(channel.unsafe().voidFuture()); } else { // start the next read - AsyncSocketchannel.read(channel); + AsyncSocketChannel.read(channel); } } } - private static final class ConnectHandler implements CompletionHandler { + private static final class ConnectHandler implements CompletionHandler { @Override - public void completed(Void result, AsyncSocketchannel channel) { + public void completed(Void result, AsyncSocketChannel channel) { ((AsyncUnsafe) channel.unsafe()).connectSuccess(); // start reading from channel - AsyncSocketchannel.read(channel); + AsyncSocketChannel.read(channel); } @Override - public void failed(Throwable exc, AsyncSocketchannel channel) { + public void failed(Throwable exc, AsyncSocketChannel channel) { ((AsyncUnsafe) channel.unsafe()).connectFailed(exc); } } diff --git a/transport/src/test/java/io/netty/channel/AsyncTransportTest.java b/transport/src/test/java/io/netty/channel/AsyncTransportTest.java index a8153e26f1..e5ea2631d6 100755 --- a/transport/src/test/java/io/netty/channel/AsyncTransportTest.java +++ b/transport/src/test/java/io/netty/channel/AsyncTransportTest.java @@ -10,25 +10,25 @@ import io.netty.channel.ChannelInboundByteHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.nio2.AsyncEventLoop; import io.netty.channel.socket.nio2.AsyncServerSocketChannel; -import io.netty.channel.socket.nio2.AsyncSocketchannel; -import io.netty.util.CharsetUtil; +import io.netty.channel.socket.nio2.AsyncSocketChannel; public class AsyncTransportTest { public static void main(String args[]) { + AsyncEventLoop loop = new AsyncEventLoop(); // Configure a test server ServerBootstrap sb = new ServerBootstrap(); - sb.eventLoop(new AsyncEventLoop(), new AsyncEventLoop()) + sb.eventLoop(loop, loop) .channel(new AsyncServerSocketChannel()) - .localAddress(new InetSocketAddress(9999)) - .childHandler(new ChannelInitializer() { + .localAddress(new InetSocketAddress(9191)) + .childHandler(new ChannelInitializer() { @Override - public void initChannel(AsyncSocketchannel ch) throws Exception { + public void initChannel(AsyncSocketChannel ch) throws Exception { ch.pipeline().addLast(new ChannelInboundByteHandlerAdapter() { @Override public void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) throws Exception { - System.out.print(in.toString(CharsetUtil.US_ASCII)); + ctx.write(in.slice()); } }); }