Tiny Javadoc improvement in ReplayingDecoder
This commit is contained in:
parent
f670bb238d
commit
19cff0c04e
@ -121,43 +121,43 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
|
||||
* <li>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:
|
||||
* <pre>public class MyDecoder extends ReplayingDecoder<VoidEnum> {
|
||||
* <pre> public class MyDecoder extends ReplayingDecoder<VoidEnum> {
|
||||
*
|
||||
* private final Queue<Integer> values = new LinkedList<Integer>();
|
||||
* private final Queue<Integer> values = new LinkedList<Integer>();
|
||||
*
|
||||
* public Object decode(.., ChannelBuffer buffer, ..) throws Exception {
|
||||
* public Object decode(.., ChannelBuffer buffer, ..) throws Exception {
|
||||
*
|
||||
* // A message contains 2 integers.
|
||||
* values.offer(buffer.readInt());
|
||||
* values.offer(buffer.readInt());
|
||||
* // A message contains 2 integers.
|
||||
* values.offer(buffer.readInt());
|
||||
* values.offer(buffer.readInt());
|
||||
*
|
||||
* // This assertion will fail intermittently since values.offer()
|
||||
* // can be called more than two times!
|
||||
* assert values.size() == 2;
|
||||
* return values.poll() + values.poll();
|
||||
* }
|
||||
* // This assertion will fail intermittently since values.offer()
|
||||
* // can be called more than two times!
|
||||
* assert values.size() == 2;
|
||||
* return values.poll() + values.poll();
|
||||
* }
|
||||
* }</pre>
|
||||
* The correct implementation looks like the following, and you can utilize
|
||||
* the 'checkpoint' feature which is explained in detail in the next
|
||||
* section.
|
||||
* <pre>public class MyDecoder extends ReplayingDecoder<VoidEnum> {
|
||||
* The correct implementation looks like the following, and you can also
|
||||
* utilize the 'checkpoint' feature which is explained in detail in the
|
||||
* next section.
|
||||
* <pre> public class MyDecoder extends ReplayingDecoder<VoidEnum> {
|
||||
*
|
||||
* private final Queue<Integer> values = new LinkedList<Integer>();
|
||||
* private final Queue<Integer> values = new LinkedList<Integer>();
|
||||
*
|
||||
* public Object decode(.., ChannelBuffer buffer, ..) throws Exception {
|
||||
* public Object decode(.., ChannelBuffer buffer, ..) throws Exception {
|
||||
*
|
||||
* // Revert the state of the variable that might have been changed
|
||||
* // since the last partial decode.
|
||||
* values.clear();
|
||||
* // Revert the state of the variable that might have been changed
|
||||
* // since the last partial decode.
|
||||
* values.clear();
|
||||
*
|
||||
* // A message contains 2 integers.
|
||||
* values.offer(buffer.readInt());
|
||||
* values.offer(buffer.readInt());
|
||||
* // A message contains 2 integers.
|
||||
* values.offer(buffer.readInt());
|
||||
* values.offer(buffer.readInt());
|
||||
*
|
||||
* // Now we know this assertion will never fail.
|
||||
* assert values.size() == 2;
|
||||
* return values.poll() + values.poll();
|
||||
* }
|
||||
* // Now we know this assertion will never fail.
|
||||
* assert values.size() == 2;
|
||||
* return values.poll() + values.poll();
|
||||
* }
|
||||
* }</pre>
|
||||
* </li>
|
||||
* </ul>
|
||||
|
Loading…
Reference in New Issue
Block a user