![]() |
OpenSplice C# API
v6.x
OpenSplice C# Data Distribution Service Data-Centric Publish-Subscribe API
|
The SampleInfo contains information pertaining to the associated Data value:
For each instance the middleware internally maintains an instance_state. The instance_state can be ALIVE, NOT_ALIVE_DISPOSED, or NOT_ALIVE_NO_WRITERS.
The precise behavior events that cause the instance_state to change depends on the setting of the OWNERSHIP QoS:
The instance_state available in the SampleInfo is a snapshot of the instance_state of the instance at the time the collection was obtained (i.e., at the time read or take was called). The instance_state is therefore the same for all samples in the returned collection that refer to the same instance.
Normally each DataSample contains both a SampleInfo and some Data. However there are situations where a DataSample contains only the SampleInfo and does not have any associated data. This occurs when the Service notifies the application of a change of state for an instance that was caused by some internal mechanism (such as a timeout) for which there is no associated data. An example of this situation is when the Service detects that an instance has no writers and changes the corresponding instance_state to NOT_ALIVE_NO_WRITERS.
The actual set of scenarios under which the middleware returns DataSamples containing no Data is implementation dependent. The application can distinguish whether a particular DataSample has data by examining the value of the valid_data flag. If this flag is set to TRUE, then the DataSample contains valid Data. If the flag is set to FALSE, the DataSample contains no Data.
To ensure correctness and portability, the valid_data flag must be examined by the application prior to accessing the Data associated with the DataSample and if the flag is set to FALSE, the application should not access the Data associated with the DataSample, that is, the application should access only the SampleInfo.
For each instance the middleware internally maintains two counts: the disposed_generation_count and no_writers_generation_count, relative to each DataReader:
The disposed_generation_count and no_writers_generation_count available in the SampleInfo capture a snapshot of the corresponding counters at the time the sample was received.
The sample_rank and generation_rank available in the SampleInfo are computed based solely on the actual samples in the ordered collection returned by read or take.
The generation_rank is computed using the formula:
generation_rank = (MRSIC.disposed_generation_count + MRSIC.no_writers_generation_count) - (S.disposed_generation_count + S.no_writers_generation_count)
The absolute_generation_rank available in the SampleInfo indicates the difference in ‘generations’ between the sample (S) and the Most Recent Sample of the same instance that the middleware has received (MRS). That is, it counts the number of times the instance transitioned from not-alive to alive in the time from the reception of the S to the time when the read or take was called.
absolute_generation_rank = (MRS.disposed_generation_count + MRS.no_writers_generation_count) - (S.disposed_generation_count + S.no_writers_generation_count)
These counters and ranks allow the application to distinguish samples belonging to different ‘generations’ of the instance. Note that it is possible for an instance to transition from not-alive to alive (and back) several times before the application accesses the data by means of read or take. In this case the returned collection may contain samples that cross generations (i.e., some samples were received before the instance became not-alive, others after the instance reappeared again). Using the information in the SampleInfo the application can anticipate what other information regarding the same instance appears in the returned collection, as well as, in the infrastructure and thus make appropriate decisions. For example, an application desiring to only consider the most current sample for each instance would only look at samples with sample_rank==0. Similarly an application desiring to only consider samples that correspond to the latest generation in the collection will only look at samples with generation_rank==0. An application desiring only samples pertaining to the latest generation available will ignore samples for which absolute_generation_rank != 0. Other application-defined criteria may also be used.
For each instance (identified by the key), the middleware internally maintains a view_state relative to each DataReader. The view_state can either be NEW or NOT_NEW.
The view_state available in the SampleInfo is a snapshot of the view_state of the instance relative to the DataReader used to access the samples at the time the collection was obtained (i.e., at the time read or take was called). The view_state is therefore the same for all samples in the returned collection that refer to the same instance.
Once an instance has been detected as not having any “live” writers and all the samples associated with the instance are ‘taken’ from the DataReader, the middleware can reclaim all local resources regarding the instance. Future samples will be treated as ‘never seen’.
The application accesses data by means of the operations read or take on the DataReader. These operations return an ordered collection of DataSamples consisting of a SampleInfo part and a Data part. The way the middleware builds this collection depends on QoS policies set on the DataReader and Subscriber, as well as the source timestamp of the samples, and the parameters passed to the read/take operations, namely:
The read and take operations are non-blocking and just deliver what is currently available that matches the specified states.
The read_w_condition and take_w_condition operations take a ReadCondition object as a parameter instead of sample, view, and instance states. The behavior is that the samples returned will only be those for which the condition is TRUE. These operations, in conjunction with ReadCondition objects and a WaitSet, allow performing waiting reads (see below). Once the data samples are available to the data readers, they can be read or taken by the application. The basic rule is that the application may do this in any order it wishes. This approach is very flexible and allows the application ultimate control. However, the application must use a specific access pattern in case it needs to retrieve samples in the proper order received, or it wants to access a complete set of coherent changes.
To access data coherently, or in order, the PRESENTATION QoS on must be set properly and the application must conform to the access pattern described below. Otherwise, the application will still access the data but will not necessarily see all coherent changes together, nor will it see the changes in the proper order.
There is a general pattern that will provide both ordered and coherent access across multiple DataReaders. This pattern will work for any settings of the PRESENTATION QoS. Simpler patterns may also work for specific settings of the QoS as described below.
1 . General pattern to access samples as a coherent set and/or in order across DataReader entities. This case applies when PRESENTATION QoS specifies “access_scope=GROUP.”
Note that if the PRESENTATION QoS policy specifies ordered_access=TRUE, then the list of DataReaders may return the same reader several times. In this manner the correct sample order can be maintained among samples in different DataReader objects.
2 . Specialized pattern if no order or coherence needs to be maintained across DataReader entities.This case applies if PRESENTATION QoS policy specifies access_scope something other than GROUP.
3 . Specialized pattern if the application accesses the data within the SubscriberListener. This case applies regardless of the PRESENTATION QoS policy when the application accesses the data inside the listener’s implementation of the on_data_on_readers operation.