rticommunity / rticonnextdds-connector-go

RTI Connector for Connext DDS is a lightweight technology that enables DDS data to be accessed with Go.
Other
26 stars 12 forks source link

Feature Request: Expose NOT_ALIVE_NO_WRITERS instance state #52

Closed tom-wp closed 1 month ago

tom-wp commented 1 year ago

Proposal:

We would like to be able to determine if there are any writers alive for a particular topic instance. I understand that if the heartbeat of last writer of a topic instance has timed out there should be a sample with the instance state NOT_ALIVE_NO_WRITERS in the queue. It would be great if this could be exposed to the go connector.

Current behavior:

No ability to check if there are any writers for a topic instance.

Desired behavior:

Sample received indicating that there are no remaining writers.

Use case:

Checking if remote devices have been powered off or lost network connectivity.

tom-wp commented 3 months ago

Any update on this issue? Is this project still live or is there an alternative recommended approach for integrating RTI DDS with Golang applications?

kyoungho commented 3 months ago

@tom-wp Apologies for overlooking this open issue. The functionality of Go Connector depends on the capabilities provided by the underlying Connector library in C. If the Connector C library lacks a method for get the instance state, it limits the support within Go Connector. I'll reach out to the Connector team to check whether this feature is supported within the C library.

kyoungho commented 3 months ago

@tom-wp I was looking at the Python Connector and looks like there is a way to get an instance state. https://github.com/rticommunity/rticonnextdds-connector-py/blob/master/rticonnextdds_connector/rticonnextdds_connector.py#L689

I will work on this and keep you updated on it.

kyoungho commented 3 months ago

Just added the GetInstanceState function. This function will return a string (one of "ALIVE", "NOT_ALIVE_DISPOSED" or "NOT_ALIVE_NO_WRITERS").

https://github.com/rticommunity/rticonnextdds-connector-go/blob/master/info.go#L158

Please try out and let me know if you have any issues. Thanks.

tom-wp commented 3 months ago

@kyoungho excellent, thank you. I will try this out and let you know how I get on.

kyoungho commented 3 months ago

@tom-wp Sounds good. BTW, can you share your use case with Go Connector? If you prefer, we can communicate via email (my email address is kyoungho@rti.com). Thanks.

tom-wp commented 3 months ago

@kyoungho the GetInstanceState method works well for detecting NOT_ALIVE_NO_WRITERS, the next issue is determining the key of the instance that generated this state change. As the data is invalid we cannot read the key directly, instead we need to read the instance_handle (same value as the key, as the key is 16-bytes) but this isn't exposed by the go-connector. It also appears that it isn't exposed by the c-library either. When forking the connector and trying to add a method for retrieving it, the library returns the following error:

RTILuaSampleInfo_get:Unknown SampleInfo field: instance_handle
RTILuaMetamethodImpl_InDataDereference:!RTILuaSampleInfo_get failed with retcode  1
RTILuaMetamethodImpl_InData:!dereference operation failed with retcode
RTI_Connector_get_json_from_infos:!get stack values

It would be great to get this working but in the meantime we have a work around:

Store a map of key values against the publisher ids (from GetIdentity) for valid samples, then index this by the publisher id on the NOT_ALIVE_NO_WRITERS sample. This only works as we currently have a 1:1 relationship between publishers and instance keys on this particular topic.

kyoungho commented 3 months ago

Hi @tom-wp The instance_handle appears to not be exposed in the C library. I have taken note of your report and have logged it in our internal issue tracking system under the issue ID CON-317. Appreciate your detailed description of your use case and the workaround you've shared.