ZeroCopyFrameDecoder: Follow checkstyle rules
This commit is contained in:
parent
a3f46b5359
commit
0086eb3e1d
@ -15,7 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.jboss.netty.handler.codec.frame;
|
package org.jboss.netty.handler.codec.frame;
|
||||||
|
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||||
import org.jboss.netty.buffer.ChannelBuffers;
|
import org.jboss.netty.buffer.ChannelBuffers;
|
||||||
import org.jboss.netty.buffer.CompositeChannelBuffer;
|
import org.jboss.netty.buffer.CompositeChannelBuffer;
|
||||||
import org.jboss.netty.channel.Channel;
|
import org.jboss.netty.channel.Channel;
|
||||||
@ -23,18 +28,16 @@ import org.jboss.netty.channel.ChannelHandler;
|
|||||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||||
import org.jboss.netty.channel.ChannelPipeline;
|
import org.jboss.netty.channel.ChannelPipeline;
|
||||||
import org.jboss.netty.channel.ChannelStateEvent;
|
import org.jboss.netty.channel.ChannelStateEvent;
|
||||||
|
import org.jboss.netty.channel.ChannelUpstreamHandler;
|
||||||
import org.jboss.netty.channel.Channels;
|
import org.jboss.netty.channel.Channels;
|
||||||
import org.jboss.netty.channel.ExceptionEvent;
|
import org.jboss.netty.channel.ExceptionEvent;
|
||||||
import org.jboss.netty.channel.LifeCycleAwareChannelHandler;
|
import org.jboss.netty.channel.LifeCycleAwareChannelHandler;
|
||||||
import org.jboss.netty.channel.MessageEvent;
|
import org.jboss.netty.channel.MessageEvent;
|
||||||
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
|
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
|
||||||
|
import org.jboss.netty.handler.codec.replay.ReplayingDecoder;
|
||||||
import java.net.SocketAddress;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes the received {@link org.jboss.netty.buffer.ChannelBuffer}s into a meaningful frame object.
|
* Decodes the received {@link ChannelBuffer}s into a meaningful frame object.
|
||||||
* <p>
|
* <p>
|
||||||
* In a stream-based transport such as TCP/IP, packets can be fragmented and
|
* In a stream-based transport such as TCP/IP, packets can be fragmented and
|
||||||
* reassembled during transmission even in a LAN environment. For example,
|
* reassembled during transmission even in a LAN environment. For example,
|
||||||
@ -52,9 +55,9 @@ import java.util.List;
|
|||||||
* +----+-------+---+---+
|
* +----+-------+---+---+
|
||||||
* </pre>
|
* </pre>
|
||||||
* <p>
|
* <p>
|
||||||
* {@link org.jboss.netty.handler.codec.frame.ZeroCopyFrameDecoder} helps you defrag the received packets into one or more
|
* {@link ZeroCopyFrameDecoder} helps you defrag the received packets into one or more
|
||||||
* meaningful <strong>frames</strong> that could be easily understood by the
|
* meaningful <strong>frames</strong> that could be easily understood by the
|
||||||
* application logic. In case of the example above, your {@link org.jboss.netty.handler.codec.frame.ZeroCopyFrameDecoder}
|
* application logic. In case of the example above, your {@link ZeroCopyFrameDecoder}
|
||||||
* implementation could defrag the received packets like the following:
|
* implementation could defrag the received packets like the following:
|
||||||
* <pre>
|
* <pre>
|
||||||
* +-----+-----+-----+
|
* +-----+-----+-----+
|
||||||
@ -77,12 +80,12 @@ import java.util.List;
|
|||||||
* DECODER IMPLEMENTATION
|
* DECODER IMPLEMENTATION
|
||||||
* ======================
|
* ======================
|
||||||
*
|
*
|
||||||
* public class IntegerHeaderFrameDecoder extends {@link org.jboss.netty.handler.codec.frame.ZeroCopyFrameDecoder} {
|
* public class IntegerHeaderFrameDecoder extends {@link ZeroCopyFrameDecoder} {
|
||||||
*
|
*
|
||||||
* {@code @Override}
|
* {@code @Override}
|
||||||
* protected Object decode({@link org.jboss.netty.channel.ChannelHandlerContext} ctx,
|
* protected Object decode({@link ChannelHandlerContext} ctx,
|
||||||
* {@link org.jboss.netty.channel.Channel channel},
|
* {@link Channel} channel,
|
||||||
* {@link org.jboss.netty.buffer.ChannelBuffer} buf) throws Exception {
|
* {@link ChannelBuffer} buf) throws Exception {
|
||||||
*
|
*
|
||||||
* // Make sure if the length field was received.
|
* // Make sure if the length field was received.
|
||||||
* if (buf.readableBytes() < 4) {
|
* if (buf.readableBytes() < 4) {
|
||||||
@ -117,7 +120,7 @@ import java.util.List;
|
|||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // There's enough bytes in the buffer. Read it.
|
* // There's enough bytes in the buffer. Read it.
|
||||||
* {@link org.jboss.netty.buffer.ChannelBuffer} frame = buf.readBytes(length);
|
* {@link ChannelBuffer} frame = buf.readBytes(length);
|
||||||
*
|
*
|
||||||
* // Successfully decoded a frame. Return the decoded frame.
|
* // Successfully decoded a frame. Return the decoded frame.
|
||||||
* return <strong>frame</strong>;
|
* return <strong>frame</strong>;
|
||||||
@ -125,34 +128,34 @@ import java.util.List;
|
|||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* <h3>Returning a POJO rather than a {@link org.jboss.netty.buffer.ChannelBuffer}</h3>
|
* <h3>Returning a POJO rather than a {@link ChannelBuffer}</h3>
|
||||||
* <p>
|
* <p>
|
||||||
* Please note that you can return an object of a different type than
|
* Please note that you can return an object of a different type than
|
||||||
* {@link org.jboss.netty.buffer.ChannelBuffer} in your {@code decode()} and {@code decodeLast()}
|
* {@link ChannelBuffer} in your {@code decode()} and {@code decodeLast()}
|
||||||
* implementation. For example, you could return a
|
* implementation. For example, you could return a
|
||||||
* <a href="http://en.wikipedia.org/wiki/POJO">POJO</a> so that the next
|
* <a href="http://en.wikipedia.org/wiki/POJO">POJO</a> so that the next
|
||||||
* {@link org.jboss.netty.channel.ChannelUpstreamHandler} receives a {@link org.jboss.netty.channel.MessageEvent} which
|
* {@link ChannelUpstreamHandler} receives a {@link MessageEvent} which
|
||||||
* contains a POJO rather than a {@link org.jboss.netty.buffer.ChannelBuffer}.
|
* contains a POJO rather than a {@link ChannelBuffer}.
|
||||||
*
|
*
|
||||||
* <h3>Replacing a decoder with another decoder in a pipeline</h3>
|
* <h3>Replacing a decoder with another decoder in a pipeline</h3>
|
||||||
* <p>
|
* <p>
|
||||||
* If you are going to write a protocol multiplexer, you will probably want to
|
* If you are going to write a protocol multiplexer, you will probably want to
|
||||||
* replace a {@link org.jboss.netty.handler.codec.frame.ZeroCopyFrameDecoder} (protocol detector) with another
|
* replace a {@link ZeroCopyFrameDecoder} (protocol detector) with another
|
||||||
* {@link org.jboss.netty.handler.codec.frame.ZeroCopyFrameDecoder} or {@link org.jboss.netty.handler.codec.replay.ReplayingDecoder} (actual protocol decoder).
|
* {@link ZeroCopyFrameDecoder} or {@link ReplayingDecoder} (actual protocol decoder).
|
||||||
* It is not possible to achieve this simply by calling
|
* It is not possible to achieve this simply by calling
|
||||||
* {@link org.jboss.netty.channel.ChannelPipeline#replace(org.jboss.netty.channel.ChannelHandler, String, org.jboss.netty.channel.ChannelHandler)}, but
|
* {@link ChannelPipeline#replace(ChannelHandler, String, ChannelHandler)}, but
|
||||||
* some additional steps are required:
|
* some additional steps are required:
|
||||||
* <pre>
|
* <pre>
|
||||||
* public class FirstDecoder extends {@link org.jboss.netty.handler.codec.frame.ZeroCopyFrameDecoder} {
|
* public class FirstDecoder extends {@link ZeroCopyFrameDecoder} {
|
||||||
*
|
*
|
||||||
* public FirstDecoder() {
|
* public FirstDecoder() {
|
||||||
* super(true); // Enable unfold
|
* super(true); // Enable unfold
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* {@code @Override}
|
* {@code @Override}
|
||||||
* protected Object decode({@link org.jboss.netty.channel.ChannelHandlerContext} ctx,
|
* protected Object decode({@link ChannelHandlerContext} ctx,
|
||||||
* {@link org.jboss.netty.channel.Channel} channel,
|
* {@link Channel} channel,
|
||||||
* {@link org.jboss.netty.buffer.ChannelBuffer} buf) {
|
* {@link ChannelBuffer} buf) {
|
||||||
* ...
|
* ...
|
||||||
* // Decode the first message
|
* // Decode the first message
|
||||||
* Object firstMessage = ...;
|
* Object firstMessage = ...;
|
||||||
@ -176,7 +179,8 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @apiviz.landmark
|
* @apiviz.landmark
|
||||||
*/
|
*/
|
||||||
public abstract class ZeroCopyFrameDecoder extends SimpleChannelUpstreamHandler implements LifeCycleAwareChannelHandler {
|
public abstract class ZeroCopyFrameDecoder
|
||||||
|
extends SimpleChannelUpstreamHandler implements LifeCycleAwareChannelHandler {
|
||||||
|
|
||||||
private final boolean unfold;
|
private final boolean unfold;
|
||||||
protected List<ChannelBuffer> cumulation;
|
protected List<ChannelBuffer> cumulation;
|
||||||
@ -349,8 +353,8 @@ public abstract class ZeroCopyFrameDecoder extends SimpleChannelUpstreamHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets called on {@link #channelDisconnected(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelStateEvent)} and
|
* Gets called on {@link #channelDisconnected(ChannelHandlerContext, ChannelStateEvent)} and
|
||||||
* {@link #channelClosed(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelStateEvent)}
|
* {@link #channelClosed(ChannelHandlerContext, ChannelStateEvent)}
|
||||||
*/
|
*/
|
||||||
protected void cleanup(ChannelHandlerContext ctx, ChannelStateEvent e)
|
protected void cleanup(ChannelHandlerContext ctx, ChannelStateEvent e)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@ -381,11 +385,11 @@ public abstract class ZeroCopyFrameDecoder extends SimpleChannelUpstreamHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link org.jboss.netty.buffer.ChannelBuffer} which is used for the cumulation.
|
* Create a new {@link ChannelBuffer} which is used for the cumulation.
|
||||||
* Sub-classes may override this.
|
* Sub-classes may override this.
|
||||||
*
|
*
|
||||||
* @param ctx {@link org.jboss.netty.channel.ChannelHandlerContext} for this handler
|
* @param ctx {@link ChannelHandlerContext} for this handler
|
||||||
* @return buffer the {@link org.jboss.netty.buffer.ChannelBuffer} which is used for cumulation
|
* @return buffer the {@link ChannelBuffer} which is used for cumulation
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
protected ChannelBuffer newCumulationBuffer(
|
protected ChannelBuffer newCumulationBuffer(
|
||||||
@ -394,8 +398,8 @@ public abstract class ZeroCopyFrameDecoder extends SimpleChannelUpstreamHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace this {@link org.jboss.netty.handler.codec.frame.ZeroCopyFrameDecoder} in the {@link org.jboss.netty.channel.ChannelPipeline} with the given {@link org.jboss.netty.channel.ChannelHandler}. All
|
* Replace this {@link ZeroCopyFrameDecoder} in the {@link ChannelPipeline} with the given {@link ChannelHandler}.
|
||||||
* remaining bytes in the {@link org.jboss.netty.buffer.ChannelBuffer} will get send to the new {@link org.jboss.netty.channel.ChannelHandler} that was used
|
* All remaining bytes in the {@link ChannelBuffer} will get send to the new {@link ChannelHandler} that was used
|
||||||
* as replacement
|
* as replacement
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user