Foo:
DataReaderQos reader_qos = new DataReaderQos(); // MyReaderListener is user defined and // implements DataReaderListener DataReaderListener reader_listener = new MyReaderListener(); // or = null subscriber.get_default_datareader_qos(reader_qos); FooDataReader reader = null; try { reader = (FooDataReader) subscriber.create_datareader(topic, reader_qos, reader_listener, StatusKind.STATUS_MASK_ALL); } catch (RETCODE_ERROR err) { // respond to exception }
FooDataReader reader = ...;
Foo
Foo data = new Foo(); // user data of type Foo // ... try { reader.get_key_value(data, instance_handle); } catch (RETCODE_ERROR err) { // ... check for cause of failure }
Foo
. The samples are removed from the Service. The caller is responsible for deallocating the buffers. FooSeq data_seq = new FooSeq(); // holder for sequence of user data type Foo SampleInfoSeq info_seq = new SampleInfoSeq(); // holder for sequence of DDS_SampleInfo int max_samples; int sample_state_mask = SampleStateMask.ANY_SAMPLE_STATE; int view_state_mask = ViewStateMask.ANY_VIEW_STATE; int instance_state_mask = InstanceStateMask.ANY_INSTANCE_STATE; try { reader.take(data_seq, info_seq, max_samples, sample_state_mask, view_state_mask, instance_state_mask); } catch (RETCODE_ERROR) { // ... check for cause of failure }
// Use the received data samples 'data_seq' and associated // information 'info_seq' for (int i = 0; i < data_seq.size(); ++i) { // use... data_seq.get(i) ... // use... info_seq.get(i) ... }
reader.return_loan(data_seq, info_seq);
Foo
. The samples are not removed from the Service. It remains responsible for deallocating the buffers. FooSeq data_seq = new FooSeq(); // holder for sequence of user data type Foo SampleInfoSeq info_seq = new SampleInfoSeq)_; // holder for sequence of DDS_SampleInfo int max_samples; int sample_state_mask = SampleStateMask.ANY_SAMPLE_STATE; int view_state_mask = ViewStateMask.ANY_VIEW_STATE; int instance_state_mask = InstanceStateMask.ANY_INSTANCE_STATE; try { reader.read(data_seq, info_seq, max_samples, sample_state_mask, view_state_mask, instance_state_mask); } catch (RETCODE_ERROR) { // ... check for cause of failure }
// Use the received data samples 'data_seq' and associated // information 'info_seq' for (int i = 0; i < data_seq.size(); ++i) { // use... data_seq.get(i) ... // use... info_seq.get(i) ... }
reader.return_loan(data_seq, info_seq);
try { subscriber.delete_datareader(reader); } catch (RETCODE_ERROR err) { // ... check for cause of failure }