Working with subscribers.
More...
Working with subscribers.
Setting up a subscriber
- 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
- Set up to handle the DATA_ON_READERS_STATUS status, in one or both of the following two ways.
Access received data via a subscriber
- 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);
}
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:
- Indicate that data will be accessed via the subscriber:
subscriber.begin_access();
- Indicate that the data access via the subscriber is done:
Tearing down a subscriber
- Delete Subscriber:
try {
participant.delete_subscriber(subscriber);
} catch (RETCODE_ERROR err) {
}