From 14f2e29af9cb23021facc075c38dd42cb8ff678b Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sun, 16 Jun 2013 16:53:03 +0200 Subject: [PATCH] [#1450] Fix examples in ReplayDecoder javadocs --- .../netty/handler/codec/ReplayingDecoder.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java index f1f4025cb5..67ad7311b7 100644 --- a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java @@ -101,12 +101,12 @@ import io.netty.util.internal.StringUtil; *
  • You must keep in mind that {@code decode(..)} method can be called many * times to decode a single message. For example, the following code will * not work: - *
     public class MyDecoder extends {@link ReplayingDecoder}<{@link Integer}, {@link Void}> {
    + * 
     public class MyDecoder extends {@link ReplayingDecoder}<{@link Void}> {
      *
      *   private final Queue<Integer> values = new LinkedList<Integer>();
      *
      *   {@code @Override}
    - *   public {@link Integer} decode(.., {@link ByteBuf} in) throws Exception {
    + *   public void decode(.., {@link ByteBuf} in, {@link MessageList} out) throws Exception {
      *
      *     // A message contains 2 integers.
      *     values.offer(buffer.readInt());
    @@ -115,18 +115,18 @@ import io.netty.util.internal.StringUtil;
      *     // This assertion will fail intermittently since values.offer()
      *     // can be called more than two times!
      *     assert values.size() == 2;
    - *     return values.poll() + values.poll();
    + *     out.add(values.poll() + values.poll());
      *   }
      * }
    * The correct implementation looks like the following, and you can also * utilize the 'checkpoint' feature which is explained in detail in the * next section. - *
     public class MyDecoder extends {@link ReplayingDecoder}<{@link Integer}, {@link Void}> {
    + * 
     public class MyDecoder extends {@link ReplayingDecoder}<{@link Void}> {
      *
      *   private final Queue<Integer> values = new LinkedList<Integer>();
      *
      *   {@code @Override}
    - *   public {@link Integer} decode(.., {@link ByteBuf} buffer) throws Exception {
    + *   public void decode(.., {@link ByteBuf} buffer, {@link MessageList} out) throws Exception {
      *
      *     // Revert the state of the variable that might have been changed
      *     // since the last partial decode.
    @@ -138,7 +138,7 @@ import io.netty.util.internal.StringUtil;
      *
      *     // Now we know this assertion will never fail.
      *     assert values.size() == 2;
    - *     return values.poll() + values.poll();
    + *     out.add(values.poll() + values.poll());
      *   }
      * }
    *
  • @@ -178,8 +178,8 @@ import io.netty.util.internal.StringUtil; * } * * {@code @Override} - * protected {@link Object} decode({@link ChannelHandlerContext} ctx, - * {@link ByteBuf} in) throws Exception { + * protected void decode({@link ChannelHandlerContext} ctx, + * {@link ByteBuf} in, {@link MessageList} out) throws Exception { * switch (state()) { * case READ_LENGTH: * length = buf.readInt(); @@ -187,7 +187,7 @@ import io.netty.util.internal.StringUtil; * case READ_CONTENT: * ByteBuf frame = buf.readBytes(length); * checkpoint(MyDecoderState.READ_LENGTH); - * return frame; + * out.add(frame); * default: * throw new Error("Shouldn't reach here."); * } @@ -206,8 +206,8 @@ import io.netty.util.internal.StringUtil; * private int length; * * {@code @Override} - * protected {@link Object} decode({@link ChannelHandlerContext} ctx, - * {@link ByteBuf} in) throws Exception { + * protected void decode({@link ChannelHandlerContext} ctx, + * {@link ByteBuf} in, {@link MessageList} out) throws Exception { * if (!readLength) { * length = buf.readInt(); * readLength = true; @@ -218,7 +218,7 @@ import io.netty.util.internal.StringUtil; * ByteBuf frame = buf.readBytes(length); * readLength = false; * checkpoint(); - * return frame; + * out.add(frame); * } * } * } @@ -238,7 +238,7 @@ import io.netty.util.internal.StringUtil; * * {@code @Override} * protected Object decode({@link ChannelHandlerContext} ctx, - * {@link ByteBuf} in) { + * {@link ByteBuf} in, {@link MessageList} out) { * ... * // Decode the first message * Object firstMessage = ...; @@ -246,16 +246,16 @@ import io.netty.util.internal.StringUtil; * // Add the second decoder * ctx.pipeline().addLast("second", new SecondDecoder()); * - * // Remove the first decoder (me) - * ctx.pipeline().remove(this); - * * if (buf.isReadable()) { * // Hand off the remaining data to the second decoder - * return new Object[] { firstMessage, buf.readBytes(super.actualReadableBytes()) }; + * out.add(firstMessage); + * out.add(buf.readBytes(super.actualReadableBytes())); * } else { * // Nothing to hand off - * return firstMessage; + * out.add(firstMessage); * } + * // Remove the first decoder (me) + * ctx.pipeline().remove(this); * } * * @param