DomainParticipant.find_topic not working in Java API

3 posts / 0 new
Last post
Offline
Last seen: 8 months 1 week ago
Joined: 05/04/2023
Posts: 5
DomainParticipant.find_topic not working in Java API

 

With the following JAVA code (dds 7.1) the topic is created successfully, however topic2,  the result of 'find_topic()' is always null. 

Topic topic = my_participant.create_topic(topic_name,

type_name,

DomainParticipant.TOPIC_QOS_DEFAULT, 

null, 

StatusKind.STATUS_MASK_NONE);
}

Topic topic2 = my_participant.find_topic( topic_name, null);

Organization:
Offline
Last seen: 8 months 1 week ago
Joined: 05/04/2023
Posts: 5

I have found that   participant.lookup_topicdescription(topic_name)  works as expected!

Offline
Last seen: 5 months 1 week ago
Joined: 12/05/2019
Posts: 16

Hello sander66, the reason why "find_topic" is failing is because the second argument is null. As specified in the documentation, this is the timeout to wait until a Topic has been completely created, and cannot be null.

If you're only interested in a TopicDescription, that is, a description of a topic but are not interested in using it for creating entities (DataReader, DataWriter), you can continue using "lookup_topicdescription".
If you're interested in using "topic2" to create entities, consider using "find_topic" with a valid timeout argument.

EDIT: After re-reading the documentation, "find_topic" will create a new Topic whereas "lookup_topicdescription" will return a reference to an existing one. With the latter, you can simply cast the object to "Topic" and use it in entity creation.