Class TopicName

java.lang.Object
org.apache.pulsar.common.naming.TopicName
All Implemented Interfaces:
ServiceUnitId

public class TopicName extends Object implements ServiceUnitId
Encapsulate the parsing of the completeTopicName name.
  • Field Details

  • Method Details

    • get

      public static TopicName get(String domain, NamespaceName namespaceName, String topic)
    • get

      public static TopicName get(String domain, String tenant, String namespace, String topic)
    • get

      public static TopicName get(String domain, String tenant, String cluster, String namespace, String topic)
    • get

      public static TopicName get(String topic)
    • getPartitionedTopicName

      public static TopicName getPartitionedTopicName(String topic)
    • isValid

      public static boolean isValid(String topic)
    • isPersistent

      public boolean isPersistent()
    • getNamespace

      public String getNamespace()
      Extract the namespace portion out of a completeTopicName name.

      Works both with old & new convention.

      Returns:
      the namespace
    • getNamespaceObject

      public NamespaceName getNamespaceObject()
      Get the namespace object that this completeTopicName belongs to.
      Specified by:
      getNamespaceObject in interface ServiceUnitId
      Returns:
      namespace object
    • getDomain

      public TopicDomain getDomain()
    • getTenant

      public String getTenant()
    • getCluster

      @Deprecated public String getCluster()
      Deprecated.
    • getNamespacePortion

      public String getNamespacePortion()
    • getLocalName

      public String getLocalName()
    • getEncodedLocalName

      public String getEncodedLocalName()
    • getPartition

      public TopicName getPartition(int index)
    • getPartitionIndex

      public int getPartitionIndex()
      Returns:
      partition index of the completeTopicName. It returns -1 if the completeTopicName (topic) is not partitioned.
    • isPartitioned

      public boolean isPartitioned()
    • getPartitionedTopicName

      public String getPartitionedTopicName()
      For partitions in a topic, return the base partitioned topic name. Eg:
      • persistent://prop/cluster/ns/my-topic-partition-1 --> persistent://prop/cluster/ns/my-topic
      • persistent://prop/cluster/ns/my-topic --> persistent://prop/cluster/ns/my-topic
    • getPartitionIndex

      public static int getPartitionIndex(String topic)
      Returns:
      partition index of the completeTopicName. It returns -1 if the completeTopicName (topic) is not partitioned.
    • getTopicPartitionNameString

      public static String getTopicPartitionNameString(String topic, int partitionIndex)
      A helper method to get a partition name of a topic in String.
      Returns:
      topic + "-partition-" + partition.
    • getRestPath

      public String getRestPath()
      Returns the http rest path for use in the admin web service. Eg: * "persistent/my-tenant/my-namespace/my-topic" * "non-persistent/my-tenant/my-namespace/my-topic"
      Returns:
      topic rest path
    • getRestPath

      public String getRestPath(boolean includeDomain)
    • getPersistenceNamingEncoding

      public String getPersistenceNamingEncoding()
      Returns the name of the persistence resource associated with the completeTopicName.
      Returns:
      the relative path to be used in persistence
    • fromPersistenceNamingEncoding

      public static String fromPersistenceNamingEncoding(String mlName)
      get topic full name from managedLedgerName.
      Returns:
      the topic full name, format -> domain://tenant/namespace/topic
    • getLookupName

      public String getLookupName()
      Get a string suitable for completeTopicName lookup.

      Example:

      persistent://tenant/cluster/namespace/completeTopicName -> persistent/tenant/cluster/namespace/completeTopicName

      Returns:
    • isGlobal

      public boolean isGlobal()
    • getSchemaName

      public String getSchemaName()
    • toString

      public String toString()
      Specified by:
      toString in interface ServiceUnitId
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • includes

      public boolean includes(TopicName otherTopicName)
      Description copied from interface: ServiceUnitId
      Check whether a fully-qualified topic is included in this ServiceUnitId object.
      Specified by:
      includes in interface ServiceUnitId
      Parameters:
      otherTopicName - a fully-qualified topic object
      Returns:
      true or false
    • isV2

      public boolean isV2()
      Returns true if this a V2 topic name prop/ns/topic-name.
      Returns:
      true if V2