【发布时间】:2015-04-25 06:56:40
【问题描述】:
我目前正在将 RTI DDS 用于我正在实施的 pub 子系统,并且对于某些主题希望保持历史深度仅为 1 以便在需要时保持重新发送以及其他主题,如果需要的话,想要保留所有的历史记录。下面是我正在使用的Qos policy 文件。
<?xml version="1.0"?>
<dds>
<qos_library name="Keep_History_Library">
<qos_profile name="Keep_History_profile" is_default_qos="true">
<datawriter_qos name="ReliableWriter">
<property>
<value>
<element>
<name>dds.data_writer.history.memory_manager.fast_pool.pool_buffer_max_size</name>
<!-- Typical size of your data type. -->
<value>32000</value>
</element>
</value>
</property>
<durability>
<kind>TRANSIENT_LOCAL_DURABILITY_QOS</kind>
</durability>
<history><kind>KEEP_LAST_HISTORY_QOS</kind><depth>1</depth></history>
<reliability>
<kind>RELIABLE_RELIABILITY_QOS</kind>
</reliability>
<publication_name>
<name>HistoryDataWriter</name>
</publication_name>
</datawriter_qos>
<datareader_qos name="ReliableReader">
<history><kind>KEEP_LAST_HISTORY_QOS</kind><depth>1</depth></history>
<reliability>
<kind>RELIABLE_RELIABILITY_QOS</kind>
</reliability>
<durability>
<kind>TRANSIENT_LOCAL_DURABILITY_QOS</kind>
</durability>
<subscription_name>
<name>HistoryDataReader</name>
</subscription_name>
</datareader_qos>
</qos_profile>
<qos_profile name="Keep_All_History_profile">
<datawriter_qos name="ReliableWriter">
<property>
<value>
<element>
<name>dds.data_writer.history.memory_manager.fast_pool.pool_buffer_max_size</name>
<!-- Typical size of your data type. -->
<value>32000</value>
</element>
</value>
</property>
<history><kind>KEEP_ALL_HISTORY_QOS</kind></history>
<reliability>
<kind>RELIABLE_RELIABILITY_QOS</kind>
</reliability>
<durability>
<kind>TRANSIENT_LOCAL_DURABILITY_QOS</kind>
</durability>
<publication_name>
<name>HistoryDataWriter</name>
</publication_name>
</datawriter_qos>
<datareader_qos name="ReliableReader">
<history><kind>KEEP_ALL_HISTORY_QOS</kind><depth>1000000</depth></history>
<reliability>
<kind>RELIABLE_RELIABILITY_QOS</kind>
</reliability>
<durability>
<kind>TRANSIENT_LOCAL_DURABILITY_QOS</kind>
</durability>
<subscription_name>
<name>HistoryDataReader</name>
</subscription_name>
</datareader_qos>
</qos_profile>
</qos_library>
</dds>
以下是用java编写的代码,用于从Qos policy文件中为读者加载Keep_All_History_profile。
DataReaderQos datareader_qos = new DataReaderQos();
DomainParticipantFactory.TheParticipantFactory.get_datareader_qos_from_profile(datareader_qos, "Keep_History_Library", "Keep_All_History_profile");
以及将Qos 文件加载到编写器中的代码
DataWriterQos datawriter_qos = new DataWriterQos();
DomainParticipantFactory.TheParticipantFactory.get_datawriter_qos_from_profile(datawriter_qos, "Keep_History_Library", "Keep_All_History_profile");
但是我遇到的问题是,当我尝试加载 Keep All History profile 时,只有 1 的深度才会保留而不再存在。但是,如果我将配置文件的keep last history 部分更改为深度为 10,它将保留并读取应该加载保留所有历史记录的最后 10 条消息。为什么会发生这种情况,看起来好像加载了错误的配置文件?
编辑
用于制作数据写入器的代码,在加载Qos 配置文件后立即使用。
writer = (DataDataWriter)
publisher.create_datawriter(
topic, Publisher.DATAWRITER_QOS_DEFAULT,
null, StatusKind.STATUS_MASK_NONE);
if (writer == null) {
System.err.println("create_datawriter error\n");
return;
}
还有数据阅读器
listener = new DataListener();
reader = (DataDataReader)
subscriber.create_datareader(
topic, Subscriber.DATAREADER_QOS_DEFAULT, listener,
StatusKind.STATUS_MASK_ALL);
if (reader == null) {
System.err.println("create_datareader error\n");
return;
}
}
然后数据读取器使用以下方法发送消息,
public void writeData(String results) throws InterruptedException
{
instance.results = results;
writer.write(instance, handle);
}
【问题讨论】:
-
KEEP_ALL_HISTORY_QOS 不使用
... 元素。请从 Keep_All_History_profile 个人资料中删除它。 (另外,配置文件中 Writer 的深度在值的末尾有一个无关的 >) -
并展示您的工作——您如何继续在代码中使用 datareader_qos 和 datawriter_qos 对象?
-
@rip... 这就是我的想法,但是后来网络上的一些示例显示了保留所有内容的深度,因此我将其放回原来的状态。我将展示我如何创建数据读取器和写入器以及发送数据。
-
@rip... 写入器中 datawriter_qos 的打印输出显示以下内容。 history_kind=KEEP_LAST_HISTORY_QOS, history_depth=1 以及 history=HistoryQosPolicy[kind=KEEP_ALL_HISTORY_QOS, depth=1
标签: java publish-subscribe qos data-distribution-service