* Fixed a documentation error in ChannelBuffer javadoc

* Clearly specified that FrameDecoder is an implementation of ChannelHandler
This commit is contained in:
Trustin Lee 2011-02-07 19:58:48 +09:00
parent b53742e366
commit 4d6581fe3d
2 changed files with 18 additions and 11 deletions

View File

@ -692,35 +692,41 @@ public class TimeClientHandler extends &SimpleChannelHandler; {
</para> </para>
<programlisting>package org.jboss.netty.example.time; <programlisting>package org.jboss.netty.example.time;
public class TimeDecoder extends &FrameDecoder; { public class TimeDecoder extends &FrameDecoder;<co id="example.time4.co1"/> {
@Override @Override
protected Object decode( protected Object decode(
&ChannelHandlerContext; ctx, &Channel; channel, &ChannelBuffer; buffer)<co id="example.time4.co1"/> { &ChannelHandlerContext; ctx, &Channel; channel, &ChannelBuffer; buffer)<co id="example.time4.co2"/> {
if (buffer.readableBytes() &lt; 4) { if (buffer.readableBytes() &lt; 4) {
return null; <co id="example.time4.co2"/> return null; <co id="example.time4.co3"/>
} }
return buffer.readBytes(4);<co id="example.time4.co3"/> return buffer.readBytes(4);<co id="example.time4.co4"/>
} }
}</programlisting> }</programlisting>
<calloutlist> <calloutlist>
<callout arearefs="example.time4.co1"> <callout arearefs="example.time4.co1">
<para>
&FrameDecoder; is an implementation of &ChannelHandler; which
makes it easy to which deals with the fragmentation issue.
</para>
</callout>
<callout arearefs="example.time4.co2">
<para> <para>
&FrameDecoder; calls <methodname>decode</methodname> method with &FrameDecoder; calls <methodname>decode</methodname> method with
an internally maintained cumulative buffer whenever new data is an internally maintained cumulative buffer whenever new data is
received. received.
</para> </para>
</callout> </callout>
<callout arearefs="example.time4.co2"> <callout arearefs="example.time4.co3">
<para> <para>
If <literal>null</literal> is returned, it means there's not If <literal>null</literal> is returned, it means there's not
enough data yet. &FrameDecoder; will call again when there is a enough data yet. &FrameDecoder; will call again when there is a
sufficient amount of data. sufficient amount of data.
</para> </para>
</callout> </callout>
<callout arearefs="example.time4.co3"> <callout arearefs="example.time4.co4">
<para> <para>
If non-<literal>null</literal> is returned, it means the If non-<literal>null</literal> is returned, it means the
<methodname>decode</methodname> method has decoded a message <methodname>decode</methodname> method has decoded a message
@ -873,10 +879,11 @@ public void channelConnected(&ChannelHandlerContext; ctx, &ChannelStateEvent; e)
f.addListener(&ChannelFutureListener;.CLOSE); f.addListener(&ChannelFutureListener;.CLOSE);
}</programlisting> }</programlisting>
<para> <para>
Now, the only missing piece is the &ChannelHandler; which translates a Now, the only missing piece is an encoder, which is an implementation of
<classname>UnixTime</classname> back into a &ChannelBuffer;. It's much &ChannelHandler; that translates a <classname>UnixTime</classname> back
simpler than writing a decoder because there's no need to deal with into a &ChannelBuffer;. It's much simpler than writing a decoder because
packet fragmentation and assembly when encoding a message. there's no need to deal with packet fragmentation and assembly when
encoding a message.
</para> </para>
<programlisting>package org.jboss.netty.example.time; <programlisting>package org.jboss.netty.example.time;

View File

@ -48,7 +48,7 @@ import java.nio.charset.UnsupportedCharsetException;
* <pre> * <pre>
* {@link ChannelBuffer} buffer = ...; * {@link ChannelBuffer} buffer = ...;
* for (int i = 0; i &lt; buffer.capacity(); i ++</strong>) { * for (int i = 0; i &lt; buffer.capacity(); i ++</strong>) {
* byte b = array.getByte(i); * byte b = buffer.getByte(i);
* System.out.println((char) b); * System.out.println((char) b);
* } * }
* </pre> * </pre>