Class PersistentSubscription

java.lang.Object
org.apache.pulsar.broker.service.AbstractSubscription
org.apache.pulsar.broker.service.persistent.PersistentSubscription
All Implemented Interfaces:
Subscription
Direct Known Subclasses:
CompactorSubscription

public class PersistentSubscription extends AbstractSubscription implements Subscription
  • Field Details

    • topic

      protected final PersistentTopic topic
    • cursor

      protected final org.apache.bookkeeper.mledger.ManagedCursor cursor
    • dispatcher

      protected volatile Dispatcher dispatcher
    • topicName

      protected final String topicName
    • subName

      protected final String subName
    • fullName

      protected final String fullName
  • Constructor Details

    • PersistentSubscription

      public PersistentSubscription(PersistentTopic topic, String subscriptionName, org.apache.bookkeeper.mledger.ManagedCursor cursor, boolean replicated)
    • PersistentSubscription

      public PersistentSubscription(PersistentTopic topic, String subscriptionName, org.apache.bookkeeper.mledger.ManagedCursor cursor, boolean replicated, Map<String,String> subscriptionProperties)
  • Method Details

    • updateLastMarkDeleteAdvancedTimestamp

      public void updateLastMarkDeleteAdvancedTimestamp()
    • interceptor

      public BrokerInterceptor interceptor()
      Specified by:
      interceptor in interface Subscription
    • getName

      public String getName()
      Specified by:
      getName in interface Subscription
    • getTopic

      public Topic getTopic()
      Specified by:
      getTopic in interface Subscription
    • isReplicated

      public boolean isReplicated()
      Specified by:
      isReplicated in interface Subscription
    • setReplicated

      public boolean setReplicated(boolean replicated)
    • addConsumer

      public CompletableFuture<Void> addConsumer(Consumer consumer)
      Specified by:
      addConsumer in interface Subscription
    • removeConsumer

      public void removeConsumer(Consumer consumer, boolean isResetCursor) throws BrokerServiceException
      Specified by:
      removeConsumer in interface Subscription
      Throws:
      BrokerServiceException
    • deactivateCursor

      public void deactivateCursor()
    • consumerFlow

      public void consumerFlow(Consumer consumer, int additionalNumberOfMessages)
      Specified by:
      consumerFlow in interface Subscription
    • acknowledgeMessage

      public void acknowledgeMessage(List<org.apache.bookkeeper.mledger.Position> positions, org.apache.pulsar.common.api.proto.CommandAck.AckType ackType, Map<String,Long> properties)
      Specified by:
      acknowledgeMessage in interface Subscription
    • transactionIndividualAcknowledge

      public CompletableFuture<Void> transactionIndividualAcknowledge(org.apache.pulsar.client.api.transaction.TxnID txnId, List<org.apache.commons.lang3.tuple.MutablePair<org.apache.bookkeeper.mledger.impl.PositionImpl,Integer>> positions)
    • transactionCumulativeAcknowledge

      public CompletableFuture<Void> transactionCumulativeAcknowledge(org.apache.pulsar.client.api.transaction.TxnID txnId, List<org.apache.bookkeeper.mledger.impl.PositionImpl> positions)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getTopicName

      public String getTopicName()
      Specified by:
      getTopicName in interface Subscription
    • getType

      public org.apache.pulsar.common.api.proto.CommandSubscribe.SubType getType()
      Specified by:
      getType in interface Subscription
    • getTypeString

      public String getTypeString()
      Specified by:
      getTypeString in interface Subscription
    • analyzeBacklog

      public CompletableFuture<AnalyzeBacklogResult> analyzeBacklog(Optional<org.apache.bookkeeper.mledger.Position> position)
      Specified by:
      analyzeBacklog in interface Subscription
    • clearBacklog

      public CompletableFuture<Void> clearBacklog()
      Specified by:
      clearBacklog in interface Subscription
    • skipMessages

      public CompletableFuture<Void> skipMessages(int numMessagesToSkip)
      Specified by:
      skipMessages in interface Subscription
    • resetCursor

      public CompletableFuture<Void> resetCursor(long timestamp)
      Specified by:
      resetCursor in interface Subscription
    • resetCursor

      public CompletableFuture<Void> resetCursor(org.apache.bookkeeper.mledger.Position position)
      Specified by:
      resetCursor in interface Subscription
    • peekNthMessage

      public CompletableFuture<org.apache.bookkeeper.mledger.Entry> peekNthMessage(int messagePosition)
      Specified by:
      peekNthMessage in interface Subscription
    • getNumberOfEntriesInBacklog

      public long getNumberOfEntriesInBacklog(boolean getPreciseBacklog)
      Specified by:
      getNumberOfEntriesInBacklog in interface Subscription
    • getDispatcher

      public Dispatcher getDispatcher()
      Specified by:
      getDispatcher in interface Subscription
    • getNumberOfEntriesSinceFirstNotAckedMessage

      public long getNumberOfEntriesSinceFirstNotAckedMessage()
    • getTotalNonContiguousDeletedMessagesRange

      public int getTotalNonContiguousDeletedMessagesRange()
    • close

      public CompletableFuture<Void> close()
      Close the cursor ledger for this subscription. Requires that there are no active consumers on the dispatcher
      Specified by:
      close in interface Subscription
      Returns:
      CompletableFuture indicating the completion of delete operation
    • disconnect

      public CompletableFuture<Void> disconnect()
      Disconnect all consumers attached to the dispatcher and close this subscription.
      Specified by:
      disconnect in interface Subscription
      Returns:
      CompletableFuture indicating the completion of disconnect operation
    • delete

      public CompletableFuture<Void> delete()
      Delete the subscription by closing and deleting its managed cursor if no consumers are connected to it. Handle unsubscribe call from admin layer.
      Specified by:
      delete in interface Subscription
      Returns:
      CompletableFuture indicating the completion of delete operation
    • deleteForcefully

      public CompletableFuture<Void> deleteForcefully()
      Forcefully close all consumers and deletes the subscription.
      Specified by:
      deleteForcefully in interface Subscription
      Returns:
    • doUnsubscribe

      public CompletableFuture<Void> doUnsubscribe(Consumer consumer)
      Handle unsubscribe command from the client API Check with the dispatcher is this consumer can proceed with unsubscribe.
      Specified by:
      doUnsubscribe in interface Subscription
      Parameters:
      consumer - consumer object that is initiating the unsubscribe operation
      Returns:
      CompletableFuture indicating the completion of unsubscribe operation
    • getConsumers

      public List<Consumer> getConsumers()
      Specified by:
      getConsumers in interface Subscription
    • expireMessages

      public boolean expireMessages(int messageTTLInSeconds)
      Specified by:
      expireMessages in interface Subscription
    • expireMessages

      public boolean expireMessages(org.apache.bookkeeper.mledger.Position position)
      Specified by:
      expireMessages in interface Subscription
    • getExpiredMessageRate

      public double getExpiredMessageRate()
      Specified by:
      getExpiredMessageRate in interface Subscription
    • getExpiryMonitor

      public PersistentMessageExpiryMonitor getExpiryMonitor()
    • estimateBacklogSize

      public long estimateBacklogSize()
    • getStats

      public org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl getStats(Boolean getPreciseBacklog, boolean subscriptionBacklogSize, boolean getEarliestTimeInBacklog)
    • redeliverUnacknowledgedMessages

      public void redeliverUnacknowledgedMessages(Consumer consumer, long consumerEpoch)
      Specified by:
      redeliverUnacknowledgedMessages in interface Subscription
    • redeliverUnacknowledgedMessages

      public void redeliverUnacknowledgedMessages(Consumer consumer, List<org.apache.bookkeeper.mledger.impl.PositionImpl> positions)
      Specified by:
      redeliverUnacknowledgedMessages in interface Subscription
    • addUnAckedMessages

      public void addUnAckedMessages(int unAckMessages)
      Specified by:
      addUnAckedMessages in interface Subscription
    • getNumberOfEntriesDelayed

      public long getNumberOfEntriesDelayed()
      Specified by:
      getNumberOfEntriesDelayed in interface Subscription
    • markTopicWithBatchMessagePublished

      public void markTopicWithBatchMessagePublished()
      Specified by:
      markTopicWithBatchMessagePublished in interface Subscription
    • getSubscriptionProperties

      public Map<String,String> getSubscriptionProperties()
      Specified by:
      getSubscriptionProperties in interface Subscription
    • getPositionInPendingAck

      public org.apache.bookkeeper.mledger.impl.PositionImpl getPositionInPendingAck(org.apache.bookkeeper.mledger.impl.PositionImpl position)
    • updateSubscriptionProperties

      public CompletableFuture<Void> updateSubscriptionProperties(Map<String,String> subscriptionProperties)
      Specified by:
      updateSubscriptionProperties in interface Subscription
    • mergeCursorProperties

      protected Map<String,Long> mergeCursorProperties(Map<String,Long> userProperties)
      Return a merged map that contains the cursor properties specified by used (eg. when using compaction subscription) and the subscription properties.
    • processReplicatedSubscriptionSnapshot

      public void processReplicatedSubscriptionSnapshot(org.apache.pulsar.common.api.proto.ReplicatedSubscriptionsSnapshot snapshot)
      Specified by:
      processReplicatedSubscriptionSnapshot in interface Subscription
    • endTxn

      public CompletableFuture<Void> endTxn(long txnidMostBits, long txnidLeastBits, int txnAction, long lowWaterMark)
      Specified by:
      endTxn in interface Subscription
    • getCursor

      public org.apache.bookkeeper.mledger.ManagedCursor getCursor()
    • getPendingAckHandle

      public PendingAckHandle getPendingAckHandle()
    • syncBatchPositionBitSetForPendingAck

      public void syncBatchPositionBitSetForPendingAck(org.apache.bookkeeper.mledger.impl.PositionImpl position)
    • checkIsCanDeleteConsumerPendingAck

      public boolean checkIsCanDeleteConsumerPendingAck(org.apache.bookkeeper.mledger.impl.PositionImpl position)
    • getTransactionPendingAckStats

      public org.apache.pulsar.common.policies.data.TransactionPendingAckStats getTransactionPendingAckStats(boolean lowWaterMarks)
    • checkAndUnblockIfStuck

      public boolean checkAndUnblockIfStuck()
    • getTransactionInPendingAckStats

      public org.apache.pulsar.common.policies.data.TransactionInPendingAckStats getTransactionInPendingAckStats(org.apache.pulsar.client.api.transaction.TxnID txnID)
    • getPendingAckManageLedger

      public CompletableFuture<org.apache.bookkeeper.mledger.ManagedLedger> getPendingAckManageLedger()
    • checkIfPendingAckStoreInit

      public boolean checkIfPendingAckStoreInit()
    • checkPositionInPendingAckState

      public org.apache.pulsar.common.stats.PositionInPendingAckStats checkPositionInPendingAckState(org.apache.bookkeeper.mledger.impl.PositionImpl position, Integer batchIndex)