从DDS删除已读主题 [英] Remove read topic from DDS

查看:120
本文介绍了从DDS删除已读主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Java平台订阅数据时遇到问题。当订阅者订阅主题时,必须从DDS中删除该订阅的数据。但就我而言,每当我预订数据时,同一数据就会被预订很多次。不会从DDS中删除数据。我尝试使用QoS,但不知道如何使用它。

I have a problem with subscribing the data (using the java platform). When a subscriber subscribes to a topic, that subscribed data must be removed from the DDS. But in my case whenever I subscribe to the data the same data is subscribed many times. The data is not removed from the DDS. I tried with QoS but I don't know how to use it.

请建议我如何从DDS中删除读取的数据。

Please suggest how I can remove the read data from the DDS.

推荐答案

此行为不是由您的QoS设置引起的,而是由您访问 DataReader 的方法引起的。检索数据时,您可能会在循环中调用以下 read()之类的东西:

This behavior is not caused by your QoS settings, but by your method of accessing the DataReader. When you retrieve your data, you are probably calling something like the following read() in a loop:

FooReader.read(
    dataSeq, infoSeq, 10,
    ANY_SAMPLE_STATE.value,
    ANY_VIEW_STATE.value,
    ANY_INSTANCE_STATE.value);

像这样调用的 read()方法将会在您的 FooReader 中返回所有当前可用的示例。在 read()之后,这些样本仍保留在 FooReader 中,这就是 read()方法起作用。将阅读内容视为偷看。下次以此方式调用 read()方法时,您将看到以前看到的所有示例,除非它们已被<中的新更新覆盖。 code> DataWriter 。

The read() method invoked like this will return all currently available samples in your FooReader. After the read(), those samples still remain available in the FooReader, that is how the read() method behaves. Think of a read as a "peek". The next time that you invoke the read() method in this way, you will see all samples that you saw before, unless they have been overwritten by a new update from a DataWriter.

要解决您的问题,可以替换 read() take(),例如:

To resolve your issue, you could replace the read() with a take(), like this:

FooReader.take(
    dataSeq, infoSeq, 10,
    ANY_SAMPLE_STATE.value,
    ANY_VIEW_STATE.value,
    ANY_INSTANCE_STATE.value);

take()方法与 read()方法的作用是破坏性的读取;它不仅读取数据,还将其从 FooReader 中删除​​。这样,您将永远不会两次收到相同的样本。实际上,如果您始终使用 take()而不是 read(),您将永远看不到任何示例两次。

The take() method is different from the read() method in that it does a destructive read; it not only reads the data but also removes it from FooReader. That way, you will never receive the same sample twice. In fact, if you consistently use take() as opposed to read(), you will never be able to see any sample twice.

解决问题的另一种方法是坚持使用 read(),但要调整请求的值 SAMPLE_STATE ,从 ANY NOT_READ ,如下所示:

Another way to resolve your issue is to stick with read(), but adjust the requested SAMPLE_STATE, from ANY to NOT_READ, like this:

FooReader.read(
    dataSeq, infoSeq, 10,
    NOT_READ_SAMPLE_STATE.value,
    ANY_VIEW_STATE.value,
    ANY_INSTANCE_STATE.value);

这样,您将只读取以前未读过的样本。在这种情况下,与 take()的区别在于,数据确实在您的 FooReader 中仍然可用。如果您想在以后重新读取它(在这种情况下,您需要使用 ANY 示例状态,而不是 NOT_READ 来获取以前读取的样本。

That way, you will only read samples that you have not read previously. The difference with take() in this case is that the data does remain available in your FooReader, which might be useful if you want to re-read it at a later stage (in which case you need to use the ANY sample state as opposed to NOT_READ to obtain previously read samples).

这篇关于从DDS删除已读主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆