我目前正在使用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编写的代码,用于从Keep_All_History_profile文件中为读者加载Qos policy。
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时,深度只是保持,而不再是。但是,如果我将配置文件的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);
}发布于 2015-02-23 22:52:34
为什么你看到你看到的:
您正在使用Subscriber.DATAREADER_QOS_DEFAULT和Publisher.DATAREADER_QOS_DEFAULT,并且在Keep_Last深度1配置文件上设置了“is_default_qos”布尔值。
它在引擎盖下做什么:
当您在配置文件"Foo“上设置is_default_qos标志时,即使用*_QOS_DEFAULT标志时将使用的配置文件。即使您使用其他配置文件中的参与者配置文件。
*_QOS_DEFAULT标志将始终恢复为"is_default_qos“配置文件。
如何得到你想要的:
如果您想使用Subscriber.DATAREADER_QOS_DEFAULT和Publisher.DATAREADER_QOS_DEFAULT,那么您必须告诉订阅服务器和发布服务器对象,它们将使用不同的默认值。
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);https://stackoverflow.com/questions/28682469
复制相似问题