How can I get a notification when my DataReader receives a ‘dispose’ sample with identity

4 posts / 0 new
Last post
rohitrx4's picture
Offline
Last seen: 5 years 1 month ago
Joined: 02/15/2019
Posts: 10
How can I get a notification when my DataReader receives a ‘dispose’ sample with identity

Scenario:

I have UI application hosted on the remote machine. Server publishes data and UI Application(Remote) subscribe it continuously and populate data on UI.
If the server added a new record and published new data this data get subscribe through the UI application and populate on UI.

But I am facing problem with dispose data.  
If server delete sample DataReader:on_data_avilable get invoked but I can’t able to identify which sample is getting deleted. This sample I need to remove from UI.   



      @Override

        public void on_data_available(DataReader reader) {

            try {

                reader.take_untyped(

                    _dataSeq, _infoSeq,

                    ResourceLimitsQosPolicy.LENGTH_UNLIMITED,

                    SampleStateKind.ANY_SAMPLE_STATE,

                    ViewStateKind.ANY_VIEW_STATE,

                    InstanceStateKind.ANY_INSTANCE_STATE);

 

                for(int i = 0; i < _dataSeq.size(); ++i) {

                    SampleInfo info = (SampleInfo)_infoSeq.get(i);

                    //info.valid_data == true for new sample and false for dispose sample

                    if (info.valid_data) {

                        if(messageProcessor != null) {

                           messageProcessor.processMessage((_dataSeq.get(i)));

                        }

                    }

                }

            } catch (RETCODE_NO_DATA noData) {

                // No data to process

            } finally {

                reader.return_loan_untyped(_dataSeq, _infoSeq);

            }

        }

    

fercs77's picture
Offline
Last seen: 2 months 1 week ago
Joined: 01/15/2011
Posts: 30

Hi,

You should be able to call the DataReader::get_key_value to get the key value of the instance that has been disposed. This method receives as a parameter the instance_handle in SampleInfo.

Best Regards,

- Fernando

Offline
Last seen: 4 years 1 month ago
Joined: 08/20/2012
Posts: 25

It’s actually not the *sample* that’s being disposed, but rather the instance it belongs to, as defined by the values of the “@key” fields in your data type. The SampleInfo has an instance_handle field. The DataReader can populate a sample with the corresponding key field values given the instance handle using the get_key_value() method. Your application can then inspect the key fields for the instance that was disposed.

Regards,

Tom

rohitrx4's picture
Offline
Last seen: 5 years 1 month ago
Joined: 02/15/2019
Posts: 10

Thanks Fernando and Tom,

I am able to fetch data using get_key_value(). I really appreciate your help.
Thanks once again.



Regards,
Rohit K.