Fixed various inspector warnings

This commit is contained in:
Trustin Lee 2013-11-04 20:19:33 +09:00
parent ff34bb08a6
commit f7c70366ea
14 changed files with 48 additions and 49 deletions

View File

@ -16,7 +16,6 @@
package io.netty.handler.codec.memcache;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.AbstractReferenceCounted;
/**
* The default {@link MemcacheObject} implementation.

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.memcache;
import io.netty.buffer.ByteBufHolder;
import io.netty.channel.ChannelPipeline;
/**
* An Memcache content chunk.
@ -23,7 +24,7 @@ import io.netty.buffer.ByteBufHolder;
* A MemcacheObjectDecoder generates {@link MemcacheContent} after
* {@link MemcacheMessage} when the content is large. If you prefer not to
* receive {@link MemcacheContent} in your handler, place a aggregator
* after MemcacheObjectDecoder in the {@link io.netty.channel.ChannelPipeline}.
* after MemcacheObjectDecoder in the {@link ChannelPipeline}.
*/
public interface MemcacheContent extends MemcacheObject, ByteBufHolder {

View File

@ -15,25 +15,29 @@
*/
package io.netty.handler.codec.memcache;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.memcache.binary.BinaryMemcacheRequestDecoder;
import io.netty.handler.codec.memcache.binary.BinaryMemcacheResponseEncoder;
/**
* A {@link io.netty.channel.ChannelHandler} that aggregates an {@link MemcacheMessage}
* A {@link ChannelHandler} that aggregates an {@link MemcacheMessage}
* 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
* care of memcache messages where the content comes along in chunks. Insert this
* handler after a MemcacheObjectDecoder in the {@link io.netty.channel.ChannelPipeline}.
* handler after a MemcacheObjectDecoder in the {@link ChannelPipeline}.
* <p/>
* For example, here for the binary protocol:
* <p/>
* <pre>
* {@link io.netty.channel.ChannelPipeline} p = ...;
* {@link ChannelPipeline} p = ...;
* ...
* p.addLast("decoder", new {@link io.netty.handler.codec.memcache.binary.BinaryMemcacheRequestDecoder}());
* p.addLast("decoder", new {@link BinaryMemcacheRequestDecoder}());
* p.addLast("aggregator", <b>new {@link MemcacheObjectAggregator}(1048576)</b>);
* ...
* p.addLast("encoder", new {@link io.netty.handler.codec.memcache.binary.BinaryMemcacheResponseEncoder}());
* p.addLast("encoder", new {@link BinaryMemcacheResponseEncoder}());
* p.addLast("handler", new YourMemcacheRequestHandler());
* </pre>
*/
@ -55,7 +59,7 @@ public abstract class MemcacheObjectAggregator extends MessageToMessageDecoder<M
private final int maxContentLength;
public MemcacheObjectAggregator(int maxContentLength) {
protected MemcacheObjectAggregator(int maxContentLength) {
if (maxContentLength <= 0) {
throw new IllegalArgumentException("maxContentLength must be a positive integer: " + maxContentLength);
}

View File

@ -45,7 +45,7 @@ public final class BinaryMemcacheClientCodec
* Create a new {@link BinaryMemcacheClientCodec} with the default settings applied.
*/
public BinaryMemcacheClientCodec() {
this(Decoder.DEFAULT_MAX_CHUNK_SIZE);
this(BinaryMemcacheDecoder.DEFAULT_MAX_CHUNK_SIZE);
}
/**
@ -92,10 +92,10 @@ public final class BinaryMemcacheClientCodec
super.decode(ctx, in, out);
if (failOnMissingResponse) {
int size = out.size();
for (int i = oldSize; i < size; size++) {
final int size = out.size();
for (int i = oldSize; i < size; i ++) {
Object msg = out.get(i);
if (msg != null && msg instanceof LastMemcacheContent) {
if (msg instanceof LastMemcacheContent) {
requestResponseCounter.decrementAndGet();
}
}

View File

@ -26,14 +26,14 @@ import io.netty.util.CharsetUtil;
import java.util.List;
import static io.netty.buffer.ByteBufUtil.readBytes;
import static io.netty.buffer.ByteBufUtil.*;
/**
* Decoder for both {@link BinaryMemcacheRequest} and {@link BinaryMemcacheResponse}.
* <p/>
* The difference in the protocols (header) is implemented by the subclasses.
*/
public abstract class BinaryMemcacheDecoder<M extends BinaryMemcacheMessage, H extends BinaryMemcacheMessageHeader>
public abstract class BinaryMemcacheDecoder<M extends BinaryMemcacheMessage<H>, H extends BinaryMemcacheMessageHeader>
extends MemcacheObjectDecoder {
public static final int DEFAULT_MAX_CHUNK_SIZE = 8192;
@ -50,7 +50,7 @@ public abstract class BinaryMemcacheDecoder<M extends BinaryMemcacheMessage, H e
/**
* Create a new {@link BinaryMemcacheDecoder} with default settings.
*/
public BinaryMemcacheDecoder() {
protected BinaryMemcacheDecoder() {
this(DEFAULT_MAX_CHUNK_SIZE);
}
@ -59,7 +59,7 @@ public abstract class BinaryMemcacheDecoder<M extends BinaryMemcacheMessage, H e
*
* @param chunkSize the maximum chunk size of the payload.
*/
public BinaryMemcacheDecoder(int chunkSize) {
protected BinaryMemcacheDecoder(int chunkSize) {
if (chunkSize < 0) {
throw new IllegalArgumentException("chunkSize must be a positive integer: " + chunkSize);
}
@ -110,7 +110,9 @@ public abstract class BinaryMemcacheDecoder<M extends BinaryMemcacheMessage, H e
if (valueLength > 0) {
if (toRead == 0) {
return;
} else if (toRead > chunkSize) {
}
if (toRead > chunkSize) {
toRead = chunkSize;
}
@ -119,7 +121,7 @@ public abstract class BinaryMemcacheDecoder<M extends BinaryMemcacheMessage, H e
}
ByteBuf chunkBuffer = readBytes(ctx.alloc(), in, toRead);
boolean isLast = (alreadyReadChunkSize + toRead) >= valueLength;
boolean isLast = alreadyReadChunkSize + toRead >= valueLength;
MemcacheContent chunk = isLast
? new DefaultLastMemcacheContent(chunkBuffer)
: new DefaultMemcacheContent(chunkBuffer);

View File

@ -18,20 +18,21 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.memcache.MemcacheObjectEncoder;
import io.netty.util.CharsetUtil;
/**
* A {@link io.netty.handler.codec.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 extends BinaryMemcacheMessageHeader>
public abstract class BinaryMemcacheEncoder<M extends BinaryMemcacheMessage<H>, H extends BinaryMemcacheMessageHeader>
extends MemcacheObjectEncoder<M> {
@Override
protected ByteBuf encodeMessage(ChannelHandlerContext ctx, M msg) {
ByteBuf buf = ctx.alloc().buffer();
encodeHeader(buf, (H) msg.getHeader());
encodeHeader(buf, msg.getHeader());
encodeExtras(buf, msg.getExtras());
encodeKey(buf, msg.getKey());
@ -44,7 +45,7 @@ public abstract class BinaryMemcacheEncoder<M extends BinaryMemcacheMessage, H e
* @param buf the {@link ByteBuf} to write into.
* @param extras the extras to encode.
*/
private void encodeExtras(ByteBuf buf, ByteBuf extras) {
private static void encodeExtras(ByteBuf buf, ByteBuf extras) {
if (extras == null) {
return;
}
@ -58,7 +59,7 @@ public abstract class BinaryMemcacheEncoder<M extends BinaryMemcacheMessage, H e
* @param buf the {@link ByteBuf} to write into.
* @param key the key to encode.
*/
private void encodeKey(ByteBuf buf, String key) {
private static void encodeKey(ByteBuf buf, String key) {
if (key == null || key.isEmpty()) {
return;
}

View File

@ -17,7 +17,6 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.memcache.MemcacheMessage;
import io.netty.handler.codec.memcache.MemcacheObject;
/**
* An interface that defines a binary Memcache message, providing common properties for
@ -56,11 +55,13 @@ public interface BinaryMemcacheMessage<H extends BinaryMemcacheMessageHeader> ex
/**
* Increases the reference count by {@code 1}.
*/
BinaryMemcacheMessage retain();
@Override
BinaryMemcacheMessage<H> retain();
/**
* Increases the reference count by the specified {@code increment}.
*/
BinaryMemcacheMessage retain(int increment);
@Override
BinaryMemcacheMessage<H> retain(int increment);
}

View File

@ -25,6 +25,7 @@ public interface BinaryMemcacheRequest extends BinaryMemcacheMessage<BinaryMemca
*
* @return the required request header.
*/
@Override
BinaryMemcacheRequestHeader getHeader();
}

View File

@ -21,7 +21,7 @@ package io.netty.handler.codec.memcache.binary;
* <p/>
* <p>Note that while the additional field in the request is called "reserved", it can still be used for a custom
* memcached implementation. It will not be mirrored back like the
* {@link io.netty.handler.codec.memcache.binary.BinaryMemcacheRequestHeader#getOpaque()} field, because in the
* {@link BinaryMemcacheRequestHeader#getOpaque()} field, because in the
* {@link BinaryMemcacheResponseHeader}, the status field is set there instead.</p>
*/
public interface BinaryMemcacheRequestHeader extends BinaryMemcacheMessageHeader {

View File

@ -25,6 +25,7 @@ public interface BinaryMemcacheResponse extends BinaryMemcacheMessage<BinaryMemc
*
* @return the required response header.
*/
@Override
BinaryMemcacheResponseHeader getHeader();
}

View File

@ -28,7 +28,7 @@ public class BinaryMemcacheServerCodec
extends CombinedChannelDuplexHandler<BinaryMemcacheRequestDecoder, BinaryMemcacheResponseEncoder> {
public BinaryMemcacheServerCodec() {
this(BinaryMemcacheRequestDecoder.DEFAULT_MAX_CHUNK_SIZE);
this(BinaryMemcacheDecoder.DEFAULT_MAX_CHUNK_SIZE);
}
public BinaryMemcacheServerCodec(int decodeChunkSize) {

View File

@ -17,8 +17,6 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.memcache.DefaultMemcacheObject;
import io.netty.util.AbstractReferenceCounted;
import io.netty.util.ReferenceCounted;
/**
* Default implementation of a {@link BinaryMemcacheMessage}.
@ -49,7 +47,7 @@ public abstract class DefaultBinaryMemcacheMessage<H extends BinaryMemcacheMessa
* @param key the message key.
* @param extras the message extras.
*/
public DefaultBinaryMemcacheMessage(H header, String key, ByteBuf extras) {
protected DefaultBinaryMemcacheMessage(H header, String key, ByteBuf extras) {
this.header = header;
this.key = key;
this.extras = extras;
@ -79,7 +77,7 @@ public abstract class DefaultBinaryMemcacheMessage<H extends BinaryMemcacheMessa
}
@Override
public BinaryMemcacheMessage retain() {
public BinaryMemcacheMessage<H> retain() {
if (extras != null) {
extras.retain();
}
@ -87,7 +85,7 @@ public abstract class DefaultBinaryMemcacheMessage<H extends BinaryMemcacheMessa
}
@Override
public BinaryMemcacheMessage retain(int increment) {
public BinaryMemcacheMessage<H> retain(int increment) {
if (extras != null) {
extras.retain(increment);
}

View File

@ -23,9 +23,8 @@ import io.netty.handler.codec.memcache.MemcacheContent;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
@ -40,7 +39,7 @@ public class BinaryMemcacheDecoderTest {
/**
* Represents a GET request header with a key size of three.
*/
private static final byte[] GET_REQUEST = new byte[]{
private static final byte[] GET_REQUEST = {
(byte) 0x80, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03,
@ -50,7 +49,7 @@ public class BinaryMemcacheDecoderTest {
0x66, 0x6f, 0x6f
};
private static final byte[] SET_REQUEST_WITH_CONTENT = new byte[]{
private static final byte[] SET_REQUEST_WITH_CONTENT = {
(byte) 0x80, 0x01, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0B,

View File

@ -18,18 +18,10 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.memcache.LastMemcacheContent;
import io.netty.handler.codec.memcache.MemcacheContent;
import io.netty.util.CharsetUtil;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import java.nio.charset.Charset;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
@ -38,7 +30,7 @@ import static org.hamcrest.core.IsNull.nullValue;
*/
public class BinaryMemcacheObjectAggregatorTest {
private static final byte[] SET_REQUEST_WITH_CONTENT = new byte[]{
private static final byte[] SET_REQUEST_WITH_CONTENT = {
(byte) 0x80, 0x01, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0B,