* Replaced callout-bug with simple co tags

* Stylesheet update
This commit is contained in:
Trustin Lee 2008-09-20 09:11:54 +00:00
parent 0f3edc8cd8
commit ea7c7e769c
3 changed files with 113 additions and 100 deletions

View File

@ -90,10 +90,16 @@ pre a:link * {color:#0066cc !important;}
pre a:visited * {color:#6699cc !important;}
.programlistingco pre {
.programlisting, .programlistingco pre {
line-height: 160%;
}
.programlisting img {
margin: 0;
padding: 0;
vertical-align: middle;
}
span.co {
position: relative;
left: 0;

View File

@ -46,14 +46,7 @@
the received data, and that's all. Let's start straight from the handler
implementation, which handles I/O events generated by Netty.
</para>
<programlistingco>
<areaspec>
<area id="example.discard.c1" coords="9" />
<area id="example.discard.c2" coords="10" />
<area id="example.discard.c3" coords="13" />
<area id="example.discard.c4" coords="17" />
</areaspec>
<programlisting>package org.jboss.netty.example.discard;
<programlisting>package org.jboss.netty.example.discard;
import org.jboss.netty.channel.&ChannelHandlerContext;;
import org.jboss.netty.channel.&ChannelPipelineCoverage;;
@ -61,81 +54,72 @@ import org.jboss.netty.channel.&ExceptionEvent;;
import org.jboss.netty.channel.&MessageEvent;;
import org.jboss.netty.channel.&SimpleChannelHandler;;
@&ChannelPipelineCoverage;("all")
public class DiscardServerHandler extends &SimpleChannelHandler; {
@&ChannelPipelineCoverage;("all")<co id="example.discard.co1"/>
public class DiscardServerHandler extends &SimpleChannelHandler; {<co id="example.discard.co2"/>
@Override
public void messageReceived(&ChannelHandlerContext; ctx, &MessageEvent; e) {
public void messageReceived(&ChannelHandlerContext; ctx, &MessageEvent; e) {<co id="example.discard.co3"/>
}
@Override
public void exceptionCaught(&ChannelHandlerContext; ctx, &ExceptionEvent; e) {
public void exceptionCaught(&ChannelHandlerContext; ctx, &ExceptionEvent; e) {<co id="example.discard.co4"/>
e.getCause().printStackTrace();
&Channel; ch = e.getChannel();
ch.close();
}
}</programlisting>
<calloutlist>
<callout arearefs="example.discard.c1">
<para>
&ChannelPipelineCoverage; annotates a handler type to tell if the
handler instance of the annotated type can be shared by more than
one &Channel; (and its associated &ChannelPipeline;).
<classname>DiscardServerHandler</classname> doesn't manage any
stateful information, and therefore it's annotated with the value
<literal>"all"</literal>. It's OK even if you are confused with
this yet. We will revisit it soon.
</para>
</callout>
<callout arearefs="example.discard.c2">
<para>
<classname>DiscardServerHandler</classname> extends
&SimpleChannelHandler;, which is an implementation of
&ChannelUpstreamHandler;. &SimpleChannelHandler; provides various
event handler methods that you can override. For now, it's just
enough to extend &SimpleChannelHandler; rather than to implement
handler interfaces.
</para>
</callout>
<callout arearefs="example.discard.c3">
<para>
We override the <methodname>messageReceived</methodname> event
handler method here. This method is called with a &MessageEvent;,
which contains the received data, whenever new data is received
from a client. In this example, we just ignore the received data
by doing nothing to implement the DISCARD protocol.
</para>
</callout>
<callout arearefs="example.discard.c4">
<para>
<methodname>exceptionCaught</methodname> event handler method is
called with an &ExceptionEvent; when an exception was raised by
Netty due to I/O error or by a handler implementation due to the
exception thrown while processing events. In most cases, the
caught exception should be logged and its associated channel
should be closed here, although the implementation of this method
can be different depending on what you want to do to deal with an
exceptional situation. For example, you might want to send a
response message with an error code before closing the connection.
</para>
</callout>
</calloutlist>
</programlistingco>
<calloutlist>
<callout arearefs="example.discard.co1">
<para>
&ChannelPipelineCoverage; annotates a handler type to tell if the
handler instance of the annotated type can be shared by more than
one &Channel; (and its associated &ChannelPipeline;).
<classname>DiscardServerHandler</classname> doesn't manage any
stateful information, and therefore it's annotated with the value
<literal>"all"</literal>. It's OK even if you are confused with
this yet. We will revisit it soon.
</para>
</callout>
<callout arearefs="example.discard.co2">
<para>
<classname>DiscardServerHandler</classname> extends
&SimpleChannelHandler;, which is an implementation of
&ChannelUpstreamHandler;. &SimpleChannelHandler; provides various
event handler methods that you can override. For now, it's just
enough to extend &SimpleChannelHandler; rather than to implement
handler interfaces.
</para>
</callout>
<callout arearefs="example.discard.co3">
<para>
We override the <methodname>messageReceived</methodname> event
handler method here. This method is called with a &MessageEvent;,
which contains the received data, whenever new data is received
from a client. In this example, we just ignore the received data
by doing nothing to implement the DISCARD protocol.
</para>
</callout>
<callout arearefs="example.discard.co4">
<para>
<methodname>exceptionCaught</methodname> event handler method is
called with an &ExceptionEvent; when an exception was raised by
Netty due to I/O error or by a handler implementation due to the
exception thrown while processing events. In most cases, the
caught exception should be logged and its associated channel
should be closed here, although the implementation of this method
can be different depending on what you want to do to deal with an
exceptional situation. For example, you might want to send a
response message with an error code before closing the connection.
</para>
</callout>
</calloutlist>
<para>
So far so good. We have implemented the half of the DISCARD server.
What's left now is to write the <methodname>main</methodname> method
which starts the server up with the <classname>DiscardServerHandler</classname>.
</para>
<programlistingco>
<areaspec>
<area id="example.discard2.c1" coords="13" />
<area id="example.discard2.c2" coords="18" />
<area id="example.discard2.c3" coords="21" />
<area id="example.discard2.c4" coords="23" />
<area id="example.discard2.c5" coords="26" />
</areaspec>
<programlisting>package org.jboss.netty.example.discard;
<programlisting>package org.jboss.netty.example.discard;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
@ -147,46 +131,49 @@ import org.jboss.netty.channel.socket.nio.&NioServerSocketChannelFactory;;
public class DiscardServer {
public static void main(String[] args) throws Exception {
&ChannelFactory; factory =
new &NioServerSocketChannelFactory;(
&ChannelFactory;<co id="example.discard2.co1" /> factory =
new &NioServerSocketChannelFactory;<co id="example.discard2.co2" />(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
&ServerBootstrap; bootstrap = new &ServerBootstrap;(factory);
&ServerBootstrap; bootstrap = new &ServerBootstrap;<co id="example.discard2.co3" />(factory);
DiscardServerHandler handler = new DiscardServerHandler();
&ChannelPipeline; pipeline = bootstrap.getPipeline();
pipeline.addLast("handler", handler);
pipeline.addLast("handler", handler);<co id="example.discard2.co4" />
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.tcpNoDelay", true);<co id="example.discard2.co5" />
bootstrap.setOption("child.keepAlive", true);
bootstrap.bind(new InetSocketAddress(8080));
bootstrap.bind(new InetSocketAddress(8080));<co id="example.discard2.co6" />
}
}</programlisting>
<calloutlist>
<callout arearefs="example.discard2.c1">
<para>
&ChannelFactory; is a factory which creates a &Channel;
</para>
</callout>
<callout arearefs="example.discard2.c2">
<para>
</para>
</callout>
<callout arearefs="example.discard2.c3">
<para>
</para>
</callout>
<callout arearefs="example.discard2.c4">
<para>
</para>
</callout>
<callout arearefs="example.discard2.c5">
<para>
</para>
</callout>
</calloutlist>
</programlistingco>
<calloutlist>
<callout arearefs="example.discard2.co1">
<para>
&ChannelFactory; is a factory which creates a &Channel;
</para>
</callout>
<callout arearefs="example.discard2.co2">
<para>
</para>
</callout>
<callout arearefs="example.discard2.co3">
<para>
</para>
</callout>
<callout arearefs="example.discard2.co4">
<para>
</para>
</callout>
<callout arearefs="example.discard2.co5">
<para>
</para>
</callout>
<callout arearefs="example.discard2.co6">
<para>
</para>
</callout>
</calloutlist>
</section>
</chapter>

View File

@ -1,8 +1,28 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:import href="http://docbook.sourceforge.net/release/xsl/1.72.0/fo/docbook.xsl" />
<xsl:import href="classpath:/xslt/org/jboss/pdf.xsl" />
<xsl:param name="body.font.family" select="'Times New Roman, serif'" />
<xsl:param name="monospace.font.family" select="'DejaVu Sans Mono, monospace'" />
<xsl:param name="sans.font.family" select="'Arial, sans-serif'" />
<xsl:param name="title.font.family" select="$body.font.family" />
<xsl:param name="programlisting.font" select="$monospace.font.family" />
<xsl:param name="programlisting.font.size" select="'75%'" />
<xsl:param name="callout.graphics" select="1" />
<xsl:param name="callout.unicode" select="0" />
<xsl:param name="callout.unicode.font" select="'Malgun Gothic, sans-serif'" />
<xsl:param name="ulink.show" select="0"/>
<xsl:attribute-set name="xref.properties">
<xsl:attribute name="font-style">normal</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="//programlisting/*/text()|//programlisting/*/*/text()">
<fo:inline font-size="75%">
<xsl:value-of select="." />
</fo:inline>
</xsl:template>
</xsl:stylesheet>