* Fixed too frequent plugin update
* Keep writing the guide...
This commit is contained in:
parent
da8fa65aca
commit
d3f24589a4
3
pom.xml
3
pom.xml
@ -433,6 +433,9 @@
|
|||||||
<snapshots>
|
<snapshots>
|
||||||
<enabled>false</enabled>
|
<enabled>false</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
|
<releases>
|
||||||
|
<updatePolicy>interval:10080</updatePolicy>
|
||||||
|
</releases>
|
||||||
<id>jboss.release</id>
|
<id>jboss.release</id>
|
||||||
<name>JBoss releases</name>
|
<name>JBoss releases</name>
|
||||||
<url>http://repository.jboss.org/maven2</url>
|
<url>http://repository.jboss.org/maven2</url>
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
<!ENTITY Channel "<ulink url='&API;channel/Channel.html'><interfacename>Channel</interfacename></ulink>">
|
<!ENTITY Channel "<ulink url='&API;channel/Channel.html'><interfacename>Channel</interfacename></ulink>">
|
||||||
<!ENTITY ChannelDownstreamHandler "<ulink url='&API;channel/ChannelDownstreamHandler.html'><interfacename>ChannelDownstreamHandler</interfacename></ulink>">
|
<!ENTITY ChannelDownstreamHandler "<ulink url='&API;channel/ChannelDownstreamHandler.html'><interfacename>ChannelDownstreamHandler</interfacename></ulink>">
|
||||||
|
<!ENTITY ChannelEvent "<ulink url='&API;channel/ChannelEvent.html'><interfacename>ChannelEvent</interfacename></ulink>">
|
||||||
<!ENTITY ChannelFactory "<ulink url='&API;channel/ChannelFactory.html'><interfacename>ChannelFactory</interfacename></ulink>">
|
<!ENTITY ChannelFactory "<ulink url='&API;channel/ChannelFactory.html'><interfacename>ChannelFactory</interfacename></ulink>">
|
||||||
<!ENTITY ChannelHandler "<ulink url='&API;channel/ChannelHandler.html'><interfacename>ChannelHandler</interfacename></ulink>">
|
<!ENTITY ChannelHandler "<ulink url='&API;channel/ChannelHandler.html'><interfacename>ChannelHandler</interfacename></ulink>">
|
||||||
<!ENTITY ChannelHandlerContext "<ulink url='&API;channel/ChannelHandlerContext.html'><interfacename>ChannelHandlerContext</interfacename></ulink>">
|
<!ENTITY ChannelHandlerContext "<ulink url='&API;channel/ChannelHandlerContext.html'><interfacename>ChannelHandlerContext</interfacename></ulink>">
|
||||||
@ -27,6 +28,10 @@
|
|||||||
<!ENTITY MessageEvent "<ulink url='&API;channel/MessageEvent.html'><interfacename>MessageEvent</interfacename></ulink>">
|
<!ENTITY MessageEvent "<ulink url='&API;channel/MessageEvent.html'><interfacename>MessageEvent</interfacename></ulink>">
|
||||||
<!ENTITY SimpleChannelHandler "<ulink url='&API;channel/SimpleChannelHandler.html'><classname>SimpleChannelHandler</classname></ulink>">
|
<!ENTITY SimpleChannelHandler "<ulink url='&API;channel/SimpleChannelHandler.html'><classname>SimpleChannelHandler</classname></ulink>">
|
||||||
|
|
||||||
|
<!-- Types in the channel.socket package -->
|
||||||
|
|
||||||
|
<!ENTITY ServerSocketChannel "<ulink url='&API;channel/socket/ServerSocketChannel.html'><classname>ServerSocketChannel</classname></ulink>">
|
||||||
|
|
||||||
<!-- Types in the channel.socket.nio package -->
|
<!-- Types in the channel.socket.nio package -->
|
||||||
|
|
||||||
<!ENTITY NioServerSocketChannelFactory "<ulink url='&API;channel/socket/nio/NioServerSocketChannelFactory.html'><classname>NioServerSocketChannelFactory</classname></ulink>">
|
<!ENTITY NioServerSocketChannelFactory "<ulink url='&API;channel/socket/nio/NioServerSocketChannelFactory.html'><classname>NioServerSocketChannelFactory</classname></ulink>">
|
||||||
|
@ -77,8 +77,7 @@ public class DiscardServerHandler extends &SimpleChannelHandler; {<co id="exampl
|
|||||||
one &Channel; (and its associated &ChannelPipeline;).
|
one &Channel; (and its associated &ChannelPipeline;).
|
||||||
<classname>DiscardServerHandler</classname> doesn't manage any
|
<classname>DiscardServerHandler</classname> doesn't manage any
|
||||||
stateful information, and therefore it's annotated with the value
|
stateful information, and therefore it's annotated with the value
|
||||||
<literal>"all"</literal>. It's OK even if you are confused with
|
<literal>"all"</literal>.
|
||||||
this yet. We will revisit it soon.
|
|
||||||
</para>
|
</para>
|
||||||
</callout>
|
</callout>
|
||||||
<callout arearefs="example.discard.co2">
|
<callout arearefs="example.discard.co2">
|
||||||
@ -131,47 +130,79 @@ import org.jboss.netty.channel.socket.nio.&NioServerSocketChannelFactory;;
|
|||||||
public class DiscardServer {
|
public class DiscardServer {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
&ChannelFactory;<co id="example.discard2.co1" /> factory =
|
&ChannelFactory; factory =
|
||||||
new &NioServerSocketChannelFactory;<co id="example.discard2.co2" />(
|
new &NioServerSocketChannelFactory;<co id="example.discard2.co1" />(
|
||||||
Executors.newCachedThreadPool(),
|
Executors.newCachedThreadPool(),
|
||||||
Executors.newCachedThreadPool());
|
Executors.newCachedThreadPool());
|
||||||
|
|
||||||
&ServerBootstrap; bootstrap = new &ServerBootstrap;<co id="example.discard2.co3" />(factory);
|
&ServerBootstrap; bootstrap = new &ServerBootstrap;<co id="example.discard2.co2" />(factory);
|
||||||
|
|
||||||
DiscardServerHandler handler = new DiscardServerHandler();
|
DiscardServerHandler handler = new DiscardServerHandler();
|
||||||
&ChannelPipeline; pipeline = bootstrap.getPipeline();
|
&ChannelPipeline; pipeline = bootstrap.getPipeline();
|
||||||
pipeline.addLast("handler", handler);<co id="example.discard2.co4" />
|
pipeline.addLast("handler", handler);<co id="example.discard2.co3" />
|
||||||
|
|
||||||
bootstrap.setOption("child.tcpNoDelay", true);<co id="example.discard2.co5" />
|
bootstrap.setOption("child.tcpNoDelay", true);<co id="example.discard2.co4" />
|
||||||
bootstrap.setOption("child.keepAlive", true);
|
bootstrap.setOption("child.keepAlive", true);
|
||||||
|
|
||||||
bootstrap.bind(new InetSocketAddress(8080));<co id="example.discard2.co6" />
|
bootstrap.bind(new InetSocketAddress(8080));<co id="example.discard2.co5" />
|
||||||
}
|
}
|
||||||
}</programlisting>
|
}</programlisting>
|
||||||
<calloutlist>
|
<calloutlist>
|
||||||
<callout arearefs="example.discard2.co1">
|
<callout arearefs="example.discard2.co1">
|
||||||
<para>
|
<para>
|
||||||
&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.
|
||||||
</para>
|
</para>
|
||||||
</callout>
|
</callout>
|
||||||
<callout arearefs="example.discard2.co2">
|
<callout arearefs="example.discard2.co2">
|
||||||
<para>
|
<para>
|
||||||
|
&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.
|
||||||
</para>
|
</para>
|
||||||
</callout>
|
</callout>
|
||||||
<callout arearefs="example.discard2.co3">
|
<callout arearefs="example.discard2.co3">
|
||||||
<para>
|
<para>
|
||||||
|
Here, we add the <classname>DiscardServerHandler</classname> to the
|
||||||
|
<emphasis>default</emphasis> &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
|
||||||
|
<ulink url="http://en.wikipedia.org/wiki/Object_copy">a shallow-copy
|
||||||
|
operation</ulink>; all &Channel; and their &ChannelPipeline;s will
|
||||||
|
share the same <classname>DiscardServerHandler</classname> instance.
|
||||||
</para>
|
</para>
|
||||||
</callout>
|
</callout>
|
||||||
<callout arearefs="example.discard2.co4">
|
<callout arearefs="example.discard2.co4">
|
||||||
<para>
|
<para>
|
||||||
|
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 <literal>tcpNoDelay</literal> and
|
||||||
|
<literal>keepAlive</literal>. Please note that the
|
||||||
|
<literal>"child."</literal> 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:
|
||||||
|
<programlisting>bootstrap.setOption("reuseAddress", true);</programlisting>
|
||||||
</para>
|
</para>
|
||||||
</callout>
|
</callout>
|
||||||
<callout arearefs="example.discard2.co5">
|
<callout arearefs="example.discard2.co5">
|
||||||
<para>
|
<para>
|
||||||
</para>
|
OK, we are all set. What's left is bind to the port to start the
|
||||||
</callout>
|
server. Here, we bind to the port <literal>8080</literal> of all
|
||||||
<callout arearefs="example.discard2.co6">
|
NICs in the machine. You are allowed to call the
|
||||||
<para>
|
<methodname>bind</methodname> method as many times as you want with
|
||||||
|
different bind addresses.
|
||||||
</para>
|
</para>
|
||||||
</callout>
|
</callout>
|
||||||
</calloutlist>
|
</calloutlist>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user