From d3f24589a40bf38e79deefe289a8dc6845ed7017 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 22 Sep 2008 02:10:31 +0000 Subject: [PATCH] * Fixed too frequent plugin update * Keep writing the guide... --- pom.xml | 3 ++ src/docbook/custom.dtd | 5 ++++ src/docbook/module/start.xml | 57 ++++++++++++++++++++++++++++-------- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 9ab1b8cf4b..f5c849c3e6 100644 --- a/pom.xml +++ b/pom.xml @@ -433,6 +433,9 @@ false + + interval:10080 + jboss.release JBoss releases http://repository.jboss.org/maven2 diff --git a/src/docbook/custom.dtd b/src/docbook/custom.dtd index 3c12eabae7..8e86f6dafa 100644 --- a/src/docbook/custom.dtd +++ b/src/docbook/custom.dtd @@ -17,6 +17,7 @@ Channel"> ChannelDownstreamHandler"> +ChannelEvent"> ChannelFactory"> ChannelHandler"> ChannelHandlerContext"> @@ -27,6 +28,10 @@ MessageEvent"> SimpleChannelHandler"> + + +ServerSocketChannel"> + NioServerSocketChannelFactory"> diff --git a/src/docbook/module/start.xml b/src/docbook/module/start.xml index 36cbcbbee8..d3dec59fa8 100644 --- a/src/docbook/module/start.xml +++ b/src/docbook/module/start.xml @@ -77,8 +77,7 @@ public class DiscardServerHandler extends &SimpleChannelHandler; {. It's OK even if you are confused with - this yet. We will revisit it soon. + "all". @@ -131,47 +130,79 @@ import org.jboss.netty.channel.socket.nio.&NioServerSocketChannelFactory;; public class DiscardServer { public static void main(String[] args) throws Exception { - &ChannelFactory; factory = - new &NioServerSocketChannelFactory;( + &ChannelFactory; factory = + new &NioServerSocketChannelFactory;( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); - &ServerBootstrap; bootstrap = new &ServerBootstrap;(factory); + &ServerBootstrap; bootstrap = new &ServerBootstrap;(factory); DiscardServerHandler handler = new DiscardServerHandler(); &ChannelPipeline; pipeline = bootstrap.getPipeline(); - pipeline.addLast("handler", handler); + pipeline.addLast("handler", handler); - bootstrap.setOption("child.tcpNoDelay", true); + bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.keepAlive", true); - bootstrap.bind(new InetSocketAddress(8080)); + bootstrap.bind(new InetSocketAddress(8080)); } } - &ChannelFactory; is a factory which creates a &Channel; + &ChannelFactory; is a factory which creates and manages &Channel;s + and its related resources. It processes all I/O requests and + performs I/O to generate &ChannelEvent;s. Netty provides various + &ChannelFactory; implementations. We are implementing a server-side + application in this example, and therefore + &NioServerSocketChannelFactory; was used. Another thing to note is + that it doesn't create I/O threads by itself. It is supposed to + acquire threads from the thread pool you specified in the + constructor, and it gives you more control over how threads should + be managed in the environment where your application runs, such as + an application server with a security manager. + &ServerBootstrap; is a helper class that sets up a server. You can + set up the server by yourself using a &Channel; directly, but it's a + tedious process and you won't need to do that in most cases. + Here, we add the DiscardServerHandler to the + default &ChannelPipeline;. Whenever a new + connection is accepted by the server, a new &ChannelPipeline; will + be created for a newly accepted &Channel; and all the + &ChannelHandler;s added here will be added to the new + &ChannelPipeline;. It's just like + a shallow-copy + operation; all &Channel; and their &ChannelPipeline;s will + share the same DiscardServerHandler instance. + You can also set the parameters which are specific to the &Channel; + implementation. We are writing a TCP/IP server, so we are allowed + to set the socket options such as tcpNoDelay and + keepAlive. Please note that the + "child." prefix was added to all options. It + means the options will be applied to the accepted &Channel;s instead + of the options of the &ServerSocketChannel;. To set the options of + the &ServerSocketChannel;, you could do the following: + bootstrap.setOption("reuseAddress", true); - - - - + OK, we are all set. What's left is bind to the port to start the + server. Here, we bind to the port 8080 of all + NICs in the machine. You are allowed to call the + bind method as many times as you want with + different bind addresses.