diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java index bb114e7f0e36b..084a273bf96d9 100644 --- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java +++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java @@ -1364,8 +1364,29 @@ protected static final class OpSendMsg { int totalChunks = 0; int chunkId = -1; + void initialize() { + msg = null; + msgs = null; + cmd = null; + callback = null; + rePopulate = null; + sequenceId = -1L; + createdAt = -1L; + firstSentAt = -1L; + lastSentAt = -1L; + highestSequenceId = -1L; + totalChunks = 0; + chunkId = -1; + uncompressedSize = 0; + retryCount = 0; + batchSizeByte = 0; + numMessagesInBatch = 1; + chunkedMessageCtx = null; + } + static OpSendMsg create(MessageImpl msg, ByteBufPair cmd, long sequenceId, SendCallback callback) { OpSendMsg op = RECYCLER.get(); + op.initialize(); op.msg = msg; op.cmd = cmd; op.callback = callback; @@ -1377,6 +1398,7 @@ static OpSendMsg create(MessageImpl msg, ByteBufPair cmd, long sequenceId, Se static OpSendMsg create(List> msgs, ByteBufPair cmd, long sequenceId, SendCallback callback) { OpSendMsg op = RECYCLER.get(); + op.initialize(); op.msgs = msgs; op.cmd = cmd; op.callback = callback; @@ -1392,6 +1414,7 @@ static OpSendMsg create(List> msgs, ByteBufPair cmd, long sequenc static OpSendMsg create(List> msgs, ByteBufPair cmd, long lowestSequenceId, long highestSequenceId, SendCallback callback) { OpSendMsg op = RECYCLER.get(); + op.initialize(); op.msgs = msgs; op.cmd = cmd; op.callback = callback; @@ -1444,24 +1467,8 @@ void sendComplete(final Exception e) { } void recycle() { - msg = null; - msgs = null; - cmd = null; - callback = null; - rePopulate = null; - sequenceId = -1L; - createdAt = -1L; - firstSentAt = -1L; - lastSentAt = -1L; - highestSequenceId = -1L; - totalChunks = 0; - chunkId = -1; - uncompressedSize = 0; - retryCount = 0; - batchSizeByte = 0; - numMessagesInBatch = 1; ReferenceCountUtil.safeRelease(chunkedMessageCtx); - chunkedMessageCtx = null; + initialize(); recyclerHandle.recycle(this); }