TYPE
- The concrete type of the data to be read.public interface DataReader<TYPE> extends DomainEntity<DataReaderListener<TYPE>,DataReaderQos>
Subscriber
.
A DataReader refers to exactly one TopicDescription
(either a
Topic
, a ContentFilteredTopic
, or a MultiTopic
)
that identifies the data to be read. The subscription has a unique
resulting type. The data reader may give access to several instances of
the resulting type, which can be distinguished from each other by their
keys.
All operations except for the inherited operations
Entity.setQos(org.omg.dds.core.EntityQos)
, Entity.getQos()
,
Entity.setListener(java.util.EventListener)
, Entity.getListener()
,
Entity.enable()
, getStatusCondition()
, and Entity.close()
may
fail with the exception NotEnabledException
.
All sample-accessing operations, namely all variants of read()
or
take()
, may fail with the exception
PreconditionNotMetException
.
Access to the Data
Data is made available to the application by the following operations on
DataReader objects: read()
, take()
, and the other methods
beginning with those prefixes.. The general semantics of the "read"
operations is that the application only gets access to the corresponding
data; the data remains the middleware's responsibility and can be read
again. The semantics of the "take" operations is that the application
takes full responsibility for the data; that data will no longer be
accessible to the DataReader. Consequently, it is possible for a
DataReader to access the same sample multiple times but only if all
previous accesses were read operations.
Each of these operations returns an ordered collection of Sample
s
(data values and associated meta-information). Each data value represents
an atom of data information (i.e., a value for one instance). This
collection may contain samples related to the same or different instances
(identified by the key). Multiple samples can refer to the same instance
if the settings of the History
allow for it.Modifier and Type | Interface and Description |
---|---|
static interface |
DataReader.Selector<T>
Selector class encapsulates different ways of selecting samples from a
DataReader . |
Modifier and Type | Method and Description |
---|---|
<OTHER> DataReader<OTHER> |
cast()
Cast this data reader to the given type, or throw an exception if
the cast fails.
|
void |
closeContainedEntities()
This operation closes all the entities that were created by means of
the "create" operations on the DataReader.
|
QueryCondition<TYPE> |
createQueryCondition(String queryExpression,
List<String> queryParameters)
This operation creates a QueryCondition.
|
QueryCondition<TYPE> |
createQueryCondition(Subscriber.DataState states,
String queryExpression,
List<String> queryParameters)
This operation creates a QueryCondition.
|
ReadCondition<TYPE> |
createReadCondition(Subscriber.DataState states)
This operation creates a ReadCondition.
|
TYPE |
getKeyValue(TYPE keyHolder,
InstanceHandle handle)
This operation can be used to retrieve the instance key that
corresponds to an instance handle.
|
LivelinessChangedStatus |
getLivelinessChangedStatus()
This operation allows access to the LIVELINESS_CHANGED communication
status.
|
PublicationBuiltinTopicData |
getMatchedPublicationData(InstanceHandle publicationHandle)
This operation retrieves information on a publication that is
currently "associated" with the DataReader; that is, a publication
with a matching
Topic and compatible QoS that the application
has not indicated should be "ignored" by means of
DomainParticipant.ignorePublication(InstanceHandle) . |
Set<InstanceHandle> |
getMatchedPublications()
This operation retrieves the list of publications currently
"associated" with the DataReader; that is, publications that have a
matching
Topic and compatible QoS that the application has not
indicated should be "ignored" by means of
DomainParticipant.ignorePublication(InstanceHandle) . |
Subscriber |
getParent() |
RequestedDeadlineMissedStatus |
getRequestedDeadlineMissedStatus()
This operation allows access to the REQUESTED_DEADLINE_MISSED
communication status.
|
RequestedIncompatibleQosStatus |
getRequestedIncompatibleQosStatus()
This operation allows access to the REQUESTED_INCOMPATIBLE_QOS
communication status.
|
SampleLostStatus |
getSampleLostStatus()
This operation allows access to the SAMPLE_LOST communication status.
|
SampleRejectedStatus |
getSampleRejectedStatus()
This operation allows access to the SAMPLE_REJECTED communication
status.
|
StatusCondition<DataReader<TYPE>> |
getStatusCondition()
This operation allows access to the
StatusCondition associated
with the Entity. |
SubscriptionMatchedStatus |
getSubscriptionMatchedStatus()
This operation allows access to the SUBSCRIPTION_MATCHED communication
status.
|
TopicDescription<TYPE> |
getTopicDescription() |
ModifiableInstanceHandle |
lookupInstance(ModifiableInstanceHandle handle,
TYPE keyHolder)
This operation takes as a parameter an instance and returns a handle
that can be used in subsequent operations that accept an instance
handle as an argument.
|
InstanceHandle |
lookupInstance(TYPE keyHolder)
This operation takes as a parameter an instance and returns a handle
that can be used in subsequent operations that accept an instance
handle as an argument.
|
Sample.Iterator<TYPE> |
read()
This operation accesses a collection of samples from this DataReader.
|
Sample.Iterator<TYPE> |
read(DataReader.Selector<TYPE> query)
This operation accesses a collection of samples from this DataReader.
|
Sample.Iterator<TYPE> |
read(int maxSamples)
This operation accesses a collection of samples from this DataReader.
|
List<Sample<TYPE>> |
read(List<Sample<TYPE>> samples)
This operation accesses a collection of samples from this DataReader.
|
List<Sample<TYPE>> |
read(List<Sample<TYPE>> samples,
DataReader.Selector<TYPE> selector)
This operation accesses a collection of samples from this DataReader.
|
boolean |
readNextSample(Sample<TYPE> sample)
This operation copies the next, non-previously accessed sample from
this DataReader.
|
DataReader.Selector<TYPE> |
select()
|
Sample.Iterator<TYPE> |
take()
This operation accesses a collection of samples from this DataReader.
|
Sample.Iterator<TYPE> |
take(DataReader.Selector<TYPE> query)
This operation accesses a collection of samples from this DataReader.
|
Sample.Iterator<TYPE> |
take(int maxSamples)
This operation accesses a collection of samples from this DataReader.
|
List<Sample<TYPE>> |
take(List<Sample<TYPE>> samples)
This operation accesses a collection of samples from this DataReader.
|
List<Sample<TYPE>> |
take(List<Sample<TYPE>> samples,
DataReader.Selector<TYPE> query)
This operation accesses a collection of samples from this DataReader.
|
boolean |
takeNextSample(Sample<TYPE> sample)
This operation copies the next, non-previously accessed sample from
this DataReader and "removes" it from the DataReader so it is no
longer accessible.
|
void |
waitForHistoricalData(Duration maxWait)
This operation is intended only for DataReader entities for which
Durability.getKind() is not
Durability.Kind.VOLATILE . |
void |
waitForHistoricalData(long maxWait,
TimeUnit unit)
This operation is intended only for DataReader entities for which
Durability.getKind() is not
Durability.Kind.VOLATILE . |
close, enable, getInstanceHandle, getListener, getQos, getStatusChanges, retain, setListener, setListener, setQos, setQos
getEnvironment
<OTHER> DataReader<OTHER> cast()
OTHER
- The type of the data subscribed to by this reader,
according to the caller.ClassCastException
- if the cast failsReadCondition<TYPE> createReadCondition(Subscriber.DataState states)
states
- The returned condition will only trigger on samples
with one of these sample states, view states, and
instance states.QueryCondition<TYPE> createQueryCondition(String queryExpression, List<String> queryParameters)
queryExpression
- The returned condition will only trigger on
samples that pass this content-based filter expression.queryParameters
- A set of parameter values for the
queryExpression.createQueryCondition(org.omg.dds.sub.Subscriber.DataState, String, List)
QueryCondition<TYPE> createQueryCondition(Subscriber.DataState states, String queryExpression, List<String> queryParameters)
states
- The returned condition will only trigger on samples
with one of these sample states, view states, and instance
states.queryExpression
- The returned condition will only trigger on
samples that pass this content-based filter expression.queryParameters
- A set of parameter values for the
queryExpression.createQueryCondition(String, List)
void closeContainedEntities()
PreconditionNotMetException
- if the any of the contained
entities is in a state where it cannot be closed.TopicDescription<TYPE> getTopicDescription()
SampleRejectedStatus getSampleRejectedStatus()
org.omg.dds.core.status
LivelinessChangedStatus getLivelinessChangedStatus()
org.omg.dds.core.status
RequestedDeadlineMissedStatus getRequestedDeadlineMissedStatus()
org.omg.dds.core.status
RequestedIncompatibleQosStatus getRequestedIncompatibleQosStatus()
org.omg.dds.core.status
SubscriptionMatchedStatus getSubscriptionMatchedStatus()
org.omg.dds.core.status
SampleLostStatus getSampleLostStatus()
org.omg.dds.core.status
void waitForHistoricalData(Duration maxWait) throws TimeoutException
Durability.getKind()
is not
Durability.Kind.VOLATILE
.
As soon as an application enables a non-VOLATILE DataReader it will
start receiving both "historical" data, i.e., the data that was
written prior to the time the DataReader joined the domain, as well as
any new data written by the DataWriter entities. There are situations
where the application logic may require the application to wait until
all "historical" data is received. This is the purpose of this
operation.
The operation blocks the calling thread until either all "historical"
data is received, or else the duration specified by the max_Wait
parameter elapses, whichever happens first.TimeoutException
- if maxWait elapsed before all the
data was received.waitForHistoricalData(long, TimeUnit)
void waitForHistoricalData(long maxWait, TimeUnit unit) throws TimeoutException
Durability.getKind()
is not
Durability.Kind.VOLATILE
.
As soon as an application enables a non-VOLATILE DataReader it will
start receiving both "historical" data, i.e., the data that was
written prior to the time the DataReader joined the domain, as well as
any new data written by the DataWriter entities. There are situations
where the application logic may require the application to wait until
all "historical" data is received. This is the purpose of this
operation.
The operation blocks the calling thread until either all "historical"
data is received, or else the duration specified by the max_Wait
parameter elapses, whichever happens first.TimeoutException
- if maxWait elapsed before all the
data was received.waitForHistoricalData(Duration)
Set<InstanceHandle> getMatchedPublications()
Topic
and compatible QoS that the application has not
indicated should be "ignored" by means of
DomainParticipant.ignorePublication(InstanceHandle)
.
The handles returned in the 'publicationHandles' list are the ones
that are used by the DDS implementation to locally identify the
corresponding matched DataWriter entities. These handles match the
ones that appear in Sample.getInstanceHandle()
when reading
the "DCPSPublications" built-in topic.
The operation may fail if the infrastructure does not locally maintain
the connectivity information.getMatchedPublicationData(InstanceHandle)
PublicationBuiltinTopicData getMatchedPublicationData(InstanceHandle publicationHandle)
Topic
and compatible QoS that the application
has not indicated should be "ignored" by means of
DomainParticipant.ignorePublication(InstanceHandle)
.
The operation getMatchedPublications()
can be used
to find the publications that are currently matched with the
DataReader.publicationHandle
- a handle to the publication, the
data of which is to be retrieved.IllegalArgumentException
- if the publicationHandle does
not correspond to a publication currently associated with the
DataReader.UnsupportedOperationException
- if the infrastructure does
not hold the information necessary to fill in the
publicationData.getMatchedPublications()
Sample.Iterator<TYPE> read()
read(Selector)
except that the
collection of returned samples is not constrained by any Selector.read(Selector)
,
read(List)
,
read(List, Selector)
,
readNextSample(Sample)
,
take()
Sample.Iterator<TYPE> read(DataReader.Selector<TYPE> query)
DataReader.Selector
. The
setting of the Presentation
may impose further limits on the returned samples.
Presentation.getAccessScope()
is
Presentation.AccessScopeKind.INSTANCE
,
then samples belonging to the same data instance are consecutive.
Presentation.getAccessScope()
is
Presentation.AccessScopeKind.TOPIC
and
Presentation.isOrderedAccess()
is set to false, then samples belonging to the same data
instance are consecutive.Presentation.getAccessScope()
is
Presentation.AccessScopeKind.TOPIC
and
Presentation.isOrderedAccess()
is set to true, then samples belonging to the same instance
may or may not be consecutive. This is because to preserve
order it may be necessary to mix samples from different
instances.Presentation.getAccessScope()
is
Presentation.AccessScopeKind.GROUP
and
Presentation.isOrderedAccess()
is set to false, then samples belonging to the same data
instance are consecutive.Presentation.getAccessScope()
is
Presentation.AccessScopeKind.GROUP
and
Presentation.isOrderedAccess()
is set to true, then the returned collection contains at most
one sample. The difference in this case is due to the fact
that it is required that the application is able to read
samples belonging to different DataReader objects in a
specific order.
DestinationOrder
:
DestinationOrder.getKind()
is
DestinationOrder.Kind.BY_RECEPTION_TIMESTAMP
,
samples belonging to the same instances will appear in the
relative order in which they were received (FIFO, earlier
samples ahead of the later samples).DestinationOrder.getKind()
is
DestinationOrder.Kind.BY_SOURCE_TIMESTAMP
,
samples belonging to the same instances will appear in the
relative order implied by the result of
Sample.getSourceTimestamp()
(FIFO, smaller values of
the source time stamp ahead of the larger values).Sample
.
The returned samples are "loaned" by the DataReader. The use of this
variant allows for zero-copy (assuming the implementation supports it)
access to the data and the application will need to "return the loan"
to the DataReader using the Sample.Iterator.close()
operation.
Some elements in the returned collection may not have valid data. If
the instance state in the Sample is
InstanceState.NOT_ALIVE_DISPOSED
or
InstanceState.NOT_ALIVE_NO_WRITERS
, then the last sample for
that instance in the collection, that is, the one with
Sample.getSampleRank()
== 0, does not contain valid data.
Samples that contain no data do not count towards the limits imposed
by the ResourceLimits
.
The act of reading a sample sets its sample state to
SampleState.READ
. If the sample belongs to the most recent
generation of the instance, it will also set the view state of the
instance to ViewState.NOT_NEW
. It will not affect the
instance state of the instance.
If the DataReader has no samples that meet the constraints, the
return value will be a non-null iterator that provides no samples.read()
,
read(List)
,
read(List, Selector)
,
readNextSample(Sample)
,
take(Selector)
Sample.Iterator<TYPE> read(int maxSamples)
read()
except that the returned
samples are no more than #maxSamples.read()
,
read(Selector)
,
read(List, Selector)
,
readNextSample(Sample)
,
take(List)
List<Sample<TYPE>> read(List<Sample<TYPE>> samples)
read()
except that the returned
samples are not "on loan" from the Service; they are deeply copied to
the application.
If the number of samples read are fewer than the current
length of the list, the list will be trimmed to fit the
samples read. If list is null, a new list will be allocated
and its size may be zero or unbounded depending upon the
number of samples read. If there are no samples, the list
reference will be non-null and the list will contain zero
samples.
The read operation will copy the data and meta-information into the
elements already inside the given collection, overwriting any samples
that might already be present. The use of this variant forces a copy
but the application can control where the copy is placed and the
application will not need to "return the loan."samples
, for convenience.read()
,
read(Selector)
,
read(List, Selector)
,
readNextSample(Sample)
,
take(List)
List<Sample<TYPE>> read(List<Sample<TYPE>> samples, DataReader.Selector<TYPE> selector)
read(Selector)
except that the returned
samples are not "on loan" from the Service; they are deeply copied to
the application.
The number of samples are specified as the minimum of
DataReader.Selector.getMaxSamples()
and the length of the list.
If the number of samples read are fewer than the current
length of the list, the list will be trimmed to fit the
samples read. If list is null, a new list will be allocated
and its size may be zero or unbounded depending upon the
number of samples read. If there are no samples, the list
reference will be non-null and the list will contain zero
samples.
The read operation will copy the data and meta-information into the
elements already inside the given collection, overwriting any samples
that might already be present. The use of this variant forces a copy
but the application can control where the copy is placed and the
application will not need to "return the loan."samples
, for convenience.read()
,
read(Selector)
,
read(List)
,
readNextSample(Sample)
,
take(List, Selector)
Sample.Iterator<TYPE> take()
take(Selector)
except that the
collection of returned samples is not constrained by any Selector.take(Selector)
,
take(List)
,
take(List, Selector)
,
takeNextSample(Sample)
,
read()
Sample.Iterator<TYPE> take(int maxSamples)
take(Selector)
except that the
collection of returned samples is not constrained by any Selector.
The number of samples accessible via the iterator will not be
more than #maxSamples.take(Selector)
,
take(List)
,
take(List, Selector)
,
takeNextSample(Sample)
,
read()
Sample.Iterator<TYPE> take(DataReader.Selector<TYPE> query)
Presentation
and other
factors using the same logic as for read(Selector)
.
The act of taking a sample removes it from the DataReader so it cannot
be "read" or "taken" again. If the sample belongs to the most recent
generation of the instance, it will also set the view state of the
instance to ViewState.NOT_NEW
. It will not affect the
instance state of the instance.
The behavior of the take operation follows the same rules than the
read operation regarding the preconditions and postconditions for the
arguments and return results. Similar to read, the take operation will
"loan" elements to the application; this loan must then be returned by
means of Sample.Iterator.close()
. The only difference
with read is that, as stated, the sample returned by take will no
longer be accessible to successive calls to read or take.
If the DataReader has no samples that meet the constraints, the
return value will be a non-null iterator that provides no samples.take()
,
take(List)
,
take(List, Selector)
,
takeNextSample(Sample)
,
read(Selector)
List<Sample<TYPE>> take(List<Sample<TYPE>> samples)
take()
except that the returned
samples are not "on loan" from the Service; they are deeply copied to
the application.
The take operation will copy the data and meta-information into the
elements already inside the given collection, overwriting any samples
that might already be present. The use of this variant forces a copy
but the application can control where the copy is placed and the
application will not need to "return the loan."samples
, for convenience.take()
,
take(Selector)
,
take(List, Selector)
,
takeNextSample(Sample)
,
read(List)
List<Sample<TYPE>> take(List<Sample<TYPE>> samples, DataReader.Selector<TYPE> query)
take(Selector)
except that the returned
samples are not "on loan" from the Service; they are deeply copied to
the application.
The take operation will copy the data and meta-information into the
elements already inside the given collection, overwriting any samples
that might already be present. The use of this variant forces a copy
but the application can control where the copy is placed and the
application will not need to "return the loan."samples
, for convenience.take()
,
take(Selector)
,
take(List)
,
takeNextSample(Sample)
,
read(List, Selector)
boolean readNextSample(Sample<TYPE> sample)
read(List, Selector)
.
This operation is semantically equivalent to
read(List, Selector)
where DataReader.Selector.getMaxSamples()
is 1, DataReader.Selector.getDataState()
followed by
Subscriber.DataState.getSampleStates()
==
SampleState.NOT_READ
, DataReader.Selector.getDataState()
followed by
Subscriber.DataState.getViewStates()
contains all view
states, and DataReader.Selector.getDataState()
followed by
Subscriber.DataState.getInstanceStates()
contains all
instance states.
This operation provides a simplified API to "read" samples avoiding
the need for the application to manage iterators and specify queries.
If there is no unread data in the DataReader, the operation will
return false and the provided sample is not modified.read()
,
read(Selector)
,
read(List)
,
read(List, Selector)
,
takeNextSample(Sample)
boolean takeNextSample(Sample<TYPE> sample)
readNextSample(Sample)
except for the fact that the sample is
"removed" from the DataReader.
This operation is semantically equivalent to
take(List, Selector)
where DataReader.Selector.getMaxSamples()
is 1, DataReader.Selector.getDataState()
followed by
Subscriber.DataState.getSampleStates()
==
SampleState.NOT_READ
, DataReader.Selector.getDataState()
followed by
Subscriber.DataState.getViewStates()
contains all view
states, and DataReader.Selector.getDataState()
followed by
Subscriber.DataState.getInstanceStates()
contains all
instance states.
This operation provides a simplified API to "take" samples avoiding
the need for the application to manage iterators and specify queries.
If there is no unread data in the DataReader, the operation will
return false and the provided sample is not modified.take()
,
take(Selector)
,
take(List)
,
take(List, Selector)
,
readNextSample(Sample)
TYPE getKeyValue(TYPE keyHolder, InstanceHandle handle)
keyHolder
- a container, into which this method shall
place its result.handle
- a handle indicating the instance whose value
this method should get.IllegalArgumentException
- if the InstanceHandle
does not correspond to an existing data object known to the
DataReader. If the implementation is not able to check
invalid handles, then the result in this situation is
unspecified.ModifiableInstanceHandle lookupInstance(ModifiableInstanceHandle handle, TYPE keyHolder)
handle
- a container, into which this method shall place its
result.keyHolder
- a sample of the instance whose handle this
method should look up.lookupInstance(Object)
InstanceHandle lookupInstance(TYPE keyHolder)
keyHolder
- a sample of the instance whose handle this
method should look up.lookupInstance(ModifiableInstanceHandle, Object)
StatusCondition<DataReader<TYPE>> getStatusCondition()
Entity
StatusCondition
associated
with the Entity. The returned condition can then be added to a
WaitSet
so that the application can wait for specific status
changes that affect the Entity.getStatusCondition
in interface Entity<DataReaderListener<TYPE>,DataReaderQos>
Subscriber getParent()
getParent
in interface DomainEntity<DataReaderListener<TYPE>,DataReaderQos>
DataReader.Selector<TYPE> select()
DataReader.Selector
object returned by this method
is the default selector. By default it selects
ResourceLimits.LENGTH_UNLIMITED
samples. This is equivalent to calling read()
without
any parameters.Copyright © 2014. All rights reserved.