Setting QoS in java

2 posts / 0 new
Last post
Offline
Last seen: 9 years 4 months ago
Joined: 09/22/2014
Posts: 2
Setting QoS in java

Hi,

I've created a writer that works as expected with normal QoS, but when I want to change some of the settings (programatically, in Java) it resets to the default QoS. Is there some sort of overwriting mechanism going on, or is there a hierarchy of prioritised QoS settings? What I'm doing is this:

 //Basing the custom QoS off the default.
DataWriterQos qos = Publisher.DATAWRITER_QOS_DEFAULT;

//Change one setting.
qos.destination_order.kind = DestinationOrderQosPolicyKind.BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS;

//The following gives me the BY_SOURCE_TIMESTAMP(...) as expected
System.out.println(qos.destination_order.kind);

//Use the qos as defined above to create a data writer.
final DataWriterImpl dataWriter = (...) defaultDomainParticipantStatusMaskNone.create_datawriter(<<Valid type support>>, qos, null, StatusKind.STATUS_MASK_NONE);
    

 

Here the defaultDomainParticipantStatusMaskNone is what you think it is; a domain participant created by the DomainParticipantFactory.get_instance().create_participant() with valid parameters, including a PARTICIPANT_QOS_DEFAULT parameter, and StatusKind.STATUS_MASK_NONE.

The datawriter is created, but when I analyse it the writer just shows up as having the default settings, i.e. by reception timestamp. What am I missing?

Keywords:
rip
rip's picture
Offline
Last seen: 1 day 1 hour ago
Joined: 04/06/2012
Posts: 324

Hi,

This below is not exactly the same process.  In this use, I've already created the datawriter, I'm just setting a mutable field (lifespan) after the writer has already been instantiated.  What I'm bringing attention to is the first two lines.

	DataWriterQos dwqos = new DataWriterQos();
        myParticipant.get_default_datawriter_qos(dwqos);

        dwqos.lifespan.duration.sec = 2;
        dwqos.lifespan.duration.nanosec = 500000000;
        dwqos.history.kind = HistoryQosPolicyKind.KEEP_ALL_HISTORY_QOS;

        wCircle.set_qos(dwqos);

In your case, what I think you are seeing, is you are getting a reference to the default qos (out of the c-based JNI-accessed libraries), editing the structure in java, and then writing it back.  Or trying to.  You can't though, because the underlying default QoS is immutable.  Probably there should be a warning instead of simply failing silently.   I think that the JNI layer interface isn't writing the changes back to the actual runtime (in C, underneath the java), because the pointer is to an immutable structure.

Anyway, the above algorithm works, get a new QoS local object, copy the default values into it, make changes, and then use the local object when you do the create call.

Your code would end up looking something like this:

	DataWriterQos dwqos = new DataWriterQos();
        myParticipant.get_default_datawriter_qos(dwqos);

        dwqos.destination_order.kind = DestinationOrderQosPolicyKind.BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS;

        final myTypeDataWriter dataWriter = (myTypeDataWriter) defaultDomainParticipantStatusMaskNone
		.create_datawriter(myType, dwqos, null, StatusKind.STATUS_MASK_NONE);