@@ -45,7 +45,7 @@ public class TopicName implements ServiceUnitId {
4545 private final String namespacePortion ;
4646 private final String localName ;
4747
48- private volatile NamespaceName namespaceName ;
48+ private final NamespaceName namespaceName ;
4949
5050 private final int partitionIndex ;
5151
@@ -138,6 +138,7 @@ private TopicName(String completeTopicName) {
138138 }
139139 this .partitionIndex = getPartitionIndex (localName );
140140 this .completeTopicName = domain .name () + "://" + tenant + "/" + namespacePortion + "/" + localName ;
141+ this .namespaceName = NamespaceName .get (tenant , namespacePortion );
141142 } else {
142143 // The fully qualified topic name can be in two different forms:
143144 // new: persistent://tenant/namespace/topic
@@ -154,13 +155,15 @@ private TopicName(String completeTopicName) {
154155 this .namespacePortion = parts .get (1 );
155156 this .localName = parts .get (2 );
156157 this .partitionIndex = getPartitionIndex (localName );
158+ this .namespaceName = NamespaceName .get (tenant , namespacePortion );
157159 } else if (parts .size () == 4 ) {
158160 // Legacy topic name that includes cluster name
159161 this .tenant = parts .get (0 );
160162 this .cluster = parts .get (1 );
161163 this .namespacePortion = parts .get (2 );
162164 this .localName = parts .get (3 );
163165 this .partitionIndex = getPartitionIndex (localName );
166+ namespaceName = NamespaceName .get (tenant , cluster , namespacePortion );
164167 } else {
165168 throw new IllegalArgumentException ("Invalid topic name " + completeTopicName );
166169 }
@@ -200,16 +203,6 @@ public String getNamespace() {
200203 */
201204 @ Override
202205 public NamespaceName getNamespaceObject () {
203- if (namespaceName != null ) {
204- return namespaceName ;
205- }
206- synchronized (this ) {
207- if (cluster == null ) {
208- namespaceName = NamespaceName .get (tenant , namespacePortion );
209- } else {
210- namespaceName = NamespaceName .get (tenant , cluster , namespacePortion );
211- }
212- }
213206 return namespaceName ;
214207 }
215208
0 commit comments