From 033a52dbfdcf8cfa3755aa20249c8308de89c490 Mon Sep 17 00:00:00 2001 From: Vladimir Korenev Date: Mon, 19 May 2014 11:47:31 +0300 Subject: [PATCH 1/4] Upgrade Netty to 4.0.19 and Javassist to 3.18.1 --- netty4-client/src/main/java/redis/netty4/RedisClientBase.java | 2 +- netty4/pom.xml | 4 ++-- netty4/src/main/java/redis/netty4/RedisReplyDecoder.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/netty4-client/src/main/java/redis/netty4/RedisClientBase.java b/netty4-client/src/main/java/redis/netty4/RedisClientBase.java index a24770e..e3160c8 100644 --- a/netty4-client/src/main/java/redis/netty4/RedisClientBase.java +++ b/netty4-client/src/main/java/redis/netty4/RedisClientBase.java @@ -53,7 +53,7 @@ public Promise send(Command command) { Promise reply = new Promise<>(); synchronized (this) { queue.add(reply); - socketChannel.write(command); + socketChannel.writeAndFlush(command); } return reply; } diff --git a/netty4/pom.xml b/netty4/pom.xml index c6e89fc..09364e5 100644 --- a/netty4/pom.xml +++ b/netty4/pom.xml @@ -14,12 +14,12 @@ io.netty netty-all - 4.0.10.Final + 4.0.19.Final org.javassist javassist - 3.18.0-GA + 3.18.1-GA com.github.spullara.redis diff --git a/netty4/src/main/java/redis/netty4/RedisReplyDecoder.java b/netty4/src/main/java/redis/netty4/RedisReplyDecoder.java index f9e0ed4..299c509 100644 --- a/netty4/src/main/java/redis/netty4/RedisReplyDecoder.java +++ b/netty4/src/main/java/redis/netty4/RedisReplyDecoder.java @@ -46,7 +46,7 @@ public ByteBuf readBytes(ByteBuf is) throws IOException { if (size == -1) { return null; } - ByteBuf buffer = is.readSlice(size); + ByteBuf buffer = is.readSlice(size).retain(); int cr = is.readByte(); int lf = is.readByte(); if (cr != CR || lf != LF) { From f1f9d53fbf6a342f7ee96e061062381b689a2973 Mon Sep 17 00:00:00 2001 From: Vladimir Korenev Date: Tue, 27 May 2014 23:24:40 +0300 Subject: [PATCH 2/4] Fix NPE in BulkReply. --- netty4/src/main/java/redis/netty4/BulkReply.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netty4/src/main/java/redis/netty4/BulkReply.java b/netty4/src/main/java/redis/netty4/BulkReply.java index a106644..103be5b 100644 --- a/netty4/src/main/java/redis/netty4/BulkReply.java +++ b/netty4/src/main/java/redis/netty4/BulkReply.java @@ -28,7 +28,7 @@ public BulkReply(byte[] bytes) { public BulkReply(ByteBuf bytes) { this.bytes = bytes; - capacity = bytes.capacity(); + capacity = bytes == null ? -1 : bytes.readableBytes(); } @Override From 0956091774ed5095642e9be9a798c7b69372c66a Mon Sep 17 00:00:00 2001 From: Vladimir Korenev Date: Wed, 28 May 2014 13:42:52 +0300 Subject: [PATCH 3/4] Fix setting checkpoint in RedisReplyDecoder. --- .../java/redis/netty4/RedisReplyDecoder.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/netty4/src/main/java/redis/netty4/RedisReplyDecoder.java b/netty4/src/main/java/redis/netty4/RedisReplyDecoder.java index 299c509..dd2c78e 100644 --- a/netty4/src/main/java/redis/netty4/RedisReplyDecoder.java +++ b/netty4/src/main/java/redis/netty4/RedisReplyDecoder.java @@ -128,16 +128,18 @@ public void checkpoint() { } public MultiBulkReply decodeMultiBulkReply(ByteBuf is) throws IOException { - try { - if (reply == null) { - reply = new MultiBulkReply(); + final MultiBulkReply multiBulkReply; + if (reply != null) { + multiBulkReply = reply; + } else { + multiBulkReply = new MultiBulkReply(); + if (checkpointEnabled) { + reply = multiBulkReply; checkpoint(); } - reply.read(this, is); - return reply; - } finally { - reply = null; } + multiBulkReply.read(this, is); + reply = null; + return multiBulkReply; } - } From acb2831fea2590ae75541e25aacbb2397464ff30 Mon Sep 17 00:00:00 2001 From: Vladimir Korenev Date: Tue, 10 Jun 2014 23:42:59 +0300 Subject: [PATCH 4/4] Fix commands and replies mismatch. --- .../java/redis/netty4/RedisClientBase.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/netty4-client/src/main/java/redis/netty4/RedisClientBase.java b/netty4-client/src/main/java/redis/netty4/RedisClientBase.java index e3160c8..3c7f47a 100644 --- a/netty4-client/src/main/java/redis/netty4/RedisClientBase.java +++ b/netty4-client/src/main/java/redis/netty4/RedisClientBase.java @@ -34,12 +34,9 @@ public static Promise connect(String host, int port) { new SimpleChannelInboundHandler>() { @Override protected void channelRead0(ChannelHandlerContext channelHandlerContext, Reply reply) throws Exception { - Promise poll; - synchronized (client) { - poll = queue.poll(); - if (poll == null) { - throw new IllegalStateException("Promise queue is empty, received reply"); - } + Promise poll = queue.poll(); + if (poll == null) { + throw new IllegalStateException("Promise queue is empty, received reply"); } poll.set(reply); } @@ -49,12 +46,15 @@ protected void channelRead0(ChannelHandlerContext channelHandlerContext, Reply send(Command command) { - Promise reply = new Promise<>(); - synchronized (this) { - queue.add(reply); - socketChannel.writeAndFlush(command); - } + public Promise send(final Command command) { + final Promise reply = new Promise<>(); + socketChannel.eventLoop().execute(new Runnable() { + @Override + public void run() { + queue.add(reply); + socketChannel.writeAndFlush(command); + } + }); return reply; } }