Package org.apache.pulsar.broker.service
Class AbstractTopic
- java.lang.Object
-
- org.apache.pulsar.broker.service.AbstractTopic
-
- All Implemented Interfaces:
Topic
- Direct Known Subclasses:
NonPersistentTopic,PersistentTopic
public abstract class AbstractTopic extends java.lang.Object implements Topic
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pulsar.broker.service.Topic
Topic.PublishContext
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.bookkeeper.mledger.util.StatsBucketsaddEntryLatencyStatsUsecprotected BrokerServicebrokerServiceprotected java.util.concurrent.atomic.LongAdderbytesOutFromRemovedSubscriptionsprotected booleanhasBatchMessagePublishedprotected org.apache.pulsar.common.policies.data.InactiveTopicPoliciesinactiveTopicPoliciesprotected java.lang.BooleanisAllowAutoUpdateSchemaprotected booleanisEncryptionRequiredprotected booleanisFencedprotected longlastActiveprotected java.util.concurrent.locks.ReentrantReadWriteLocklockprotected java.lang.IntegermaxSubscriptionsPerTopicprotected intmaxUnackedMessagesOnConsumerAppiliedprotected java.util.concurrent.atomic.LongAddermsgOutFromRemovedSubscriptionsprotected static longPOLICY_UPDATE_FAILURE_RETRY_TIME_SECONDSprotected booleanpreciseTopicPublishRateLimitingEnableprotected java.util.concurrent.ConcurrentHashMap<java.lang.String,Producer>producersprotected longpublishRateLimitedTimesprotected java.lang.StringreplicatorPrefixprotected ResourceGroupPublishLimiterresourceGroupPublishLimiterprotected booleanresourceGroupRateLimitingEnabledprotected org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategyschemaCompatibilityStrategyprotected booleanschemaValidationEnforcedprotected java.lang.Stringtopicprotected java.util.Optional<java.lang.Long>topicEpochprotected PublishRateLimitertopicPublishRateLimiter
-
Constructor Summary
Constructors Constructor Description AbstractTopic(java.lang.String topic, BrokerService brokerService)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.util.concurrent.CompletableFuture<java.lang.Void>addConsumerToSubscription(Subscription subscription, Consumer consumer)java.util.concurrent.CompletableFuture<java.util.Optional<java.lang.Long>>addProducer(Producer producer, java.util.concurrent.CompletableFuture<java.lang.Void> producerQueuedFuture)Tries to add a producer to the topic.java.util.concurrent.CompletableFuture<org.apache.pulsar.common.protocol.schema.SchemaVersion>addSchema(org.apache.pulsar.common.protocol.schema.SchemaData schema)Add a schema to the topic.java.util.concurrent.CompletableFuture<java.lang.Void>checkSchemaCompatibleForConsumer(org.apache.pulsar.common.protocol.schema.SchemaData schema)Check if schema is compatible with current topic schema.protected voidcheckTopicFenced()voidcheckTopicPublishThrottlingRate()longcurrentUsageCount()voiddecrementUsageCount()booleandeletePartitionedTopicMetadataWhileInactive()java.util.concurrent.CompletableFuture<org.apache.pulsar.common.protocol.schema.SchemaVersion>deleteSchema()Delete the schema if this topic has a schema defined for it.java.util.concurrent.CompletableFuture<java.lang.Void>deleteTopicPolicies()voiddisableCnxAutoRead()protected voiddisableProducerRead()voidenableCnxAutoRead()protected voidenableProducerReadForPublishBufferLimiting()protected voidenableProducerReadForPublishRateLimiting()it sets cnx auto-readable if producer's cnx is disabled due to publish-throttling.protected ConsumergetActiveConsumer(Subscription subscription)PublishRateLimitergetBrokerPublishRateLimiter()BrokerServicegetBrokerService()Get BrokerService.longgetBytesInCounter()longgetBytesOutCounter()org.apache.pulsar.common.policies.data.InactiveTopicPoliciesgetInactiveTopicPolicies()longgetMsgInCounter()longgetMsgOutCounter()java.lang.StringgetName()abstract intgetNumberOfConsumers()abstract intgetNumberOfSameAddressConsumers(java.lang.String clientAddress)protected intgetNumberOfSameAddressConsumers(java.lang.String clientAddress, java.util.List<? extends Subscription> subscriptions)intgetNumberOfSameAddressProducers(java.lang.String clientAddress)java.util.Map<java.lang.String,Producer>getProducers()java.lang.StringgetReplicatorPrefix()booleangetSchemaValidationEnforced()java.util.Optional<org.apache.pulsar.common.policies.data.TopicPolicies>getTopicPolicies()GetTopicPoliciesfor this topic.PublishRateLimitergetTopicPublishRateLimiter()protected intgetWaitingProducersCount()voidhandleConsumerAdded(java.lang.String subscriptionName, java.lang.String consumerName)protected voidhandleProducerRemoved(Producer producer)protected booleanhasLocalProducers()java.util.concurrent.CompletableFuture<java.lang.Boolean>hasSchema()Whether a topic has had a schema defined for it.longincreasePublishLimitedTimes()increase the publishing limited times.voidincrementPublishCount(int numOfMessages, long msgSizeInBytes)protected abstract java.util.concurrent.CompletableFuture<java.lang.Long>incrementTopicEpoch(java.util.Optional<java.lang.Long> currentEpoch)protected java.util.concurrent.CompletableFuture<java.util.Optional<java.lang.Long>>incrementTopicEpochIfNeeded(Producer producer, java.util.concurrent.CompletableFuture<java.lang.Void> producerQueuedFuture)protected voidinternalAddProducer(Producer producer)booleanisBrokerPublishRateExceeded()protected booleanisConsumersExceededOnTopic()booleanisDeleteWhileInactive()booleanisEncryptionRequired()protected booleanisExceedMaximumMessageSize(int size)protected booleanisProducersExceeded(Producer producer)booleanisPublishRateExceeded()booleanisResourceGroupPublishRateExceeded(int numMessages, int bytes)booleanisResourceGroupRateLimitingEnabled()protected booleanisSameAddressConsumersExceededOnTopic(Consumer consumer)protected booleanisSameAddressProducersExceeded(Producer producer)protected abstract booleanisTerminated()booleanisTopicPublishRateExceeded(int numberMessages, int bytes)voidmarkBatchMessagePublished()voidrecordAddLatency(long latency, java.util.concurrent.TimeUnit unit)record add-latency.voidremoveProducer(Producer producer)voidresetBrokerPublishCountAndEnableReadIfRequired(boolean doneBrokerReset)voidresetInactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicDeleteMode inactiveTopicDeleteMode, int maxInactiveDurationSeconds, boolean deleteWhileInactive)voidresetTopicPublishCountAndEnableReadIfRequired()voidsetDeleteWhileInactive(boolean deleteWhileInactive)protected voidsetSchemaCompatibilityStrategy(org.apache.pulsar.common.policies.data.Policies policies)protected abstract java.util.concurrent.CompletableFuture<java.lang.Long>setTopicEpoch(long newEpoch)java.lang.StringtoString()voidupdateMaxPublishRate(org.apache.pulsar.common.policies.data.Policies policies)protected voidupdatePublishDispatcher(org.apache.pulsar.common.policies.data.PublishRate publishRate)update topic publish dispatcher for this topic.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.pulsar.broker.service.Topic
addSchemaIfIdleOrCheckCompatible, checkBackloggedCursors, checkDeduplicationSnapshot, checkGC, checkIfTransactionBufferRecoverCompletely, checkInactiveSubscriptions, checkMessageDeduplicationInfo, checkMessageExpiry, checkReplication, close, createSubscription, delete, deleteForcefully, endTxn, getBacklogQuota, getDispatchRateLimiter, getInternalStats, getLastMessageId, getLastPosition, getReplicators, getStats, getSubscription, getSubscriptions, initialize, isBacklogQuotaExceeded, isPersistent, isReplicated, isSystemTopic, onPoliciesUpdate, publishMessage, publishTxnMessage, subscribe, truncate, unsubscribe, updateRates
-
-
-
-
Field Detail
-
POLICY_UPDATE_FAILURE_RETRY_TIME_SECONDS
protected static final long POLICY_UPDATE_FAILURE_RETRY_TIME_SECONDS
- See Also:
- Constant Field Values
-
topic
protected final java.lang.String topic
-
producers
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,Producer> producers
-
brokerService
protected final BrokerService brokerService
-
replicatorPrefix
protected final java.lang.String replicatorPrefix
-
lock
protected final java.util.concurrent.locks.ReentrantReadWriteLock lock
-
isFenced
protected volatile boolean isFenced
-
inactiveTopicPolicies
protected org.apache.pulsar.common.policies.data.InactiveTopicPolicies inactiveTopicPolicies
-
lastActive
protected volatile long lastActive
-
hasBatchMessagePublished
protected volatile boolean hasBatchMessagePublished
-
addEntryLatencyStatsUsec
protected org.apache.bookkeeper.mledger.util.StatsBuckets addEntryLatencyStatsUsec
-
isEncryptionRequired
protected volatile boolean isEncryptionRequired
-
schemaCompatibilityStrategy
protected volatile org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy schemaCompatibilityStrategy
-
isAllowAutoUpdateSchema
protected volatile java.lang.Boolean isAllowAutoUpdateSchema
-
schemaValidationEnforced
protected volatile boolean schemaValidationEnforced
-
maxUnackedMessagesOnConsumerAppilied
protected volatile int maxUnackedMessagesOnConsumerAppilied
-
maxSubscriptionsPerTopic
protected volatile java.lang.Integer maxSubscriptionsPerTopic
-
topicPublishRateLimiter
protected volatile PublishRateLimiter topicPublishRateLimiter
-
resourceGroupPublishLimiter
protected volatile ResourceGroupPublishLimiter resourceGroupPublishLimiter
-
preciseTopicPublishRateLimitingEnable
protected boolean preciseTopicPublishRateLimitingEnable
-
resourceGroupRateLimitingEnabled
protected boolean resourceGroupRateLimitingEnabled
-
publishRateLimitedTimes
protected volatile long publishRateLimitedTimes
-
topicEpoch
protected volatile java.util.Optional<java.lang.Long> topicEpoch
-
msgOutFromRemovedSubscriptions
protected final java.util.concurrent.atomic.LongAdder msgOutFromRemovedSubscriptions
-
bytesOutFromRemovedSubscriptions
protected final java.util.concurrent.atomic.LongAdder bytesOutFromRemovedSubscriptions
-
-
Constructor Detail
-
AbstractTopic
public AbstractTopic(java.lang.String topic, BrokerService brokerService)
-
-
Method Detail
-
isProducersExceeded
protected boolean isProducersExceeded(Producer producer)
-
isSameAddressProducersExceeded
protected boolean isSameAddressProducersExceeded(Producer producer)
-
getNumberOfSameAddressProducers
public int getNumberOfSameAddressProducers(java.lang.String clientAddress)
-
isConsumersExceededOnTopic
protected boolean isConsumersExceededOnTopic()
-
isSameAddressConsumersExceededOnTopic
protected boolean isSameAddressConsumersExceededOnTopic(Consumer consumer)
-
getNumberOfConsumers
public abstract int getNumberOfConsumers()
-
getNumberOfSameAddressConsumers
public abstract int getNumberOfSameAddressConsumers(java.lang.String clientAddress)
-
getNumberOfSameAddressConsumers
protected int getNumberOfSameAddressConsumers(java.lang.String clientAddress, java.util.List<? extends Subscription> subscriptions)
-
addConsumerToSubscription
protected java.util.concurrent.CompletableFuture<java.lang.Void> addConsumerToSubscription(Subscription subscription, Consumer consumer)
-
getActiveConsumer
protected Consumer getActiveConsumer(Subscription subscription)
-
disableCnxAutoRead
public void disableCnxAutoRead()
- Specified by:
disableCnxAutoReadin interfaceTopic
-
enableCnxAutoRead
public void enableCnxAutoRead()
- Specified by:
enableCnxAutoReadin interfaceTopic
-
hasLocalProducers
protected boolean hasLocalProducers()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getProducers
public java.util.Map<java.lang.String,Producer> getProducers()
- Specified by:
getProducersin interfaceTopic
-
getBrokerService
public BrokerService getBrokerService()
Description copied from interface:TopicGet BrokerService.- Specified by:
getBrokerServicein interfaceTopic- Returns:
-
isEncryptionRequired
public boolean isEncryptionRequired()
- Specified by:
isEncryptionRequiredin interfaceTopic
-
getSchemaValidationEnforced
public boolean getSchemaValidationEnforced()
- Specified by:
getSchemaValidationEnforcedin interfaceTopic
-
markBatchMessagePublished
public void markBatchMessagePublished()
-
getReplicatorPrefix
public java.lang.String getReplicatorPrefix()
-
hasSchema
public java.util.concurrent.CompletableFuture<java.lang.Boolean> hasSchema()
Description copied from interface:TopicWhether a topic has had a schema defined for it.
-
addSchema
public java.util.concurrent.CompletableFuture<org.apache.pulsar.common.protocol.schema.SchemaVersion> addSchema(org.apache.pulsar.common.protocol.schema.SchemaData schema)
Description copied from interface:TopicAdd a schema to the topic. This will fail if the new schema is incompatible with the current schema.
-
deleteSchema
public java.util.concurrent.CompletableFuture<org.apache.pulsar.common.protocol.schema.SchemaVersion> deleteSchema()
Description copied from interface:TopicDelete the schema if this topic has a schema defined for it.- Specified by:
deleteSchemain interfaceTopic
-
checkSchemaCompatibleForConsumer
public java.util.concurrent.CompletableFuture<java.lang.Void> checkSchemaCompatibleForConsumer(org.apache.pulsar.common.protocol.schema.SchemaData schema)
Description copied from interface:TopicCheck if schema is compatible with current topic schema.- Specified by:
checkSchemaCompatibleForConsumerin interfaceTopic
-
addProducer
public java.util.concurrent.CompletableFuture<java.util.Optional<java.lang.Long>> addProducer(Producer producer, java.util.concurrent.CompletableFuture<java.lang.Void> producerQueuedFuture)
Description copied from interface:TopicTries to add a producer to the topic. Several validations will be performed.- Specified by:
addProducerin interfaceTopicproducerQueuedFuture- a future that will be triggered if the producer is being queued up prior of getting established- Returns:
- the "topic epoch" if there is one or empty
-
incrementTopicEpochIfNeeded
protected java.util.concurrent.CompletableFuture<java.util.Optional<java.lang.Long>> incrementTopicEpochIfNeeded(Producer producer, java.util.concurrent.CompletableFuture<java.lang.Void> producerQueuedFuture)
-
setTopicEpoch
protected abstract java.util.concurrent.CompletableFuture<java.lang.Long> setTopicEpoch(long newEpoch)
-
incrementTopicEpoch
protected abstract java.util.concurrent.CompletableFuture<java.lang.Long> incrementTopicEpoch(java.util.Optional<java.lang.Long> currentEpoch)
-
recordAddLatency
public void recordAddLatency(long latency, java.util.concurrent.TimeUnit unit)Description copied from interface:Topicrecord add-latency.- Specified by:
recordAddLatencyin interfaceTopic
-
setSchemaCompatibilityStrategy
protected void setSchemaCompatibilityStrategy(org.apache.pulsar.common.policies.data.Policies policies)
-
checkTopicPublishThrottlingRate
public void checkTopicPublishThrottlingRate()
- Specified by:
checkTopicPublishThrottlingRatein interfaceTopic
-
incrementPublishCount
public void incrementPublishCount(int numOfMessages, long msgSizeInBytes)- Specified by:
incrementPublishCountin interfaceTopic
-
resetTopicPublishCountAndEnableReadIfRequired
public void resetTopicPublishCountAndEnableReadIfRequired()
- Specified by:
resetTopicPublishCountAndEnableReadIfRequiredin interfaceTopic
-
resetBrokerPublishCountAndEnableReadIfRequired
public void resetBrokerPublishCountAndEnableReadIfRequired(boolean doneBrokerReset)
- Specified by:
resetBrokerPublishCountAndEnableReadIfRequiredin interfaceTopic
-
enableProducerReadForPublishRateLimiting
protected void enableProducerReadForPublishRateLimiting()
it sets cnx auto-readable if producer's cnx is disabled due to publish-throttling.
-
enableProducerReadForPublishBufferLimiting
protected void enableProducerReadForPublishBufferLimiting()
-
disableProducerRead
protected void disableProducerRead()
-
checkTopicFenced
protected void checkTopicFenced() throws BrokerServiceException- Throws:
BrokerServiceException
-
increasePublishLimitedTimes
public long increasePublishLimitedTimes()
Description copied from interface:Topicincrease the publishing limited times.- Specified by:
increasePublishLimitedTimesin interfaceTopic
-
internalAddProducer
protected void internalAddProducer(Producer producer) throws BrokerServiceException
- Throws:
BrokerServiceException
-
removeProducer
public void removeProducer(Producer producer)
- Specified by:
removeProducerin interfaceTopic
-
handleProducerRemoved
protected void handleProducerRemoved(Producer producer)
-
handleConsumerAdded
public void handleConsumerAdded(java.lang.String subscriptionName, java.lang.String consumerName)
-
decrementUsageCount
public void decrementUsageCount()
-
currentUsageCount
public long currentUsageCount()
-
isPublishRateExceeded
public boolean isPublishRateExceeded()
- Specified by:
isPublishRateExceededin interfaceTopic
-
isResourceGroupPublishRateExceeded
public boolean isResourceGroupPublishRateExceeded(int numMessages, int bytes)- Specified by:
isResourceGroupPublishRateExceededin interfaceTopic
-
isResourceGroupRateLimitingEnabled
public boolean isResourceGroupRateLimitingEnabled()
- Specified by:
isResourceGroupRateLimitingEnabledin interfaceTopic
-
isTopicPublishRateExceeded
public boolean isTopicPublishRateExceeded(int numberMessages, int bytes)- Specified by:
isTopicPublishRateExceededin interfaceTopic
-
isBrokerPublishRateExceeded
public boolean isBrokerPublishRateExceeded()
- Specified by:
isBrokerPublishRateExceededin interfaceTopic
-
getTopicPublishRateLimiter
public PublishRateLimiter getTopicPublishRateLimiter()
-
getBrokerPublishRateLimiter
public PublishRateLimiter getBrokerPublishRateLimiter()
-
updateMaxPublishRate
public void updateMaxPublishRate(org.apache.pulsar.common.policies.data.Policies policies)
-
getMsgInCounter
public long getMsgInCounter()
-
getBytesInCounter
public long getBytesInCounter()
-
getMsgOutCounter
public long getMsgOutCounter()
-
getBytesOutCounter
public long getBytesOutCounter()
-
isDeleteWhileInactive
public boolean isDeleteWhileInactive()
-
deletePartitionedTopicMetadataWhileInactive
public boolean deletePartitionedTopicMetadataWhileInactive()
-
setDeleteWhileInactive
public void setDeleteWhileInactive(boolean deleteWhileInactive)
-
isTerminated
protected abstract boolean isTerminated()
-
getInactiveTopicPolicies
public org.apache.pulsar.common.policies.data.InactiveTopicPolicies getInactiveTopicPolicies()
-
resetInactiveTopicPolicies
public void resetInactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicDeleteMode inactiveTopicDeleteMode, int maxInactiveDurationSeconds, boolean deleteWhileInactive)
-
getTopicPolicies
public java.util.Optional<org.apache.pulsar.common.policies.data.TopicPolicies> getTopicPolicies()
GetTopicPoliciesfor this topic.- Returns:
- TopicPolicies, if they exist. Otherwise, the value will not be present.
-
deleteTopicPolicies
public java.util.concurrent.CompletableFuture<java.lang.Void> deleteTopicPolicies()
-
getWaitingProducersCount
protected int getWaitingProducersCount()
-
isExceedMaximumMessageSize
protected boolean isExceedMaximumMessageSize(int size)
-
updatePublishDispatcher
protected void updatePublishDispatcher(org.apache.pulsar.common.policies.data.PublishRate publishRate)
update topic publish dispatcher for this topic.
-
-