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

public class RawBatchMessageContainerImpl extends AbstractBatchMessageContainer
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 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

      protected List<MessageImpl<?>> messages
    • previousCallback

      protected SendCallback previousCallback
    • firstCallback

      protected SendCallback firstCallback
    • allocator

      protected final io.netty.buffer.ByteBufAllocator allocator
  • Constructor Details

    • RawBatchMessageContainerImpl

      public RawBatchMessageContainerImpl()
  • Method Details

    • createOpSendMsg

      public ProducerImpl.OpSendMsg createOpSendMsg()
      Specified by:
      createOpSendMsg in interface BatchMessageContainerBase
    • 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

      public boolean add(MessageImpl<?> msg, SendCallback callback)
      Specified by:
      add in interface BatchMessageContainerBase
    • isBatchFull

      protected boolean isBatchFull()
      Overrides:
      isBatchFull in class AbstractBatchMessageContainer
    • haveEnoughSpace

      public boolean haveEnoughSpace(MessageImpl<?> msg)
      Specified by:
      haveEnoughSpace in interface BatchMessageContainerBase
      Overrides:
      haveEnoughSpace in class AbstractBatchMessageContainer
    • 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:
      clear in interface org.apache.pulsar.client.api.BatchMessageContainer
    • getCompressedBatchMetadataAndPayload

      protected io.netty.buffer.ByteBuf getCompressedBatchMetadataAndPayload()
    • isEmpty

      public boolean isEmpty()
    • discard

      public void discard(Exception arg0)
    • isMultiBatches

      public boolean isMultiBatches()
    • updateAndReserveBatchAllocatedSize

      protected void updateAndReserveBatchAllocatedSize(int arg0)
    • hasSameSchema

      public boolean hasSameSchema(MessageImpl<?> arg0)
    • getLowestSequenceId

      public long getLowestSequenceId()
    • setLowestSequenceId

      public void setLowestSequenceId(long arg0)
    • getHighestSequenceId

      public long getHighestSequenceId()
    • setHighestSequenceId

      public void setHighestSequenceId(long arg0)