提交 75d2273e 编写于 作者: A Andrews 提交者: GitHub

Rlease ping/pong command buffer (#283)

上级 83605f6e
......@@ -66,6 +66,7 @@ import com.yahoo.pulsar.common.util.protobuf.ByteBufCodedOutputStream;
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;
......@@ -531,18 +532,34 @@ public class Commands {
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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册