From f8ef5d5d782383970e2bdf35c978e872242817b3 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 14 Jun 2012 21:02:47 +0200 Subject: [PATCH] Next round for async channel api support a.k.a nio2. See See #396 --- .../java/io/netty/bootstrap/Bootstrap.java | 0 .../io/netty/bootstrap/ServerBootstrap.java | 13 +- .../java/io/netty/bootstrap/package-info.java | 0 .../io/netty/channel/AbstractChannel.java | 0 .../netty/channel/AbstractServerChannel.java | 0 .../channel/BlockingOperationException.java | 0 .../main/java/io/netty/channel/Channel.java | 0 .../java/io/netty/channel/ChannelConfig.java | 0 .../io/netty/channel/ChannelException.java | 0 .../java/io/netty/channel/ChannelFuture.java | 0 .../channel/ChannelFutureAggregator.java | 0 .../netty/channel/ChannelFutureFactory.java | 0 .../netty/channel/ChannelFutureListener.java | 0 .../ChannelFutureProgressListener.java | 0 .../java/io/netty/channel/ChannelHandler.java | 0 .../netty/channel/ChannelHandlerAdapter.java | 0 .../netty/channel/ChannelHandlerContext.java | 0 .../ChannelHandlerLifeCycleException.java | 0 .../io/netty/channel/ChannelHandlerType.java | 0 .../channel/ChannelInboundByteHandler.java | 0 .../ChannelInboundByteHandlerAdapter.java | 0 .../netty/channel/ChannelInboundHandler.java | 0 .../channel/ChannelInboundHandlerAdapter.java | 0 .../netty/channel/ChannelInboundInvoker.java | 0 .../channel/ChannelInboundMessageHandler.java | 0 .../ChannelInboundMessageHandlerAdapter.java | 0 .../io/netty/channel/ChannelInitializer.java | 0 .../channel/ChannelOperationHandler.java | 0 .../ChannelOperationHandlerAdapter.java | 0 .../java/io/netty/channel/ChannelOption.java | 0 .../channel/ChannelOutboundByteHandler.java | 0 .../ChannelOutboundByteHandlerAdapter.java | 0 .../netty/channel/ChannelOutboundHandler.java | 0 .../ChannelOutboundHandlerAdapter.java | 0 .../netty/channel/ChannelOutboundInvoker.java | 0 .../ChannelOutboundMessageHandler.java | 0 .../ChannelOutboundMessageHandlerAdapter.java | 0 .../io/netty/channel/ChannelPipeline.java | 0 .../channel/ChannelPipelineException.java | 0 .../io/netty/channel/ChannelStateHandler.java | 0 .../channel/ChannelStateHandlerAdapter.java | 0 .../netty/channel/CombinedChannelHandler.java | 0 .../netty/channel/CompleteChannelFuture.java | 0 .../netty/channel/DefaultChannelConfig.java | 0 .../netty/channel/DefaultChannelFuture.java | 0 .../channel/DefaultChannelHandlerContext.java | 0 .../netty/channel/DefaultChannelPipeline.java | 0 ...efaultChannelPipelineModificationTask.java | 0 .../channel/DefaultChildEventExecutor.java | 0 .../netty/channel/DefaultEventExecutor.java | 0 .../java/io/netty/channel/EventExecutor.java | 0 .../main/java/io/netty/channel/EventLoop.java | 0 .../io/netty/channel/EventLoopException.java | 0 .../io/netty/channel/FailedChannelFuture.java | 0 .../channel/MultithreadEventExecutor.java | 0 .../netty/channel/MultithreadEventLoop.java | 0 .../netty/channel/NoSuchBufferException.java | 0 .../java/io/netty/channel/ServerChannel.java | 0 .../channel/SingleThreadEventExecutor.java | 0 .../netty/channel/SingleThreadEventLoop.java | 0 .../netty/channel/SucceededChannelFuture.java | 0 .../io/netty/channel/VoidChannelFuture.java | 0 .../embedded/AbstractEmbeddedChannel.java | 0 .../channel/embedded/EmbeddedByteChannel.java | 0 .../channel/embedded/EmbeddedEventLoop.java | 0 .../embedded/EmbeddedMessageChannel.java | 0 .../embedded/EmbeddedSocketAddress.java | 0 .../netty/channel/embedded/package-info.java | 0 .../io/netty/channel/group/ChannelGroup.java | 0 .../channel/group/ChannelGroupFuture.java | 0 .../group/ChannelGroupFutureListener.java | 0 .../netty/channel/group/CombinedIterator.java | 0 .../channel/group/DefaultChannelGroup.java | 0 .../group/DefaultChannelGroupFuture.java | 0 .../io/netty/channel/group/package-info.java | 0 .../io/netty/channel/local/LocalAddress.java | 0 .../io/netty/channel/local/LocalChannel.java | 0 .../channel/local/LocalChannelRegistry.java | 0 .../channel/local/LocalChildEventLoop.java | 0 .../netty/channel/local/LocalEventLoop.java | 0 .../channel/local/LocalServerChannel.java | 0 .../io/netty/channel/local/package-info.java | 0 .../java/io/netty/channel/package-info.java | 0 .../netty/channel/socket/DatagramChannel.java | 0 .../channel/socket/DatagramChannelConfig.java | 0 .../netty/channel/socket/DatagramPacket.java | 0 .../socket/DefaultDatagramChannelConfig.java | 0 .../DefaultServerSocketChannelConfig.java | 0 .../socket/DefaultSocketChannelConfig.java | 0 .../socket/InternetProtocolFamily.java | 0 .../channel/socket/ServerSocketChannel.java | 0 .../socket/ServerSocketChannelConfig.java | 0 .../netty/channel/socket/SocketChannel.java | 0 .../channel/socket/SocketChannelConfig.java | 0 .../socket/nio/AbstractNioByteChannel.java | 0 .../socket/nio/AbstractNioChannel.java | 0 .../socket/nio/AbstractNioMessageChannel.java | 0 .../channel/socket/nio/NioChildEventLoop.java | 0 .../socket/nio/NioDatagramChannel.java | 0 .../socket/nio/NioDatagramChannelConfig.java | 0 .../channel/socket/nio/NioEventLoop.java | 0 .../socket/nio/NioServerSocketChannel.java | 0 .../channel/socket/nio/NioSocketChannel.java | 0 .../socket/nio/ProtocolFamilyConverter.java | 0 .../channel/socket/nio/SelectorUtil.java | 0 .../channel/socket/nio/package-info.java | 0 .../socket/nio2/AbstractAsyncChannel.java | 18 +- .../socket/nio2/AsyncChildEventLoop.java | 51 ++++ .../channel/socket/nio2/AsyncEventLoop.java | 41 +++ .../socket/nio2/AsyncNetworkChannel.java | 52 ++++ .../socket/nio2/AsyncServerSocketChannel.java | 26 +- .../nio2/AsyncServerSocketChannelConfig.java | 138 ++++++++++ .../socket/nio2/AsyncSocketChannelConfig.java | 237 ++++++++++++++++++ .../socket/nio2/AsyncSocketchannel.java | 77 ++++-- .../channel/socket/nio2/package-info.java | 0 .../socket/oio/AbstractOioByteChannel.java | 0 .../socket/oio/AbstractOioChannel.java | 0 .../socket/oio/AbstractOioMessageChannel.java | 0 .../channel/socket/oio/OioChildEventLoop.java | 0 .../socket/oio/OioDatagramChannel.java | 0 .../channel/socket/oio/OioEventLoop.java | 0 .../socket/oio/OioServerSocketChannel.java | 0 .../channel/socket/oio/OioSocketChannel.java | 0 .../channel/socket/oio/package-info.java | 0 .../io/netty/channel/socket/package-info.java | 0 .../io/netty/channel/AsyncTransportTest.java | 42 ++++ .../channel/CompleteChannelFutureTest.java | 0 .../channel/DefaultChannelPipelineTest.java | 0 .../channel/FailedChannelFutureTest.java | 0 .../channel/SingleThreadEventLoopTest.java | 0 .../channel/SucceededChannelFutureTest.java | 0 .../local/LocalChannelRegistryTest.java | 0 .../local/LocalTransportThreadModelTest.java | 0 133 files changed, 655 insertions(+), 40 deletions(-) mode change 100644 => 100755 transport/src/main/java/io/netty/bootstrap/Bootstrap.java mode change 100644 => 100755 transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java mode change 100644 => 100755 transport/src/main/java/io/netty/bootstrap/package-info.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/AbstractChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/AbstractServerChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/BlockingOperationException.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/Channel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelConfig.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelException.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelFuture.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelFutureAggregator.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelFutureFactory.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelFutureListener.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelFutureProgressListener.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelHandler.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelHandlerAdapter.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelHandlerContext.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelHandlerLifeCycleException.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelHandlerType.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelInboundByteHandler.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelInboundByteHandlerAdapter.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelInboundHandler.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelInboundHandlerAdapter.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelInboundInvoker.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelInboundMessageHandler.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelInboundMessageHandlerAdapter.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelInitializer.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelOperationHandler.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelOperationHandlerAdapter.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelOption.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelOutboundByteHandler.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelOutboundByteHandlerAdapter.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelOutboundHandler.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelOutboundHandlerAdapter.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelOutboundInvoker.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelOutboundMessageHandler.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelOutboundMessageHandlerAdapter.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelPipeline.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelPipelineException.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelStateHandler.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ChannelStateHandlerAdapter.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/CombinedChannelHandler.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/CompleteChannelFuture.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/DefaultChannelConfig.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/DefaultChannelFuture.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/DefaultChannelPipelineModificationTask.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/DefaultChildEventExecutor.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/DefaultEventExecutor.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/EventExecutor.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/EventLoop.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/EventLoopException.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/FailedChannelFuture.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/MultithreadEventExecutor.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/MultithreadEventLoop.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/NoSuchBufferException.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/ServerChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/SingleThreadEventExecutor.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/SingleThreadEventLoop.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/SucceededChannelFuture.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/VoidChannelFuture.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/embedded/AbstractEmbeddedChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/embedded/EmbeddedByteChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/embedded/EmbeddedEventLoop.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/embedded/EmbeddedMessageChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/embedded/EmbeddedSocketAddress.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/embedded/package-info.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/group/ChannelGroup.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/group/ChannelGroupFuture.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/group/ChannelGroupFutureListener.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/group/CombinedIterator.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/group/package-info.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/local/LocalAddress.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/local/LocalChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/local/LocalChannelRegistry.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/local/LocalChildEventLoop.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/local/LocalEventLoop.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/local/LocalServerChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/local/package-info.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/package-info.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/DatagramChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/DatagramChannelConfig.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/DatagramPacket.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/DefaultDatagramChannelConfig.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/DefaultServerSocketChannelConfig.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/DefaultSocketChannelConfig.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/InternetProtocolFamily.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/ServerSocketChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/ServerSocketChannelConfig.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/SocketChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/SocketChannelConfig.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/AbstractNioByteChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/AbstractNioMessageChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/NioChildEventLoop.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannelConfig.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/ProtocolFamilyConverter.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/SelectorUtil.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio/package-info.java create mode 100755 transport/src/main/java/io/netty/channel/socket/nio2/AsyncChildEventLoop.java create mode 100755 transport/src/main/java/io/netty/channel/socket/nio2/AsyncEventLoop.java create mode 100755 transport/src/main/java/io/netty/channel/socket/nio2/AsyncNetworkChannel.java create mode 100755 transport/src/main/java/io/netty/channel/socket/nio2/AsyncServerSocketChannelConfig.java create mode 100755 transport/src/main/java/io/netty/channel/socket/nio2/AsyncSocketChannelConfig.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/nio2/package-info.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/oio/AbstractOioChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/oio/AbstractOioMessageChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/oio/OioChildEventLoop.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/oio/OioEventLoop.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/oio/package-info.java mode change 100644 => 100755 transport/src/main/java/io/netty/channel/socket/package-info.java create mode 100755 transport/src/test/java/io/netty/channel/AsyncTransportTest.java mode change 100644 => 100755 transport/src/test/java/io/netty/channel/CompleteChannelFutureTest.java mode change 100644 => 100755 transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java mode change 100644 => 100755 transport/src/test/java/io/netty/channel/FailedChannelFutureTest.java mode change 100644 => 100755 transport/src/test/java/io/netty/channel/SingleThreadEventLoopTest.java mode change 100644 => 100755 transport/src/test/java/io/netty/channel/SucceededChannelFutureTest.java mode change 100644 => 100755 transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java mode change 100644 => 100755 transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java diff --git a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java old mode 100644 new mode 100755 index 15c076b64b..098ed8a1a3 --- a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java @@ -167,13 +167,6 @@ public class ServerBootstrap { return future; } - try { - channel.config().setOptions(parentOptions); - } catch (Exception e) { - future.setFailure(e); - return future; - } - ChannelPipeline p = channel.pipeline(); if (handler != null) { p.addLast(handler); @@ -185,6 +178,12 @@ public class ServerBootstrap { future.setFailure(f.cause()); return future; } + try { + channel.config().setOptions(parentOptions); + } catch (Exception e) { + future.setFailure(e); + return future; + } if (!channel.isOpen()) { // Registration was successful but the channel was closed due to some failure in diff --git a/transport/src/main/java/io/netty/bootstrap/package-info.java b/transport/src/main/java/io/netty/bootstrap/package-info.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/AbstractChannel.java b/transport/src/main/java/io/netty/channel/AbstractChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/AbstractServerChannel.java b/transport/src/main/java/io/netty/channel/AbstractServerChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/BlockingOperationException.java b/transport/src/main/java/io/netty/channel/BlockingOperationException.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/Channel.java b/transport/src/main/java/io/netty/channel/Channel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelConfig.java b/transport/src/main/java/io/netty/channel/ChannelConfig.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelException.java b/transport/src/main/java/io/netty/channel/ChannelException.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelFuture.java b/transport/src/main/java/io/netty/channel/ChannelFuture.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelFutureAggregator.java b/transport/src/main/java/io/netty/channel/ChannelFutureAggregator.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelFutureFactory.java b/transport/src/main/java/io/netty/channel/ChannelFutureFactory.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelFutureListener.java b/transport/src/main/java/io/netty/channel/ChannelFutureListener.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelFutureProgressListener.java b/transport/src/main/java/io/netty/channel/ChannelFutureProgressListener.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelHandler.java b/transport/src/main/java/io/netty/channel/ChannelHandler.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelHandlerAdapter.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/ChannelHandlerContext.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelHandlerLifeCycleException.java b/transport/src/main/java/io/netty/channel/ChannelHandlerLifeCycleException.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelHandlerType.java b/transport/src/main/java/io/netty/channel/ChannelHandlerType.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelInboundByteHandler.java b/transport/src/main/java/io/netty/channel/ChannelInboundByteHandler.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelInboundByteHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelInboundByteHandlerAdapter.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelInboundHandler.java b/transport/src/main/java/io/netty/channel/ChannelInboundHandler.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelInboundHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelInboundHandlerAdapter.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelInboundInvoker.java b/transport/src/main/java/io/netty/channel/ChannelInboundInvoker.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelInboundMessageHandler.java b/transport/src/main/java/io/netty/channel/ChannelInboundMessageHandler.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelInboundMessageHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelInboundMessageHandlerAdapter.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelInitializer.java b/transport/src/main/java/io/netty/channel/ChannelInitializer.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelOperationHandler.java b/transport/src/main/java/io/netty/channel/ChannelOperationHandler.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelOperationHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelOperationHandlerAdapter.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelOption.java b/transport/src/main/java/io/netty/channel/ChannelOption.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundByteHandler.java b/transport/src/main/java/io/netty/channel/ChannelOutboundByteHandler.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundByteHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelOutboundByteHandlerAdapter.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundHandler.java b/transport/src/main/java/io/netty/channel/ChannelOutboundHandler.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelOutboundHandlerAdapter.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundInvoker.java b/transport/src/main/java/io/netty/channel/ChannelOutboundInvoker.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundMessageHandler.java b/transport/src/main/java/io/netty/channel/ChannelOutboundMessageHandler.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundMessageHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelOutboundMessageHandlerAdapter.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelPipeline.java b/transport/src/main/java/io/netty/channel/ChannelPipeline.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelPipelineException.java b/transport/src/main/java/io/netty/channel/ChannelPipelineException.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelStateHandler.java b/transport/src/main/java/io/netty/channel/ChannelStateHandler.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ChannelStateHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelStateHandlerAdapter.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/CombinedChannelHandler.java b/transport/src/main/java/io/netty/channel/CombinedChannelHandler.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/CompleteChannelFuture.java b/transport/src/main/java/io/netty/channel/CompleteChannelFuture.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelConfig.java b/transport/src/main/java/io/netty/channel/DefaultChannelConfig.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelFuture.java b/transport/src/main/java/io/netty/channel/DefaultChannelFuture.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelPipelineModificationTask.java b/transport/src/main/java/io/netty/channel/DefaultChannelPipelineModificationTask.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/DefaultChildEventExecutor.java b/transport/src/main/java/io/netty/channel/DefaultChildEventExecutor.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/DefaultEventExecutor.java b/transport/src/main/java/io/netty/channel/DefaultEventExecutor.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/EventExecutor.java b/transport/src/main/java/io/netty/channel/EventExecutor.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/EventLoop.java b/transport/src/main/java/io/netty/channel/EventLoop.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/EventLoopException.java b/transport/src/main/java/io/netty/channel/EventLoopException.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/FailedChannelFuture.java b/transport/src/main/java/io/netty/channel/FailedChannelFuture.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/MultithreadEventExecutor.java b/transport/src/main/java/io/netty/channel/MultithreadEventExecutor.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/MultithreadEventLoop.java b/transport/src/main/java/io/netty/channel/MultithreadEventLoop.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/NoSuchBufferException.java b/transport/src/main/java/io/netty/channel/NoSuchBufferException.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/ServerChannel.java b/transport/src/main/java/io/netty/channel/ServerChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/SingleThreadEventExecutor.java b/transport/src/main/java/io/netty/channel/SingleThreadEventExecutor.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/SingleThreadEventLoop.java b/transport/src/main/java/io/netty/channel/SingleThreadEventLoop.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/SucceededChannelFuture.java b/transport/src/main/java/io/netty/channel/SucceededChannelFuture.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/VoidChannelFuture.java b/transport/src/main/java/io/netty/channel/VoidChannelFuture.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/embedded/AbstractEmbeddedChannel.java b/transport/src/main/java/io/netty/channel/embedded/AbstractEmbeddedChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/embedded/EmbeddedByteChannel.java b/transport/src/main/java/io/netty/channel/embedded/EmbeddedByteChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/embedded/EmbeddedEventLoop.java b/transport/src/main/java/io/netty/channel/embedded/EmbeddedEventLoop.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/embedded/EmbeddedMessageChannel.java b/transport/src/main/java/io/netty/channel/embedded/EmbeddedMessageChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/embedded/EmbeddedSocketAddress.java b/transport/src/main/java/io/netty/channel/embedded/EmbeddedSocketAddress.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/embedded/package-info.java b/transport/src/main/java/io/netty/channel/embedded/package-info.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/group/ChannelGroup.java b/transport/src/main/java/io/netty/channel/group/ChannelGroup.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/group/ChannelGroupFuture.java b/transport/src/main/java/io/netty/channel/group/ChannelGroupFuture.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/group/ChannelGroupFutureListener.java b/transport/src/main/java/io/netty/channel/group/ChannelGroupFutureListener.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/group/CombinedIterator.java b/transport/src/main/java/io/netty/channel/group/CombinedIterator.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/group/package-info.java b/transport/src/main/java/io/netty/channel/group/package-info.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/local/LocalAddress.java b/transport/src/main/java/io/netty/channel/local/LocalAddress.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/local/LocalChannel.java b/transport/src/main/java/io/netty/channel/local/LocalChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/local/LocalChannelRegistry.java b/transport/src/main/java/io/netty/channel/local/LocalChannelRegistry.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/local/LocalChildEventLoop.java b/transport/src/main/java/io/netty/channel/local/LocalChildEventLoop.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/local/LocalEventLoop.java b/transport/src/main/java/io/netty/channel/local/LocalEventLoop.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java b/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/local/package-info.java b/transport/src/main/java/io/netty/channel/local/package-info.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/package-info.java b/transport/src/main/java/io/netty/channel/package-info.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/DatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/DatagramChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/DatagramChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/DatagramChannelConfig.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/DatagramPacket.java b/transport/src/main/java/io/netty/channel/socket/DatagramPacket.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/DefaultDatagramChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/DefaultDatagramChannelConfig.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/DefaultServerSocketChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/DefaultServerSocketChannelConfig.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/DefaultSocketChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/DefaultSocketChannelConfig.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/InternetProtocolFamily.java b/transport/src/main/java/io/netty/channel/socket/InternetProtocolFamily.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/ServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/ServerSocketChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/ServerSocketChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/ServerSocketChannelConfig.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/SocketChannel.java b/transport/src/main/java/io/netty/channel/socket/SocketChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/SocketChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/SocketChannelConfig.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioByteChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioByteChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioMessageChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioMessageChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioChildEventLoop.java b/transport/src/main/java/io/netty/channel/socket/nio/NioChildEventLoop.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannelConfig.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java b/transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/ProtocolFamilyConverter.java b/transport/src/main/java/io/netty/channel/socket/nio/ProtocolFamilyConverter.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/SelectorUtil.java b/transport/src/main/java/io/netty/channel/socket/nio/SelectorUtil.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio/package-info.java b/transport/src/main/java/io/netty/channel/socket/nio/package-info.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/nio2/AbstractAsyncChannel.java b/transport/src/main/java/io/netty/channel/socket/nio2/AbstractAsyncChannel.java index f2371239b1..01a85958bb 100755 --- a/transport/src/main/java/io/netty/channel/socket/nio2/AbstractAsyncChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio2/AbstractAsyncChannel.java @@ -17,7 +17,6 @@ package io.netty.channel.socket.nio2; import io.netty.channel.AbstractChannel; import io.netty.channel.Channel; -import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelFuture; import io.netty.channel.EventLoop; @@ -65,24 +64,12 @@ public abstract class AbstractAsyncChannel extends AbstractChannel { return ch; } - @Override - public ChannelConfig config() { - // TODO: Fix me - return null; - } @Override public boolean isOpen() { return ch == null || ch.isOpen(); } - @Override - protected boolean isCompatible(EventLoop loop) { - // TODO: Fix me - return true; - } - - @Override protected void doDeregister() throws Exception { throw new UnsupportedOperationException("Deregistration is not supported by AbstractAsyncChannel"); @@ -93,6 +80,11 @@ public abstract class AbstractAsyncChannel extends AbstractChannel { return new AsyncUnsafe(); } + @Override + protected boolean isCompatible(EventLoop loop) { + return loop instanceof AsyncChildEventLoop; + } + protected class AsyncUnsafe extends AbstractUnsafe { @Override diff --git a/transport/src/main/java/io/netty/channel/socket/nio2/AsyncChildEventLoop.java b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncChildEventLoop.java new file mode 100755 index 0000000000..779f075dd3 --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncChildEventLoop.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.socket.nio2; + +import io.netty.channel.SingleThreadEventLoop; + +import java.util.concurrent.ThreadFactory; + +final class AsyncChildEventLoop extends SingleThreadEventLoop { + + AsyncChildEventLoop(ThreadFactory threadFactory) { + super(threadFactory); + } + + @Override + protected void run() { + for (;;) { + Runnable task; + try { + task = takeTask(); + task.run(); + } catch (InterruptedException e) { + // Waken up by interruptThread() + } + + if (isShutdown() && peekTask() == null) { + break; + } + } + } + + @Override + protected void wakeup(boolean inEventLoop) { + if (!inEventLoop) { + interruptThread(); + } + } +} diff --git a/transport/src/main/java/io/netty/channel/socket/nio2/AsyncEventLoop.java b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncEventLoop.java new file mode 100755 index 0000000000..8c4ecd40b5 --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncEventLoop.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.socket.nio2; + +import io.netty.channel.EventExecutor; +import io.netty.channel.MultithreadEventLoop; + +import java.util.concurrent.ThreadFactory; + +public class AsyncEventLoop extends MultithreadEventLoop { + + public AsyncEventLoop() { + this(0); + } + + public AsyncEventLoop(int nThreads) { + this(nThreads, null); + } + + public AsyncEventLoop(int nThreads, ThreadFactory threadFactory) { + super(nThreads, threadFactory); + } + + @Override + protected EventExecutor newChild(ThreadFactory threadFactory, Object... args) throws Exception { + return new AsyncChildEventLoop(threadFactory); + } +} diff --git a/transport/src/main/java/io/netty/channel/socket/nio2/AsyncNetworkChannel.java b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncNetworkChannel.java new file mode 100755 index 0000000000..eed1b6f5de --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncNetworkChannel.java @@ -0,0 +1,52 @@ +package io.netty.channel.socket.nio2; + +import java.io.IOException; +import java.net.SocketAddress; +import java.net.SocketOption; +import java.nio.channels.NetworkChannel; +import java.util.Map; +import java.util.Set; + +public class AsyncNetworkChannel implements NetworkChannel { + + private Map, Object> options; + + @Override + public void close() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isOpen() { + throw new UnsupportedOperationException(); + + } + + @Override + public NetworkChannel bind(SocketAddress local) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public SocketAddress getLocalAddress() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public synchronized T getOption(SocketOption name) throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public synchronized NetworkChannel setOption(SocketOption name, T value) throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Set> supportedOptions() { + throw new UnsupportedOperationException(); + } + +} 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 816d7f6be6..81cc8802e9 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 @@ -34,6 +34,7 @@ public class AsyncServerSocketChannel extends AbstractAsyncChannel implements Se private static final AcceptHandler ACCEPT_HANDLER = new AcceptHandler(); private static final InternalLogger logger = InternalLoggerFactory.getInstance(AsyncServerSocketChannel.class); + private volatile AsyncServerSocketChannelConfig config; public AsyncServerSocketChannel() { super(null, null); @@ -47,7 +48,15 @@ public class AsyncServerSocketChannel extends AbstractAsyncChannel implements Se @Override public boolean isActive() { - return localAddress0() != null; + AsynchronousServerSocketChannel channel = javaChannel(); + try { + if (channel != null && channel.getLocalAddress() != null) { + return true; + } + } catch (IOException e) { + return true; + } + return false; } @Override @@ -72,6 +81,8 @@ public class AsyncServerSocketChannel extends AbstractAsyncChannel implements Se @Override protected void doBind(SocketAddress localAddress) throws Exception { javaChannel().bind(localAddress); + javaChannel().accept(this, ACCEPT_HANDLER); + } @Override @@ -98,7 +109,8 @@ public class AsyncServerSocketChannel extends AbstractAsyncChannel implements Se @Override protected Runnable doRegister() throws Exception { ch = AsynchronousServerSocketChannel.open(AsynchronousChannelGroup.withThreadPool(eventLoop())); - javaChannel().accept(this, ACCEPT_HANDLER); + config = new AsyncServerSocketChannelConfig(javaChannel()); + return null; } @@ -109,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.outboundMessageBuffer().add(new AsyncSocketchannel(channel, null)); + channel.pipeline().inboundMessageBuffer().add(new AsyncSocketchannel(channel, null, ch)); channel.pipeline().fireInboundBufferUpdated(); } @@ -117,4 +129,12 @@ public class AsyncServerSocketChannel extends AbstractAsyncChannel implements Se logger.warn("Failed to create a new channel from an accepted socket.", t); } } + + @Override + public AsyncServerSocketChannelConfig config() { + if (config == null) { + throw new IllegalStateException("Channel not registered yet"); + } + return config; + } } diff --git a/transport/src/main/java/io/netty/channel/socket/nio2/AsyncServerSocketChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncServerSocketChannelConfig.java new file mode 100755 index 0000000000..55f62b51ce --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncServerSocketChannelConfig.java @@ -0,0 +1,138 @@ +/* + * Copyright 2012 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.socket.nio2; + +import static io.netty.channel.ChannelOption.*; +import io.netty.channel.ChannelException; +import io.netty.channel.ChannelOption; +import io.netty.channel.DefaultChannelConfig; +import io.netty.channel.socket.ServerSocketChannelConfig; + +import java.io.IOException; +import java.net.StandardSocketOptions; +import java.nio.channels.AsynchronousServerSocketChannel; +import java.util.Map; + +/** + * The Async {@link ServerSocketChannelConfig} implementation. + */ +public class AsyncServerSocketChannelConfig extends DefaultChannelConfig + implements ServerSocketChannelConfig { + + private final AsynchronousServerSocketChannel channel; + private volatile int backlog; + + /** + * Creates a new instance. + */ + public AsyncServerSocketChannelConfig(AsynchronousServerSocketChannel channel) { + if (channel == null) { + throw new NullPointerException("channel"); + } + this.channel = channel; + } + + @Override + public Map, Object> getOptions() { + return getOptions(super.getOptions(), SO_RCVBUF, SO_REUSEADDR, SO_BACKLOG); + } + + @Override + public T getOption(ChannelOption option) { + if (option == SO_RCVBUF) { + return (T) Integer.valueOf(getReceiveBufferSize()); + } + if (option == SO_REUSEADDR) { + return (T) Boolean.valueOf(isReuseAddress()); + } + if (option == SO_BACKLOG) { + return (T) Integer.valueOf(getBacklog()); + } + + return super.getOption(option); + } + + @Override + public boolean setOption(ChannelOption option, T value) { + validate(option, value); + + if (option == SO_RCVBUF) { + setReceiveBufferSize((Integer) value); + } else if (option == SO_REUSEADDR) { + setReuseAddress((Boolean) value); + } else if (option == SO_BACKLOG) { + setBacklog((Integer) value); + } else { + return super.setOption(option, value); + } + + return true; + } + + @Override + public boolean isReuseAddress() { + try { + return channel.getOption(StandardSocketOptions.SO_REUSEADDR); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setReuseAddress(boolean reuseAddress) { + try { + channel.setOption(StandardSocketOptions.SO_REUSEADDR, reuseAddress); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public int getReceiveBufferSize() { + try { + return channel.getOption(StandardSocketOptions.SO_RCVBUF); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setReceiveBufferSize(int receiveBufferSize) { + try { + channel.setOption(StandardSocketOptions.SO_RCVBUF, receiveBufferSize); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) { + throw new UnsupportedOperationException(); + } + + @Override + public int getBacklog() { + return backlog; + } + + @Override + public void setBacklog(int backlog) { + if (backlog < 0) { + throw new IllegalArgumentException("backlog: " + backlog); + } + this.backlog = backlog; + } +} diff --git a/transport/src/main/java/io/netty/channel/socket/nio2/AsyncSocketChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncSocketChannelConfig.java new file mode 100755 index 0000000000..d89b61acf0 --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/nio2/AsyncSocketChannelConfig.java @@ -0,0 +1,237 @@ +/* + * Copyright 2012 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.socket.nio2; + +import static io.netty.channel.ChannelOption.*; +import io.netty.channel.ChannelException; +import io.netty.channel.ChannelOption; +import io.netty.channel.DefaultChannelConfig; +import io.netty.channel.socket.SocketChannelConfig; + +import java.io.IOException; +import java.net.StandardSocketOptions; +import java.nio.channels.NetworkChannel; +import java.util.Map; + +/** + * The default {@link SocketChannelConfig} implementation. + */ +public class AsyncSocketChannelConfig extends DefaultChannelConfig + implements SocketChannelConfig { + + private final NetworkChannel channel; + + /** + * Creates a new instance. + */ + public AsyncSocketChannelConfig(NetworkChannel channel) { + if (channel == null) { + throw new NullPointerException("channel"); + } + this.channel = channel; + } + + @Override + public Map, Object> getOptions() { + return getOptions( + super.getOptions(), + SO_RCVBUF, SO_SNDBUF, TCP_NODELAY, SO_KEEPALIVE, SO_REUSEADDR, SO_LINGER, IP_TOS); + } + + @Override + public T getOption(ChannelOption option) { + if (option == SO_RCVBUF) { + return (T) Integer.valueOf(getReceiveBufferSize()); + } + if (option == SO_SNDBUF) { + return (T) Integer.valueOf(getSendBufferSize()); + } + if (option == TCP_NODELAY) { + return (T) Boolean.valueOf(isTcpNoDelay()); + } + if (option == SO_KEEPALIVE) { + return (T) Boolean.valueOf(isKeepAlive()); + } + if (option == SO_REUSEADDR) { + return (T) Boolean.valueOf(isReuseAddress()); + } + if (option == SO_LINGER) { + return (T) Integer.valueOf(getSoLinger()); + } + if (option == IP_TOS) { + return (T) Integer.valueOf(getTrafficClass()); + } + + return super.getOption(option); + } + + @Override + public boolean setOption(ChannelOption option, T value) { + validate(option, value); + + if (option == SO_RCVBUF) { + setReceiveBufferSize((Integer) value); + } else if (option == SO_SNDBUF) { + setSendBufferSize((Integer) value); + } else if (option == TCP_NODELAY) { + setTcpNoDelay((Boolean) value); + } else if (option == SO_KEEPALIVE) { + setKeepAlive((Boolean) value); + } else if (option == SO_REUSEADDR) { + setReuseAddress((Boolean) value); + } else if (option == SO_LINGER) { + setSoLinger((Integer) value); + } else if (option == IP_TOS) { + setTrafficClass((Integer) value); + } else { + return super.setOption(option, value); + } + + return true; + } + + @Override + public int getReceiveBufferSize() { + try { + return (int) channel.getOption(StandardSocketOptions.SO_RCVBUF); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public int getSendBufferSize() { + try { + return channel.getOption(StandardSocketOptions.SO_SNDBUF); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public int getSoLinger() { + try { + return channel.getOption(StandardSocketOptions.SO_LINGER); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public int getTrafficClass() { + try { + return channel.getOption(StandardSocketOptions.IP_TOS); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public boolean isKeepAlive() { + try { + return channel.getOption(StandardSocketOptions.SO_KEEPALIVE); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public boolean isReuseAddress() { + try { + return channel.getOption(StandardSocketOptions.SO_REUSEADDR); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public boolean isTcpNoDelay() { + try { + return channel.getOption(StandardSocketOptions.SO_REUSEADDR); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setKeepAlive(boolean keepAlive) { + try { + channel.setOption(StandardSocketOptions.SO_KEEPALIVE, keepAlive); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setPerformancePreferences( + int connectionTime, int latency, int bandwidth) { + throw new UnsupportedOperationException(); + } + + @Override + public void setReceiveBufferSize(int receiveBufferSize) { + try { + channel.setOption(StandardSocketOptions.SO_RCVBUF, receiveBufferSize); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setReuseAddress(boolean reuseAddress) { + try { + channel.setOption(StandardSocketOptions.SO_REUSEADDR, reuseAddress); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setSendBufferSize(int sendBufferSize) { + try { + channel.setOption(StandardSocketOptions.SO_SNDBUF, sendBufferSize); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setSoLinger(int soLinger) { + try { + channel.setOption(StandardSocketOptions.SO_LINGER, soLinger); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setTcpNoDelay(boolean tcpNoDelay) { + try { + channel.setOption(StandardSocketOptions.TCP_NODELAY, tcpNoDelay); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setTrafficClass(int trafficClass) { + try { + channel.setOption(StandardSocketOptions.IP_TOS, trafficClass); + } catch (IOException e) { + throw new ChannelException(e); + } + } +} 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 4c8f63ea90..cd1e8619cc 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 @@ -18,7 +18,10 @@ package io.netty.channel.socket.nio2; import io.netty.buffer.ByteBuf; import io.netty.buffer.ChannelBufType; import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; +import io.netty.channel.ChannelStateHandler; +import io.netty.channel.ChannelStateHandlerAdapter; import java.io.IOException; import java.net.InetSocketAddress; @@ -33,21 +36,42 @@ 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 ChannelStateHandler READ_START_HANDLER = new ChannelStateHandlerAdapter() { + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + try { + super.channelActive(ctx); + AsyncSocketchannel.read((AsyncSocketchannel)ctx.channel()); + + } finally { + ctx.pipeline().remove(this); + } + + + } + + }; private final AtomicBoolean flushing = new AtomicBoolean(false); + private volatile AsyncSocketChannelConfig config; public AsyncSocketchannel() { - this(null, null); + this(null, null, null); } - public AsyncSocketchannel(AsyncServerSocketChannel parent, Integer id) { + public AsyncSocketchannel(AsyncServerSocketChannel parent, Integer id, AsynchronousSocketChannel channel) { super(parent, id); + this.ch = channel; + if (ch != null) { + config = new AsyncSocketChannelConfig(javaChannel()); + pipeline().addLast(READ_START_HANDLER); + } } @Override public boolean isActive() { AsynchronousSocketChannel ch = javaChannel(); - return ch.isOpen(); + return ch.isOpen() && remoteAddress() != null; } @Override @@ -95,13 +119,18 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { @Override protected Runnable doRegister() throws Exception { - assert ch == null; - ch = AsynchronousSocketChannel.open(AsynchronousChannelGroup.withThreadPool(eventLoop())); + if (ch == null) { + ch = AsynchronousSocketChannel.open(AsynchronousChannelGroup.withThreadPool(eventLoop())); + config = new AsyncSocketChannelConfig(javaChannel()); + pipeline().addLast(READ_START_HANDLER); + } + + return null; } - private void read() { - javaChannel().read(pipeline().inboundByteBuffer().nioBuffer(), this, READ_HANDLER); + private static void read(AsyncSocketchannel channel) { + channel.javaChannel().read(channel.pipeline().inboundByteBuffer().nioBuffer(), channel, READ_HANDLER); } @Override @@ -132,14 +161,6 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { return false; } - private static boolean expandReadBuffer(ByteBuf byteBuf) { - if (!byteBuf.writable()) { - // FIXME: Magic number - byteBuf.ensureWritableBytes(4096); - return true; - } - return false; - } private static final class WriteHandler implements CompletionHandler { @@ -213,10 +234,20 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { channel.close(channel.unsafe().voidFuture()); } else { // start the next read - channel.read(); + AsyncSocketchannel.read(channel); } } } + + private static boolean expandReadBuffer(ByteBuf byteBuf) { + if (!byteBuf.writable()) { + // FIXME: Magic number + byteBuf.ensureWritableBytes(4096); + return true; + } + return false; + } + @Override public void failed(Throwable t, AsyncSocketchannel channel) { @@ -225,7 +256,7 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { channel.close(channel.unsafe().voidFuture()); } else { // start the next read - channel.read(); + AsyncSocketchannel.read(channel); } } } @@ -235,6 +266,9 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { @Override public void completed(Void result, AsyncSocketchannel channel) { ((AsyncUnsafe) channel.unsafe()).connectSuccess(); + + // start reading from channel + AsyncSocketchannel.read(channel); } @Override @@ -243,4 +277,13 @@ public class AsyncSocketchannel extends AbstractAsyncChannel { } } + @Override + public AsyncSocketChannelConfig config() { + if (config == null) { + throw new IllegalStateException("Channel not registered yet"); + } + return config; + } + + } diff --git a/transport/src/main/java/io/netty/channel/socket/nio2/package-info.java b/transport/src/main/java/io/netty/channel/socket/nio2/package-info.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioMessageChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioMessageChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioChildEventLoop.java b/transport/src/main/java/io/netty/channel/socket/oio/OioChildEventLoop.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioEventLoop.java b/transport/src/main/java/io/netty/channel/socket/oio/OioEventLoop.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/oio/package-info.java b/transport/src/main/java/io/netty/channel/socket/oio/package-info.java old mode 100644 new mode 100755 diff --git a/transport/src/main/java/io/netty/channel/socket/package-info.java b/transport/src/main/java/io/netty/channel/socket/package-info.java old mode 100644 new mode 100755 diff --git a/transport/src/test/java/io/netty/channel/AsyncTransportTest.java b/transport/src/test/java/io/netty/channel/AsyncTransportTest.java new file mode 100755 index 0000000000..a8153e26f1 --- /dev/null +++ b/transport/src/test/java/io/netty/channel/AsyncTransportTest.java @@ -0,0 +1,42 @@ +package io.netty.channel; + +import java.net.InetSocketAddress; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandlerContext; +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; + +public class AsyncTransportTest { + + public static void main(String args[]) { + // Configure a test server + ServerBootstrap sb = new ServerBootstrap(); + sb.eventLoop(new AsyncEventLoop(), new AsyncEventLoop()) + .channel(new AsyncServerSocketChannel()) + .localAddress(new InetSocketAddress(9999)) + .childHandler(new ChannelInitializer() { + @Override + 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)); + } + }); + } + }); + ChannelFuture future = sb.bind().awaitUninterruptibly(); + if (!future.isSuccess()) { + future.cause().printStackTrace(); + } + future.channel().closeFuture().awaitUninterruptibly(); + } +} diff --git a/transport/src/test/java/io/netty/channel/CompleteChannelFutureTest.java b/transport/src/test/java/io/netty/channel/CompleteChannelFutureTest.java old mode 100644 new mode 100755 diff --git a/transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java b/transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java old mode 100644 new mode 100755 diff --git a/transport/src/test/java/io/netty/channel/FailedChannelFutureTest.java b/transport/src/test/java/io/netty/channel/FailedChannelFutureTest.java old mode 100644 new mode 100755 diff --git a/transport/src/test/java/io/netty/channel/SingleThreadEventLoopTest.java b/transport/src/test/java/io/netty/channel/SingleThreadEventLoopTest.java old mode 100644 new mode 100755 diff --git a/transport/src/test/java/io/netty/channel/SucceededChannelFutureTest.java b/transport/src/test/java/io/netty/channel/SucceededChannelFutureTest.java old mode 100644 new mode 100755 diff --git a/transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java b/transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java old mode 100644 new mode 100755 diff --git a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java old mode 100644 new mode 100755