codec-memcache: prefix abstract classes with Abstract.
This commit is contained in:
parent
fcb32a77b9
commit
b17a765615
@ -27,7 +27,7 @@ import io.netty.handler.codec.memcache.binary.BinaryMemcacheResponseEncoder;
|
|||||||
* and its following {@link MemcacheContent}s into a single {@link MemcacheMessage} with
|
* and its following {@link MemcacheContent}s into a single {@link MemcacheMessage} with
|
||||||
* no following {@link MemcacheContent}s. It is useful when you don't want to take
|
* no following {@link MemcacheContent}s. It is useful when you don't want to take
|
||||||
* care of memcache messages where the content comes along in chunks. Insert this
|
* care of memcache messages where the content comes along in chunks. Insert this
|
||||||
* handler after a MemcacheObjectDecoder in the {@link ChannelPipeline}.
|
* handler after a AbstractMemcacheObjectDecoder in the {@link ChannelPipeline}.
|
||||||
* <p/>
|
* <p/>
|
||||||
* For example, here for the binary protocol:
|
* For example, here for the binary protocol:
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -35,13 +35,14 @@ import io.netty.handler.codec.memcache.binary.BinaryMemcacheResponseEncoder;
|
|||||||
* {@link ChannelPipeline} p = ...;
|
* {@link ChannelPipeline} p = ...;
|
||||||
* ...
|
* ...
|
||||||
* p.addLast("decoder", new {@link BinaryMemcacheRequestDecoder}());
|
* p.addLast("decoder", new {@link BinaryMemcacheRequestDecoder}());
|
||||||
* p.addLast("aggregator", <b>new {@link MemcacheObjectAggregator}(1048576)</b>);
|
* p.addLast("aggregator", <b>new {@link io.netty.handler.codec.memcache.binary.BinaryMemcacheObjectAggregator}(1048576)
|
||||||
|
* </b>);
|
||||||
* ...
|
* ...
|
||||||
* p.addLast("encoder", new {@link BinaryMemcacheResponseEncoder}());
|
* p.addLast("encoder", new {@link BinaryMemcacheResponseEncoder}());
|
||||||
* p.addLast("handler", new YourMemcacheRequestHandler());
|
* p.addLast("handler", new YourMemcacheRequestHandler());
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public abstract class MemcacheObjectAggregator extends MessageToMessageDecoder<MemcacheObject> {
|
public abstract class AbstractMemcacheObjectAggregator extends MessageToMessageDecoder<MemcacheObject> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the current message that gets aggregated.
|
* Contains the current message that gets aggregated.
|
||||||
@ -59,7 +60,7 @@ public abstract class MemcacheObjectAggregator extends MessageToMessageDecoder<M
|
|||||||
|
|
||||||
private final int maxContentLength;
|
private final int maxContentLength;
|
||||||
|
|
||||||
protected MemcacheObjectAggregator(int maxContentLength) {
|
protected AbstractMemcacheObjectAggregator(int maxContentLength) {
|
||||||
if (maxContentLength <= 0) {
|
if (maxContentLength <= 0) {
|
||||||
throw new IllegalArgumentException("maxContentLength must be a positive integer: " + maxContentLength);
|
throw new IllegalArgumentException("maxContentLength must be a positive integer: " + maxContentLength);
|
||||||
}
|
}
|
@ -23,5 +23,5 @@ import io.netty.handler.codec.ByteToMessageDecoder;
|
|||||||
* Currently it just acts as a common denominator, but will certainly include methods once the ascii protocol
|
* Currently it just acts as a common denominator, but will certainly include methods once the ascii protocol
|
||||||
* is implemented.
|
* is implemented.
|
||||||
*/
|
*/
|
||||||
public abstract class MemcacheObjectDecoder extends ByteToMessageDecoder {
|
public abstract class AbstractMemcacheObjectDecoder extends ByteToMessageDecoder {
|
||||||
}
|
}
|
@ -25,13 +25,13 @@ import io.netty.util.internal.StringUtil;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A general purpose {@link MemcacheObjectEncoder} that encodes {@link MemcacheMessage}s.
|
* A general purpose {@link AbstractMemcacheObjectEncoder} that encodes {@link MemcacheMessage}s.
|
||||||
* <p/>
|
* <p/>
|
||||||
* <p>Note that this class is designed to be extended, especially because both the binary and ascii protocol
|
* <p>Note that this class is designed to be extended, especially because both the binary and ascii protocol
|
||||||
* require different treatment of their messages. Since the content chunk writing is the same for both, the encoder
|
* require different treatment of their messages. Since the content chunk writing is the same for both, the encoder
|
||||||
* abstracts this right away.</p>
|
* abstracts this right away.</p>
|
||||||
*/
|
*/
|
||||||
public abstract class MemcacheObjectEncoder<M extends MemcacheMessage> extends MessageToMessageEncoder<Object> {
|
public abstract class AbstractMemcacheObjectEncoder<M extends MemcacheMessage> extends MessageToMessageEncoder<Object> {
|
||||||
|
|
||||||
private boolean expectingMoreContent;
|
private boolean expectingMoreContent;
|
||||||
|
|
@ -21,10 +21,10 @@ import io.netty.channel.ChannelPipeline;
|
|||||||
/**
|
/**
|
||||||
* An Memcache content chunk.
|
* An Memcache content chunk.
|
||||||
* <p/>
|
* <p/>
|
||||||
* A MemcacheObjectDecoder generates {@link MemcacheContent} after
|
* A implementation of a {@link AbstractMemcacheObjectDecoder} generates {@link MemcacheContent} after
|
||||||
* {@link MemcacheMessage} when the content is large. If you prefer not to
|
* {@link MemcacheMessage} when the content is large. If you prefer not to receive {@link MemcacheContent}
|
||||||
* receive {@link MemcacheContent} in your handler, place a aggregator
|
* in your handler, place a aggregator after an implementation of the {@link AbstractMemcacheObjectDecoder}
|
||||||
* after MemcacheObjectDecoder in the {@link ChannelPipeline}.
|
* in the {@link ChannelPipeline}.
|
||||||
*/
|
*/
|
||||||
public interface MemcacheContent extends MemcacheObject, ByteBufHolder {
|
public interface MemcacheContent extends MemcacheObject, ByteBufHolder {
|
||||||
|
|
||||||
|
@ -17,11 +17,11 @@ package io.netty.handler.codec.memcache.binary;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.handler.codec.memcache.AbstractMemcacheObjectDecoder;
|
||||||
import io.netty.handler.codec.memcache.DefaultLastMemcacheContent;
|
import io.netty.handler.codec.memcache.DefaultLastMemcacheContent;
|
||||||
import io.netty.handler.codec.memcache.DefaultMemcacheContent;
|
import io.netty.handler.codec.memcache.DefaultMemcacheContent;
|
||||||
import io.netty.handler.codec.memcache.LastMemcacheContent;
|
import io.netty.handler.codec.memcache.LastMemcacheContent;
|
||||||
import io.netty.handler.codec.memcache.MemcacheContent;
|
import io.netty.handler.codec.memcache.MemcacheContent;
|
||||||
import io.netty.handler.codec.memcache.MemcacheObjectDecoder;
|
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -33,8 +33,9 @@ import static io.netty.buffer.ByteBufUtil.*;
|
|||||||
* <p/>
|
* <p/>
|
||||||
* The difference in the protocols (header) is implemented by the subclasses.
|
* The difference in the protocols (header) is implemented by the subclasses.
|
||||||
*/
|
*/
|
||||||
public abstract class BinaryMemcacheDecoder<M extends BinaryMemcacheMessage<H>, H extends BinaryMemcacheMessageHeader>
|
public abstract class AbstractBinaryMemcacheDecoder
|
||||||
extends MemcacheObjectDecoder {
|
<M extends BinaryMemcacheMessage<H>, H extends BinaryMemcacheMessageHeader>
|
||||||
|
extends AbstractMemcacheObjectDecoder {
|
||||||
|
|
||||||
public static final int DEFAULT_MAX_CHUNK_SIZE = 8192;
|
public static final int DEFAULT_MAX_CHUNK_SIZE = 8192;
|
||||||
|
|
||||||
@ -48,18 +49,18 @@ public abstract class BinaryMemcacheDecoder<M extends BinaryMemcacheMessage<H>,
|
|||||||
private State state = State.READ_HEADER;
|
private State state = State.READ_HEADER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link BinaryMemcacheDecoder} with default settings.
|
* Create a new {@link AbstractBinaryMemcacheDecoder} with default settings.
|
||||||
*/
|
*/
|
||||||
protected BinaryMemcacheDecoder() {
|
protected AbstractBinaryMemcacheDecoder() {
|
||||||
this(DEFAULT_MAX_CHUNK_SIZE);
|
this(DEFAULT_MAX_CHUNK_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link BinaryMemcacheDecoder} with custom settings.
|
* Create a new {@link AbstractBinaryMemcacheDecoder} with custom settings.
|
||||||
*
|
*
|
||||||
* @param chunkSize the maximum chunk size of the payload.
|
* @param chunkSize the maximum chunk size of the payload.
|
||||||
*/
|
*/
|
||||||
protected BinaryMemcacheDecoder(int chunkSize) {
|
protected AbstractBinaryMemcacheDecoder(int chunkSize) {
|
||||||
if (chunkSize < 0) {
|
if (chunkSize < 0) {
|
||||||
throw new IllegalArgumentException("chunkSize must be a positive integer: " + chunkSize);
|
throw new IllegalArgumentException("chunkSize must be a positive integer: " + chunkSize);
|
||||||
}
|
}
|
@ -18,14 +18,15 @@ package io.netty.handler.codec.memcache.binary;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
import io.netty.handler.codec.memcache.MemcacheObjectEncoder;
|
import io.netty.handler.codec.memcache.AbstractMemcacheObjectEncoder;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link MessageToByteEncoder} that encodes binary memache messages into bytes.
|
* A {@link MessageToByteEncoder} that encodes binary memache messages into bytes.
|
||||||
*/
|
*/
|
||||||
public abstract class BinaryMemcacheEncoder<M extends BinaryMemcacheMessage<H>, H extends BinaryMemcacheMessageHeader>
|
public abstract class AbstractBinaryMemcacheEncoder
|
||||||
extends MemcacheObjectEncoder<M> {
|
<M extends BinaryMemcacheMessage<H>, H extends BinaryMemcacheMessageHeader>
|
||||||
|
extends AbstractMemcacheObjectEncoder<M> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Every binary memcache message has at least a 24 bytes header.
|
* Every binary memcache message has at least a 24 bytes header.
|
@ -18,7 +18,7 @@ package io.netty.handler.codec.memcache.binary;
|
|||||||
/**
|
/**
|
||||||
* The default implementation of a {@link BinaryMemcacheMessageHeader}.
|
* The default implementation of a {@link BinaryMemcacheMessageHeader}.
|
||||||
*/
|
*/
|
||||||
public abstract class DefaultBinaryMemcacheMessageHeader implements BinaryMemcacheMessageHeader {
|
public abstract class AbstractBinaryMemcacheMessageHeader implements BinaryMemcacheMessageHeader {
|
||||||
|
|
||||||
private byte magic;
|
private byte magic;
|
||||||
private byte opcode;
|
private byte opcode;
|
@ -45,7 +45,7 @@ public final class BinaryMemcacheClientCodec
|
|||||||
* Create a new {@link BinaryMemcacheClientCodec} with the default settings applied.
|
* Create a new {@link BinaryMemcacheClientCodec} with the default settings applied.
|
||||||
*/
|
*/
|
||||||
public BinaryMemcacheClientCodec() {
|
public BinaryMemcacheClientCodec() {
|
||||||
this(BinaryMemcacheDecoder.DEFAULT_MAX_CHUNK_SIZE);
|
this(AbstractBinaryMemcacheDecoder.DEFAULT_MAX_CHUNK_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,20 +20,20 @@ import io.netty.buffer.Unpooled;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.DecoderResult;
|
import io.netty.handler.codec.DecoderResult;
|
||||||
import io.netty.handler.codec.TooLongFrameException;
|
import io.netty.handler.codec.TooLongFrameException;
|
||||||
|
import io.netty.handler.codec.memcache.AbstractMemcacheObjectAggregator;
|
||||||
import io.netty.handler.codec.memcache.FullMemcacheMessage;
|
import io.netty.handler.codec.memcache.FullMemcacheMessage;
|
||||||
import io.netty.handler.codec.memcache.LastMemcacheContent;
|
import io.netty.handler.codec.memcache.LastMemcacheContent;
|
||||||
import io.netty.handler.codec.memcache.MemcacheContent;
|
import io.netty.handler.codec.memcache.MemcacheContent;
|
||||||
import io.netty.handler.codec.memcache.MemcacheMessage;
|
import io.netty.handler.codec.memcache.MemcacheMessage;
|
||||||
import io.netty.handler.codec.memcache.MemcacheObject;
|
import io.netty.handler.codec.memcache.MemcacheObject;
|
||||||
import io.netty.handler.codec.memcache.MemcacheObjectAggregator;
|
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link MemcacheObjectAggregator} for the binary protocol.
|
* A memcache object aggregator for the binary protocol.
|
||||||
*/
|
*/
|
||||||
public class BinaryMemcacheObjectAggregator extends MemcacheObjectAggregator {
|
public class BinaryMemcacheObjectAggregator extends AbstractMemcacheObjectAggregator {
|
||||||
|
|
||||||
private boolean tooLongFrameFound;
|
private boolean tooLongFrameFound;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
* The decoder part which takes care of decoding the request-specific headers.
|
* The decoder part which takes care of decoding the request-specific headers.
|
||||||
*/
|
*/
|
||||||
public class BinaryMemcacheRequestDecoder
|
public class BinaryMemcacheRequestDecoder
|
||||||
extends BinaryMemcacheDecoder<BinaryMemcacheRequest, BinaryMemcacheRequestHeader> {
|
extends AbstractBinaryMemcacheDecoder<BinaryMemcacheRequest, BinaryMemcacheRequestHeader> {
|
||||||
|
|
||||||
public BinaryMemcacheRequestDecoder() {
|
public BinaryMemcacheRequestDecoder() {
|
||||||
this(DEFAULT_MAX_CHUNK_SIZE);
|
this(DEFAULT_MAX_CHUNK_SIZE);
|
||||||
|
@ -21,7 +21,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
* The encoder part which takes care of encoding the request headers.
|
* The encoder part which takes care of encoding the request headers.
|
||||||
*/
|
*/
|
||||||
public class BinaryMemcacheRequestEncoder
|
public class BinaryMemcacheRequestEncoder
|
||||||
extends BinaryMemcacheEncoder<BinaryMemcacheRequest, BinaryMemcacheRequestHeader> {
|
extends AbstractBinaryMemcacheEncoder<BinaryMemcacheRequest, BinaryMemcacheRequestHeader> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encodeHeader(ByteBuf buf, BinaryMemcacheRequestHeader header) {
|
protected void encodeHeader(ByteBuf buf, BinaryMemcacheRequestHeader header) {
|
||||||
|
@ -21,7 +21,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
* The decoder which takes care of decoding the response headers.
|
* The decoder which takes care of decoding the response headers.
|
||||||
*/
|
*/
|
||||||
public class BinaryMemcacheResponseDecoder
|
public class BinaryMemcacheResponseDecoder
|
||||||
extends BinaryMemcacheDecoder<BinaryMemcacheResponse, BinaryMemcacheResponseHeader> {
|
extends AbstractBinaryMemcacheDecoder<BinaryMemcacheResponse, BinaryMemcacheResponseHeader> {
|
||||||
|
|
||||||
public BinaryMemcacheResponseDecoder() {
|
public BinaryMemcacheResponseDecoder() {
|
||||||
this(DEFAULT_MAX_CHUNK_SIZE);
|
this(DEFAULT_MAX_CHUNK_SIZE);
|
||||||
|
@ -21,7 +21,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
* The encoder which takes care of encoding the response headers.
|
* The encoder which takes care of encoding the response headers.
|
||||||
*/
|
*/
|
||||||
public class BinaryMemcacheResponseEncoder
|
public class BinaryMemcacheResponseEncoder
|
||||||
extends BinaryMemcacheEncoder<BinaryMemcacheResponse, BinaryMemcacheResponseHeader> {
|
extends AbstractBinaryMemcacheEncoder<BinaryMemcacheResponse, BinaryMemcacheResponseHeader> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encodeHeader(ByteBuf buf, BinaryMemcacheResponseHeader header) {
|
protected void encodeHeader(ByteBuf buf, BinaryMemcacheResponseHeader header) {
|
||||||
|
@ -28,7 +28,7 @@ public class BinaryMemcacheServerCodec
|
|||||||
extends CombinedChannelDuplexHandler<BinaryMemcacheRequestDecoder, BinaryMemcacheResponseEncoder> {
|
extends CombinedChannelDuplexHandler<BinaryMemcacheRequestDecoder, BinaryMemcacheResponseEncoder> {
|
||||||
|
|
||||||
public BinaryMemcacheServerCodec() {
|
public BinaryMemcacheServerCodec() {
|
||||||
this(BinaryMemcacheDecoder.DEFAULT_MAX_CHUNK_SIZE);
|
this(AbstractBinaryMemcacheDecoder.DEFAULT_MAX_CHUNK_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BinaryMemcacheServerCodec(int decodeChunkSize) {
|
public BinaryMemcacheServerCodec(int decodeChunkSize) {
|
||||||
|
@ -18,7 +18,7 @@ package io.netty.handler.codec.memcache.binary;
|
|||||||
/**
|
/**
|
||||||
* The default implementation of a {@link BinaryMemcacheRequestHeader}.
|
* The default implementation of a {@link BinaryMemcacheRequestHeader}.
|
||||||
*/
|
*/
|
||||||
public class DefaultBinaryMemcacheRequestHeader extends DefaultBinaryMemcacheMessageHeader
|
public class DefaultBinaryMemcacheRequestHeader extends AbstractBinaryMemcacheMessageHeader
|
||||||
implements BinaryMemcacheRequestHeader {
|
implements BinaryMemcacheRequestHeader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,7 +18,7 @@ package io.netty.handler.codec.memcache.binary;
|
|||||||
/**
|
/**
|
||||||
* The default implementation of a {@link BinaryMemcacheResponseHeader}.
|
* The default implementation of a {@link BinaryMemcacheResponseHeader}.
|
||||||
*/
|
*/
|
||||||
public class DefaultBinaryMemcacheResponseHeader extends DefaultBinaryMemcacheMessageHeader
|
public class DefaultBinaryMemcacheResponseHeader extends AbstractBinaryMemcacheMessageHeader
|
||||||
implements BinaryMemcacheResponseHeader {
|
implements BinaryMemcacheResponseHeader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +32,7 @@ import static org.hamcrest.core.IsNull.notNullValue;
|
|||||||
import static org.hamcrest.core.IsNull.nullValue;
|
import static org.hamcrest.core.IsNull.nullValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies the correct functionality of the {@link BinaryMemcacheDecoder}.
|
* Verifies the correct functionality of the {@link AbstractBinaryMemcacheDecoder}.
|
||||||
* <p/>
|
* <p/>
|
||||||
* While technically there are both a {@link BinaryMemcacheRequestDecoder} and a {@link BinaryMemcacheResponseDecoder}
|
* While technically there are both a {@link BinaryMemcacheRequestDecoder} and a {@link BinaryMemcacheResponseDecoder}
|
||||||
* they implement the same basics and just differ in the type of headers returned.
|
* they implement the same basics and just differ in the type of headers returned.
|
||||||
|
@ -31,7 +31,7 @@ import static org.hamcrest.core.IsEqual.equalTo;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies the correct functionality of the {@link BinaryMemcacheEncoder}.
|
* Verifies the correct functionality of the {@link AbstractBinaryMemcacheEncoder}.
|
||||||
*/
|
*/
|
||||||
public class BinaryMemcacheEncoderTest {
|
public class BinaryMemcacheEncoderTest {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user