Class ProducerImpl<T>

java.lang.Object
org.apache.pulsar.client.impl.ProducerBase<T>
org.apache.pulsar.client.impl.ProducerImpl<T>
All Implemented Interfaces:
io.netty.util.TimerTask, Closeable, AutoCloseable, Producer<T>

public class ProducerImpl<T> extends ProducerBase<T> implements io.netty.util.TimerTask
  • Field Details

    • producerId

      protected final long producerId
    • lastSequenceIdPushed

      protected volatile long lastSequenceIdPushed
    • client

      protected final PulsarClientImpl client
    • topic

      protected final String topic
    • redirectedClusterURI

      protected volatile URI redirectedClusterURI
  • Constructor Details

  • Method Details

    • semaphoreRelease

      protected void semaphoreRelease(int releaseCountRequest)
    • createPendingMessagesQueue

      protected ProducerImpl.OpSendMsgQueue createPendingMessagesQueue()
    • getConnectionHandler

      public ConnectionHandler getConnectionHandler()
    • getLastSequenceId

      public long getLastSequenceId()
      Specified by:
      getLastSequenceId in interface Producer<T>
    • sendAsync

      public void sendAsync(Message<?> message, SendCallback callback)
    • getNumOfPartitions

      public int getNumOfPartitions()
      Specified by:
      getNumOfPartitions in interface Producer<T>
    • encryptMessage

      protected io.netty.buffer.ByteBuf encryptMessage(MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) throws PulsarClientException
      Throws:
      PulsarClientException
    • sendMessage

      protected ByteBufPair sendMessage(long producerId, long sequenceId, int numMessages, MessageId messageId, MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload)
    • sendMessage

      protected ByteBufPair sendMessage(long producerId, long lowestSequenceId, long highestSequenceId, int numMessages, MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload)
    • getChecksumType

      protected Commands.ChecksumType getChecksumType()
    • closeAsync

      public CompletableFuture<Void> closeAsync()
      Specified by:
      closeAsync in interface Producer<T>
      Specified by:
      closeAsync in class ProducerBase<T>
    • isConnected

      public boolean isConnected()
      Specified by:
      isConnected in interface Producer<T>
    • getCnxIfReady

      protected ClientCnx getCnxIfReady()
      Hook method for testing. By returning null, it's possible to prevent messages being delivered to the broker.
      Returns:
      cnx if OpSend messages should be written to open connection. Caller must verify that the returned cnx is not null before using reference.
    • getLastDisconnectedTimestamp

      public long getLastDisconnectedTimestamp()
      Specified by:
      getLastDisconnectedTimestamp in interface Producer<T>
    • isWritable

      public boolean isWritable()
    • terminated

      public void terminated(ClientCnx cnx)
    • recoverChecksumError

      protected void recoverChecksumError(ClientCnx cnx, long sequenceId)
      Checks message checksum to retry if message was corrupted while sending to broker. Recomputes checksum of the message header-payload again.
      • if matches with existing checksum: it means message was corrupt while sending to broker. So, resend message
      • if doesn't match with existing checksum: it means message is already corrupt and can't retry again. So, fail send-message by failing callback
      Parameters:
      cnx -
      sequenceId -
    • recoverNotAllowedError

      protected void recoverNotAllowedError(long sequenceId, String errorMsg)
    • verifyLocalBufferIsNotCorrupted

      protected boolean verifyLocalBufferIsNotCorrupted(ProducerImpl.OpSendMsg op)
      Computes checksum again and verifies it against existing checksum. If checksum doesn't match it means that message is corrupt.
      Parameters:
      op -
      Returns:
      returns true only if message is not modified and computed-checksum is same as previous checksum else return false that means that message is corrupted. Returns true if checksum is not present.
    • connectionOpened

      public CompletableFuture<Void> connectionOpened(ClientCnx cnx)
    • connectionFailed

      public void connectionFailed(PulsarClientException exception)
    • brokerChecksumSupportedVersion

      public int brokerChecksumSupportedVersion()
    • run

      public void run(io.netty.util.Timeout timeout) throws Exception
      Process sendTimeout events.
      Specified by:
      run in interface io.netty.util.TimerTask
      Throws:
      Exception
    • flushAsync

      public CompletableFuture<Void> flushAsync()
      Specified by:
      flushAsync in interface Producer<T>
    • triggerFlush

      protected void triggerFlush()
    • processOpSendMsg

      protected void processOpSendMsg(ProducerImpl.OpSendMsg op)
    • getDelayInMillis

      public long getDelayInMillis()
    • getConnectionId

      public String getConnectionId()
    • getConnectedSince

      public String getConnectedSince()
    • getPendingQueueSize

      public int getPendingQueueSize()
    • getStats

      public ProducerStatsRecorder getStats()
      Specified by:
      getStats in interface Producer<T>
    • getProducerName

      public String getProducerName()
      Specified by:
      getProducerName in interface Producer<T>
    • getClientCnx

      public ClientCnx getClientCnx()
    • setRedirectedClusterURI

      protected void setRedirectedClusterURI(String serviceUrl, String serviceUrlTls) throws URISyntaxException
      Throws:
      URISyntaxException
    • changeToReadyState

      protected boolean changeToReadyState()
    • changeToRegisteringSchemaState

      protected boolean changeToRegisteringSchemaState()
    • getState

      protected org.apache.pulsar.client.impl.HandlerState.State getState()
    • changeToConnecting

      protected boolean changeToConnecting()
    • setState

      protected void setState(org.apache.pulsar.client.impl.HandlerState.State s)
    • getAndUpdateState

      protected org.apache.pulsar.client.impl.HandlerState.State getAndUpdateState(UnaryOperator<org.apache.pulsar.client.impl.HandlerState.State> updater)
    • getClient

      public PulsarClientImpl getClient()