为什么 OpenDDS 在删除 DataWriter 时重新发送相同的最后数据
Why OpenDDS resends same last data when DataWriter is deleted
我想了解为什么删除DataWriter 后OpenDDS 会重新发送相同的最后一条数据n 次(其中n 是已发送的消息数)?
这是我错过的特定 QoS 的影响吗?
我做的一个小测试的输出:
Received data ! ID = 0 Text = Hello world !
Received data ! ID = 1 Text = Hello world !
Received data ! ID = 2 Text = Hello world !
Received data ! ID = 3 Text = Hello world !
Received data ! ID = 4 Text = Hello world !
Received data ! ID = 5 Text = Hello world !
Received data ! ID = 6 Text = Hello world !
Received data ! ID = 7 Text = Hello world !
Received data ! ID = 8 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
我们在该示例中清楚地看到 DataReader 发送和接收了 10 条消息。然后,一旦 DataWriter 被删除(或在删除过程中?),就会出现 10 次重复收到的最后一条消息。
在网上搜索,我找到了我自己的问题的答案:
其实DataSample
里面没有数据。 valid_data
标志用于识别 DataSample
是否有数据。
这些空的 DataSample
象征着当 DataWriter
关闭时 OpenDDS 内部状态变化的通知。它们不应被阅读,而应被视为通知。
虽然我没有具体使用 OpenDDS 的经验,但我想扩展您自己的答案,这对我来说似乎并不完全正确。我基于 DDS specification.
中描述的机制
These empty DataSample symbolized notifications of changes of states internally in OpenDDS when the DataWriter went off.
根据 DDS 规范,DataWriter 的销毁会导致其所有实例的注销。取消注册意味着实例的状态从 ALIVE 变为 NOT_ALIVE。这些状态更改不像您写的那样 "internal",而是旨在让任何感兴趣的人看到。订阅应用程序可以通过检查 instance_state
field in the SampleInfo
结构来了解这一点。
在您的例子中,您写入了 10 个实例(键值),因此 DataWriter 的销毁导致了 10 次更新,每次更新都表明先前发布的实例的状态发生了变化。
They should not be read but just be considered as notifications.
由于这些更新仅指示对实例状态的更改,因此 valid_data
标志已清除,实际上不应读取它们的数据字段。但是,仍然可以通过在相关 DataReader 上调用 get_key_value() 并将 instance_handle
字段中找到的 InstanceHandle_t
传递给它来确定更新是关于哪个实例11=] 结构。如果你这样做,那么你会注意到在你的情况下,每个 ID
从 0 到 9 都会有一个通知。
我想了解为什么删除DataWriter 后OpenDDS 会重新发送相同的最后一条数据n 次(其中n 是已发送的消息数)?
这是我错过的特定 QoS 的影响吗?
我做的一个小测试的输出:
Received data ! ID = 0 Text = Hello world !
Received data ! ID = 1 Text = Hello world !
Received data ! ID = 2 Text = Hello world !
Received data ! ID = 3 Text = Hello world !
Received data ! ID = 4 Text = Hello world !
Received data ! ID = 5 Text = Hello world !
Received data ! ID = 6 Text = Hello world !
Received data ! ID = 7 Text = Hello world !
Received data ! ID = 8 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
我们在该示例中清楚地看到 DataReader 发送和接收了 10 条消息。然后,一旦 DataWriter 被删除(或在删除过程中?),就会出现 10 次重复收到的最后一条消息。
在网上搜索,我找到了我自己的问题的答案:
其实DataSample
里面没有数据。 valid_data
标志用于识别 DataSample
是否有数据。
这些空的 DataSample
象征着当 DataWriter
关闭时 OpenDDS 内部状态变化的通知。它们不应被阅读,而应被视为通知。
虽然我没有具体使用 OpenDDS 的经验,但我想扩展您自己的答案,这对我来说似乎并不完全正确。我基于 DDS specification.
中描述的机制These empty DataSample symbolized notifications of changes of states internally in OpenDDS when the DataWriter went off.
根据 DDS 规范,DataWriter 的销毁会导致其所有实例的注销。取消注册意味着实例的状态从 ALIVE 变为 NOT_ALIVE。这些状态更改不像您写的那样 "internal",而是旨在让任何感兴趣的人看到。订阅应用程序可以通过检查 instance_state
field in the SampleInfo
结构来了解这一点。
在您的例子中,您写入了 10 个实例(键值),因此 DataWriter 的销毁导致了 10 次更新,每次更新都表明先前发布的实例的状态发生了变化。
They should not be read but just be considered as notifications.
由于这些更新仅指示对实例状态的更改,因此 valid_data
标志已清除,实际上不应读取它们的数据字段。但是,仍然可以通过在相关 DataReader 上调用 get_key_value() 并将 instance_handle
字段中找到的 InstanceHandle_t
传递给它来确定更新是关于哪个实例11=] 结构。如果你这样做,那么你会注意到在你的情况下,每个 ID
从 0 到 9 都会有一个通知。