Working with subscribers.
Working with subscribers.
Setting up a subscriber
- Set up participant
- Create a Subscriber
SubscriberQos subscriber_qos = new SubscriberQos();
SubscriberListener subscriber_listener
= new MySubscriberListener();
participant.get_default_subscriber_qos(subscriber_qos);
Subscriber subscriber = null;
try {
subscriber = participant.create_subscriber(subscriber_qos,
subscriber_listener,
StatusKind.STATUS_MASK_ALL);
} catch (RETCODE_ERROR err) {
}
Set up subscriber to access received data
Access received data via a subscriber
- Ensure subscriber is set up to access received data
- Get the list of readers that have data samples available:
DataReaderSeq reader_seq = new DataReaderSeq();
int max_samples = DataReader.LENGTH_UNLIMITED;
int sample_state_mask = SampleStateKind.NOT_READ_SAMPLE_STATE;
int view_state_mask = ViewStateKind.ANY_VIEW_STATE;
int instance_state_mask = InstanceStateKind.ANY_INSTANCE_STATE;
try {
subscriber.get_datareaders(reader_seq,
sample_state_mask,
view_state_mask,
instance_state_mask);
} catch (RETCODE_ERROR err) {
}
- Upon successfully getting the list of readers with data, process the data readers to either:
If the intent is to access the data coherently or in order, the list of data readers must be processed in the order returned:
for (int i = 0; i < reader_seq.size(); ++i) {
FooDataReader reader = (FooDataReader) reader_seq.get(i);
}
- Alternatively, call com.rti.dds.subscription.Subscriber.notify_datareaders to invoke the DataReaderListener for each of the data readers.
subscriber.notify_datareaders();
Access received data coherently and/or in order
To access the received data coherently and/or in an ordered manner, according to the settings of the com.rti.dds.infrastructure.PresentationQosPolicy attached to a com.rti.dds.subscription.Subscriber:
Tearing down a subscriber
- Delete Subscriber:
try {
participant.delete_subscriber(subscriber);
} catch (RETCODE_ERROR err) {
}