Package org.apache.pulsar.client.impl
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,java.io.Closeable,java.lang.AutoCloseable,org.apache.pulsar.client.api.Producer<T>
public class ProducerImpl<T> extends ProducerBase<T> implements io.netty.util.TimerTask
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classProducerImpl.OpSendMsgprotected static classProducerImpl.OpSendMsgQueueQueue implementation that is used as the pending messages queue.-
Nested classes/interfaces inherited from class org.apache.pulsar.client.impl.ProducerBase
ProducerBase.MultiSchemaMode
-
-
Field Summary
Fields Modifier and Type Field Description protected PulsarClientImplclientprotected longlastSequenceIdPushedprotected longproducerIdprotected java.lang.Stringtopic-
Fields inherited from class org.apache.pulsar.client.impl.ProducerBase
conf, interceptors, multiSchemaMode, producerCreatedFuture, schema, schemaCache
-
-
Constructor Summary
Constructors Constructor Description ProducerImpl(PulsarClientImpl client, java.lang.String topic, ProducerConfigurationData conf, java.util.concurrent.CompletableFuture<org.apache.pulsar.client.api.Producer<T>> producerCreatedFuture, int partitionIndex, org.apache.pulsar.client.api.Schema<T> schema, ProducerInterceptors interceptors, java.util.Optional<java.lang.String> overrideProducerName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intbrokerChecksumSupportedVersion()protected booleanchangeToConnecting()protected booleanchangeToReadyState()protected booleanchangeToRegisteringSchemaState()java.util.concurrent.CompletableFuture<java.lang.Void>closeAsync()voidconnectionFailed(org.apache.pulsar.client.api.PulsarClientException exception)voidconnectionOpened(ClientCnx cnx)protected ProducerImpl.OpSendMsgQueuecreatePendingMessagesQueue()protected io.netty.buffer.ByteBufencryptMessage(org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload)java.util.concurrent.CompletableFuture<java.lang.Void>flushAsync()protected org.apache.pulsar.client.impl.HandlerState.StategetAndUpdateState(java.util.function.UnaryOperator<org.apache.pulsar.client.impl.HandlerState.State> updater)protected org.apache.pulsar.common.protocol.Commands.ChecksumTypegetChecksumType()PulsarClientImplgetClient()ClientCnxgetClientCnx()protected ClientCnxgetCnxIfReady()Hook method for testing.java.lang.StringgetConnectedSince()ConnectionHandlergetConnectionHandler()java.lang.StringgetConnectionId()longgetDelayInMillis()longgetLastDisconnectedTimestamp()longgetLastSequenceId()intgetNumOfPartitions()intgetPendingQueueSize()java.lang.StringgetProducerName()protected org.apache.pulsar.client.impl.HandlerState.StategetState()ProducerStatsRecordergetStats()booleanisConnected()booleanisWritable()protected voidprocessOpSendMsg(ProducerImpl.OpSendMsg op)protected voidrecoverChecksumError(ClientCnx cnx, long sequenceId)Checks message checksum to retry if message was corrupted while sending to broker.protected voidrecoverNotAllowedError(long sequenceId, java.lang.String errorMsg)voidrun(io.netty.util.Timeout timeout)Process sendTimeout events.protected voidsemaphoreRelease(int releaseCountRequest)voidsendAsync(org.apache.pulsar.client.api.Message<?> message, SendCallback callback)protected org.apache.pulsar.common.protocol.ByteBufPairsendMessage(long producerId, long sequenceId, int numMessages, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload)protected org.apache.pulsar.common.protocol.ByteBufPairsendMessage(long producerId, long lowestSequenceId, long highestSequenceId, int numMessages, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload)protected voidsetState(org.apache.pulsar.client.impl.HandlerState.State s)voidterminated(ClientCnx cnx)protected voidtriggerFlush()protected booleanverifyLocalBufferIsNotCorrupted(ProducerImpl.OpSendMsg op)Computes checksum again and verifies it against existing checksum.-
Methods inherited from class org.apache.pulsar.client.impl.ProducerBase
beforeSend, close, flush, getConfiguration, getTopic, newMessage, newMessage, newMessage, onPartitionsChange, onSendAcknowledgement, producerCreatedFuture, send, send, sendAsync, sendAsync, toString
-
-
-
-
Field Detail
-
producerId
protected final long producerId
-
lastSequenceIdPushed
protected volatile long lastSequenceIdPushed
-
client
protected final PulsarClientImpl client
-
topic
protected final java.lang.String topic
-
-
Constructor Detail
-
ProducerImpl
public ProducerImpl(PulsarClientImpl client, java.lang.String topic, ProducerConfigurationData conf, java.util.concurrent.CompletableFuture<org.apache.pulsar.client.api.Producer<T>> producerCreatedFuture, int partitionIndex, org.apache.pulsar.client.api.Schema<T> schema, ProducerInterceptors interceptors, java.util.Optional<java.lang.String> overrideProducerName)
-
-
Method Detail
-
semaphoreRelease
protected void semaphoreRelease(int releaseCountRequest)
-
createPendingMessagesQueue
protected ProducerImpl.OpSendMsgQueue createPendingMessagesQueue()
-
getConnectionHandler
public ConnectionHandler getConnectionHandler()
-
getLastSequenceId
public long getLastSequenceId()
- Specified by:
getLastSequenceIdin interfaceorg.apache.pulsar.client.api.Producer<T>
-
sendAsync
public void sendAsync(org.apache.pulsar.client.api.Message<?> message, SendCallback callback)
-
getNumOfPartitions
public int getNumOfPartitions()
- Specified by:
getNumOfPartitionsin interfaceorg.apache.pulsar.client.api.Producer<T>
-
encryptMessage
protected io.netty.buffer.ByteBuf encryptMessage(org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) throws org.apache.pulsar.client.api.PulsarClientException- Throws:
org.apache.pulsar.client.api.PulsarClientException
-
sendMessage
protected org.apache.pulsar.common.protocol.ByteBufPair sendMessage(long producerId, long sequenceId, int numMessages, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload)
-
sendMessage
protected org.apache.pulsar.common.protocol.ByteBufPair sendMessage(long producerId, long lowestSequenceId, long highestSequenceId, int numMessages, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload)
-
getChecksumType
protected org.apache.pulsar.common.protocol.Commands.ChecksumType getChecksumType()
-
closeAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> closeAsync()
- Specified by:
closeAsyncin interfaceorg.apache.pulsar.client.api.Producer<T>- Specified by:
closeAsyncin classProducerBase<T>
-
isConnected
public boolean isConnected()
- Specified by:
isConnectedin interfaceorg.apache.pulsar.client.api.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:
getLastDisconnectedTimestampin interfaceorg.apache.pulsar.client.api.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, java.lang.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 void connectionOpened(ClientCnx cnx)
-
connectionFailed
public void connectionFailed(org.apache.pulsar.client.api.PulsarClientException exception)
-
brokerChecksumSupportedVersion
public int brokerChecksumSupportedVersion()
-
run
public void run(io.netty.util.Timeout timeout) throws java.lang.ExceptionProcess sendTimeout events.- Specified by:
runin interfaceio.netty.util.TimerTask- Throws:
java.lang.Exception
-
flushAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> flushAsync()
- Specified by:
flushAsyncin interfaceorg.apache.pulsar.client.api.Producer<T>
-
triggerFlush
protected void triggerFlush()
-
processOpSendMsg
protected void processOpSendMsg(ProducerImpl.OpSendMsg op)
-
getDelayInMillis
public long getDelayInMillis()
-
getConnectionId
public java.lang.String getConnectionId()
-
getConnectedSince
public java.lang.String getConnectedSince()
-
getPendingQueueSize
public int getPendingQueueSize()
-
getStats
public ProducerStatsRecorder getStats()
- Specified by:
getStatsin interfaceorg.apache.pulsar.client.api.Producer<T>
-
getProducerName
public java.lang.String getProducerName()
- Specified by:
getProducerNamein interfaceorg.apache.pulsar.client.api.Producer<T>
-
getClientCnx
public ClientCnx getClientCnx()
-
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(java.util.function.UnaryOperator<org.apache.pulsar.client.impl.HandlerState.State> updater)
-
getClient
public PulsarClientImpl getClient()
-
-