Skip to content

Commit 0161e00

Browse files
committed
Update to latest SNAPSHOT
1 parent 24a6c1c commit 0161e00

File tree

4 files changed

+18
-248
lines changed

4 files changed

+18
-248
lines changed

resp-decoder/src/main/java/org/infinispan/server/resp/NettyChannelState.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ public class NettyChannelState {
1313
public EmbeddedChannel channel;
1414

1515
public enum DECODER {
16-
CURRENT,
17-
NEW
16+
CURRENT
1817
}
1918

2019
@Param
@@ -27,14 +26,13 @@ public void initializeState() {
2726
channel.config().setAllocator(PooledByteBufAllocator.DEFAULT);
2827

2928
switch (decoder) {
30-
case NEW:
31-
channel.pipeline()
32-
.addLast(new NewDecoder(new NewRespHandler()));
33-
break;
3429
case CURRENT:
3530
channel.pipeline()
3631
.addLast(new RespDecoder(new OurRespHandler()));
3732
break;
3833
}
34+
35+
// Ensure the ByteBufPool is initialized
36+
channel.pipeline().fireChannelRegistered();
3937
}
4038
}

resp-decoder/src/main/java/org/infinispan/server/resp/NewDecoder.java

Lines changed: 0 additions & 147 deletions
This file was deleted.

resp-decoder/src/main/java/org/infinispan/server/resp/NewRespHandler.java

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,43 @@
11
package org.infinispan.server.resp;
22

3+
import java.nio.charset.StandardCharsets;
34
import java.util.List;
45
import java.util.concurrent.CompletableFuture;
56
import java.util.concurrent.CompletionStage;
7+
import java.util.function.BiConsumer;
8+
import java.util.function.Consumer;
9+
import java.util.function.IntFunction;
610

711
import org.infinispan.commons.util.concurrent.CompletableFutures;
812
import org.infinispan.util.function.TriConsumer;
913

1014
import io.netty.buffer.ByteBuf;
11-
import io.netty.buffer.Unpooled;
1215
import io.netty.channel.ChannelHandlerContext;
13-
import io.netty.util.CharsetUtil;
16+
import io.netty.util.AttributeKey;
1417

1518
public class OurRespHandler extends RespRequestHandler {
1619
private static final CompletableFuture<byte[]> GET_FUTURE = CompletableFuture.completedFuture(new byte[] { 0x1, 0x12});
17-
public static ByteBuf OK = Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("+OK\r\n", CharsetUtil.US_ASCII));
18-
19-
// Returns a cached OK status that is retained for multiple uses
20-
static ByteBuf statusOK() {
21-
return OK.duplicate();
22-
}
20+
public static byte[] OK = "+OK\r\n".getBytes(StandardCharsets.US_ASCII);
2321

2422
@Override
25-
public CompletionStage<RespRequestHandler> handleRequest(ChannelHandlerContext ctx, String type, List<byte[]> arguments) {
23+
public CompletionStage<RespRequestHandler> actualHandleRequest(ChannelHandlerContext ctx, String type, List<byte[]> arguments) {
2624
switch (type) {
2725
case "GET":
2826
return stageToReturn(GET_FUTURE, ctx, GET_TRICONSUMER);
2927
case "SET":
30-
return stageToReturn(CompletableFutures.completedNull(), ctx, SET_TRICONSUMER);
28+
return stageToReturn(CompletableFutures.completedNull(), ctx, OK_BICONSUMER);
3129
}
3230
return super.handleRequest(ctx, type, arguments);
3331
}
3432

35-
private static final TriConsumer<byte[], ChannelHandlerContext, Throwable> SET_TRICONSUMER = (ignore, innerCtx, t) -> {
36-
if (t != null) {
37-
throw new AssertionError(t);
38-
} else {
39-
innerCtx.writeAndFlush(statusOK(), innerCtx.voidPromise());
40-
}
41-
};
33+
protected static final BiConsumer<Object, ByteBufPool> OK_BICONSUMER = (ignore, alloc) ->
34+
alloc.acquire(OK.length).writeBytes(OK);
4235

43-
private static final TriConsumer<byte[], ChannelHandlerContext, Throwable> GET_TRICONSUMER = (innerValueBytes, innerCtx, t) -> {
44-
if (t != null) {
45-
throw new AssertionError(t);
46-
} else if (innerValueBytes != null) {
47-
ByteBuf buf = bytesToResult(innerValueBytes, innerCtx.alloc());
48-
innerCtx.writeAndFlush(buf, innerCtx.voidPromise());
36+
protected static final BiConsumer<byte[], ByteBufPool> GET_TRICONSUMER = (innerValueBytes, alloc) -> {
37+
if (innerValueBytes != null) {
38+
bytesToResult(innerValueBytes, alloc);
4939
} else {
50-
innerCtx.writeAndFlush(RespRequestHandler.stringToByteBuf("$-1\r\n", innerCtx.alloc()), innerCtx.voidPromise());
40+
stringToByteBuf("$-1\r\n", alloc);
5141
}
5242
};
5343
}

0 commit comments

Comments
 (0)