SubscriberQos subscriber_qos = new SubscriberQos(); // MySubscriberListener is user defined and // implements SubscriberListener SubscriberListener subscriber_listener = new MySubscriberListener(); // or = null 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) { // respond to exception }
DataReaderSeq reader_seq = new DataReaderSeq(); // list of readers 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) { // handle exception }
for (int i = 0; i < reader_seq.size(); ++i) { FooDataReader reader = (FooDataReader) reader_seq.get(i); // Take the data from reader, // OR // Read the data from reader }
subscriber.notify_datareaders();
subscriber.begin_access();
subscriber.end_access();
try { participant.delete_subscriber(subscriber); } catch (RETCODE_ERROR err) { // handle exception }