Skip to content

Commit

Permalink
Rlease ping/pong command buffer (apache#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
saandrews authored Mar 10, 2017
1 parent 83605f6 commit 75d2273
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.RecyclableDuplicateByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.buffer.UnpooledHeapByteBuf;
import io.netty.util.Recycler;
Expand Down Expand Up @@ -531,18 +532,34 @@ public static ByteBuf newConsumerStatsResponse(CommandConsumerStatsResponse.Buil
return res;
}

private final static ByteBuf cmdPing = serializeWithSize(
BaseCommand.newBuilder().setType(Type.PING).setPing(CommandPing.getDefaultInstance()));
private final static ByteBuf cmdPing;

static {
ByteBuf serializedCmdPing = serializeWithSize(
BaseCommand.newBuilder()
.setType(Type.PING)
.setPing(CommandPing.getDefaultInstance()));
cmdPing = Unpooled.copiedBuffer(serializedCmdPing);
serializedCmdPing.release();
}

static ByteBuf newPing() {
return RecyclableDuplicateByteBuf.create(cmdPing).retain();
return RecyclableDuplicateByteBuf.create(cmdPing);
}

private final static ByteBuf cmdPong = serializeWithSize(
BaseCommand.newBuilder().setType(Type.PONG).setPong(CommandPong.getDefaultInstance()));
private final static ByteBuf cmdPong;

static {
ByteBuf serializedCmdPong = serializeWithSize(
BaseCommand.newBuilder()
.setType(Type.PONG)
.setPong(CommandPong.getDefaultInstance()));
cmdPong = Unpooled.copiedBuffer(serializedCmdPong);
serializedCmdPong.release();
}

static ByteBuf newPong() {
return RecyclableDuplicateByteBuf.create(cmdPong).retain();
return RecyclableDuplicateByteBuf.create(cmdPong);
}

private static ByteBuf serializeWithSize(BaseCommand.Builder cmdBuilder) {
Expand Down

0 comments on commit 75d2273

Please sign in to comment.