Package org.apache.pulsar.client.impl
Class RawBatchMessageContainerImpl
java.lang.Object
org.apache.pulsar.client.impl.AbstractBatchMessageContainer
org.apache.pulsar.client.impl.RawBatchMessageContainerImpl
- All Implemented Interfaces:
org.apache.pulsar.client.api.BatchMessageContainer,BatchMessageContainerBase
A raw batch message container without producer. (Used for StrategicTwoPhaseCompactor)
incoming single messages:
(k1, v1), (k2, v1), (k3, v1), (k1, v2), (k2, v2), (k3, v2), (k1, v3), (k2, v3), (k3, v3)
batched into single batch message:
[(k1, v1), (k2, v1), (k3, v1), (k1, v2), (k2, v2), (k3, v2), (k1, v3), (k2, v3), (k3, v3)]
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.netty.buffer.ByteBufAllocatorprotected io.netty.buffer.ByteBufprotected SendCallbackprotected longprotected longprotected org.apache.pulsar.common.api.proto.MessageMetadataprotected List<MessageImpl<?>>protected SendCallbackFields inherited from class org.apache.pulsar.client.impl.AbstractBatchMessageContainer
batchAllocatedSizeBytes, compressionType, compressor, currentBatchSizeBytes, currentTxnidLeastBits, currentTxnidMostBits, INITIAL_BATCH_BUFFER_SIZE, INITIAL_MESSAGES_NUM, maxBatchSize, maxBytesInBatch, maxMessagesNum, maxNumMessagesInBatch, numMessagesInBatch, producer, topicName -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(MessageImpl<?> msg, SendCallback callback) voidclear()voidprotected io.netty.buffer.ByteBuflonglongbooleanhasSameSchema(MessageImpl<?> arg0) booleanhaveEnoughSpace(MessageImpl<?> msg) protected booleanbooleanisEmpty()booleanvoidsetCryptoKeyReader(org.apache.pulsar.client.api.CryptoKeyReader cryptoKeyReader) Sets a CryptoKeyReader instance to encrypt batched messages during serialization, `toByteBuf()`.voidsetHighestSequenceId(long arg0) voidsetLowestSequenceId(long arg0) io.netty.buffer.ByteBufSerializes the batched messages and return the ByteBuf.protected voidupdateAndReserveBatchAllocatedSize(int arg0) Methods inherited from class org.apache.pulsar.client.impl.AbstractBatchMessageContainer
clearTimestamp, createOpSendMsgs, getBatchAllocatedSizeBytes, getCurrentBatchSize, getFirstAddedTimestamp, getMaxMessageSize, getMaxMessagesNum, getNumMessagesInBatch, hasSameTxn, setProducer, tryUpdateTimestamp
-
Field Details
-
messageMetadata
protected org.apache.pulsar.common.api.proto.MessageMetadata messageMetadata -
lowestSequenceId
protected long lowestSequenceId -
highestSequenceId
protected long highestSequenceId -
batchedMessageMetadataAndPayload
protected io.netty.buffer.ByteBuf batchedMessageMetadataAndPayload -
messages
-
previousCallback
-
firstCallback
-
allocator
protected final io.netty.buffer.ByteBufAllocator allocator
-
-
Constructor Details
-
RawBatchMessageContainerImpl
public RawBatchMessageContainerImpl()
-
-
Method Details
-
createOpSendMsg
- Specified by:
createOpSendMsgin interfaceBatchMessageContainerBase
-
setCryptoKeyReader
public void setCryptoKeyReader(org.apache.pulsar.client.api.CryptoKeyReader cryptoKeyReader) Sets a CryptoKeyReader instance to encrypt batched messages during serialization, `toByteBuf()`.- Parameters:
cryptoKeyReader- a CryptoKeyReader instance
-
add
- Specified by:
addin interfaceBatchMessageContainerBase
-
isBatchFull
protected boolean isBatchFull()- Overrides:
isBatchFullin classAbstractBatchMessageContainer
-
haveEnoughSpace
- Specified by:
haveEnoughSpacein interfaceBatchMessageContainerBase- Overrides:
haveEnoughSpacein classAbstractBatchMessageContainer
-
toByteBuf
public io.netty.buffer.ByteBuf toByteBuf()Serializes the batched messages and return the ByteBuf. It sets the CompressionType and Encryption Keys from the batched messages. If successful, it calls `clear()` at the end to release buffers from this container. The returned byte buffer follows this format: [IdSize][Id][metadataAndPayloadSize][metadataAndPayload]. This format is the same as RawMessage.serialize()'s format as the compacted messages is deserialized as RawMessage in broker. It throws the following runtime exceptions from encryption: IllegalStateException if cryptoKeyReader is not set for encrypted messages. IllegalArgumentException if encryption key init fails. RuntimeException if message encryption fails.- Returns:
- a ByteBuf instance
-
clear
public void clear()- Specified by:
clearin interfaceorg.apache.pulsar.client.api.BatchMessageContainer
-
getCompressedBatchMetadataAndPayload
protected io.netty.buffer.ByteBuf getCompressedBatchMetadataAndPayload() -
isEmpty
public boolean isEmpty() -
discard
-
isMultiBatches
public boolean isMultiBatches() -
updateAndReserveBatchAllocatedSize
protected void updateAndReserveBatchAllocatedSize(int arg0) -
hasSameSchema
-
getLowestSequenceId
public long getLowestSequenceId() -
setLowestSequenceId
public void setLowestSequenceId(long arg0) -
getHighestSequenceId
public long getHighestSequenceId() -
setHighestSequenceId
public void setHighestSequenceId(long arg0)
-