Java RTI DDS Qos配置文件历史记录未按预期工作
我目前正在为我正在实施的一个发布子系统使用RTI DDS,对于某些主题,我希望保持历史深度仅为1,以便在需要时保留重新发布,对于其他主题,我希望保留所有历史,以便在需要时重新发布。下面是我正在使用的Java RTI DDS Qos配置文件历史记录未按预期工作,java,publish-subscribe,qos,data-distribution-service,Java,Publish Subscribe,Qos,Data Distribution Service,我目前正在为我正在实施的一个发布子系统使用RTI DDS,对于某些主题,我希望保持历史深度仅为1,以便在需要时保留重新发布,对于其他主题,我希望保留所有历史,以便在需要时重新发布。下面是我正在使用的Qos策略文件 <?xml version="1.0"?> <dds> <qos_library name="Keep_History_Library"> <qos_profile name="Keep_H
Qos策略
文件
<?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>
以及将Qos
文件加载到编写器中的代码
DataWriterQos datawriter_qos = new DataWriterQos();
DomainParticipantFactory.TheParticipantFactory.get_datawriter_qos_from_profile(datawriter_qos, "Keep_History_Library", "Keep_All_History_profile");
然而,我遇到的问题是,当我尝试加载保留所有历史配置文件
时,一个深度仅为保留,不再是。但是,如果我将配置文件的keep last history
部分更改为深度10,则它将保留并读取最后10条消息,其中keep all history应该加载。为什么会发生这种情况,好像加载了错误的配置文件
编辑
用于在加载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);
}
你为什么看到你所看到的: 您使用的是Subscriber.DATAREADER\u QOS\u DEFAULT和Publisher.DATAREADER\u QOS\u DEFAULT,并且在Keep\u Last depth 1配置文件上设置了“is\u DEFAULT\u QOS”布尔值 它在引擎盖下做什么: 当您在配置文件“Foo”上设置了is_default_qos标志时,即当您使用*_qos_默认标志时将使用的配置文件。即使您使用其他个人资料中的参与者个人资料 *\u QOS\u默认标志将始终恢复为“is\u DEFAULT\u QOS”配置文件 如何得到你想要的: 如果要使用Subscriber.DATAREADER\u QOS\u默认值和Publisher.DATAREADER\u QOS\u默认值,则必须告诉订阅服务器和发布服务器对象它们将使用不同的默认值
subscriber.set_default_datareader_qos_with_profile(
"Keep_History_Library", "Keep_All_History_profile");
publisher.set_default_datareader_qos_with_profile(
"Keep_History_Library", "Keep_All_History_profile");
或
使用工厂调用的_create_with_profile变量:
subscriber.create_datareader_with_profile(
topic, "Keep_History_Library", "Keep_All_History_profile",
listener, StatusKind.STATUS_MASK_ALL);
publisher.create_datawriter_with_profile(
topic, "Keep_History_Library", "Keep_All_History_profile",
null, StatusKind.STATUS_MASK_NONE);
KEEP_ALL_HISTORY_QOS不使用。。。元素。请将其从保留所有历史档案中删除。(此外,编写器在配置文件中的深度在值的末尾有一个无关的>)并显示您的工作--如何在代码中继续使用datareader_qos和datawriter_qos对象?@rip。。。这就是我所想的,但是网络上的一些例子显示了保留所有内容的深度,所以我将把它放回我最初拥有的内容。我将演示如何创建数据读写器以及如何发送数据。@rip。。。写入程序中datawriter_qos的打印输出显示以下内容。history\u kind=KEEP\u LAST\u history\u QOS,history\u depth=1以及history=HistoryQosPolicy[kind=KEEP\u ALL\u history\u QOS,depth=1
subscriber.create_datareader_with_profile(
topic, "Keep_History_Library", "Keep_All_History_profile",
listener, StatusKind.STATUS_MASK_ALL);
publisher.create_datawriter_with_profile(
topic, "Keep_History_Library", "Keep_All_History_profile",
null, StatusKind.STATUS_MASK_NONE);