OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
org.omg.dds.sub.DataReader< TYPE >.Selector< T > Interface Template Reference

Selector class encapsulates different ways of selecting samples from a org.omg.dds.sub.DataReader. More...

Inheritance diagram for org.omg.dds.sub.DataReader< TYPE >.Selector< T >:
Inheritance graph
Collaboration diagram for org.omg.dds.sub.DataReader< TYPE >.Selector< T >:
Collaboration graph

Public Member Functions

Selector< T > Content (String queryExpression, List< String > queryParameters)
 Set the Content to filter with during the read or take. More...
 
Selector< T > Content (String queryExpression, String... queryParameters)
 Set the Content to filter with during the read or take. More...
 
Selector< T > dataState (Subscriber.DataState state)
 Set DataState to filter with during the read or take. More...
 
ReadCondition< T > getCondition ()
 Returns the ReadCondition of the selector. More...
 
Subscriber.DataState getDataState ()
 Returns the dataState of the selector. More...
 
ServiceEnvironment getEnvironment ()
 
InstanceHandle getInstance ()
 Returns the current instance the selector is working on. More...
 
int getMaxSamples ()
 Returns the maximum number of samples of the selector. More...
 
String getQueryExpression ()
 Returns the query expression of the selector. More...
 
List< String > getQueryParameters ()
 Returns a collection of the query parameters of the selector. More...
 
Selector< T > instance (InstanceHandle handle)
 Set InstanceHandle to filter with during the read or take. More...
 
Selector< T > maxSamples (int max)
 Set maxSamples to limit the number of sample to get during the read or take. More...
 
Selector< T > nextInstance (boolean retrieveNextInstance)
 Set next InstanceHandle to filter with during the read or take. More...
 
Sample.Iterator< T > read ()
 This operation works the same as the DataReader#read(), except that it is performed on this Selector with possible filters set. More...
 
List< Sample< T > > read (List< Sample< T >> samples)
 This operation works the same as the DataReader#read(List), except that it is performed on this Selector with possible filters set. More...
 
boolean retrieveNextInstance ()
 Returns if the selector should use the next instance or not. More...
 
Sample.Iterator< T > take ()
 This operation works the same as the DataReader#take(), except that it is performed on this Selector with possible filters set. More...
 
List< Sample< T > > take (List< Sample< T >> samples)
 This operation works the same as the DataReader#take(List), except that it is performed on this Selector with possible filters set. More...
 

Detailed Description

Selector class encapsulates different ways of selecting samples from a org.omg.dds.sub.DataReader.

Selector can be used with org.omg.dds.sub.DataReader#read(Selector) and org.omg.dds.sub.DataReader#take(Selector) or it can be used stand-alone as it provides read and take functions.

org.omg.dds.sub.DataReader#select creates a Selector that is bound to the org.omg.dds.sub.DataReader.

A Selector may encapsulate any combination of org.omg.dds.core.InstanceHandle, Subscriber.DataState, a query filter. It can be used to bound the maximum number of samples retrieved.

The DataReader has the select() operation, which can be used to acquire the Selector functionality on the reader implicitly.

 
 // Take a maximum of 3 new samples of a certain instance.
 samples = reader.select()
                     .maxSamples(3)
                     .dataState(subscriber.createDataState().withAnyInstanceState().withAnySampleState().withAnyViewState())
                     .instance(someValidInstanceHandle)
                     .take();
 
 

However, this will create and destroy a Selector for every read/take, which is not very performance friendly.

The performance can be increase by creating a Selector up front and doing the reading on that Selector directly and re-using it.

 
 // Create a Selector as selective reader up front.
 Selector<Foo> selector = reader.select();
 // Configure it to take a maximum of 3 new samples of a certain instance
 selector.maxSamples(3);
 selector.dataState(subscriber.createDataState().withAnyInstanceState().withAnySampleState().withAnyViewState());
 selector.instance(someValidInstanceHandle);
 // Use the configured Selector to -take- a maximum of 3 new samples of a
 // certain instance (which it was configured to do).
 // This can be used in loops for example, reducing the need for creating
 // implicit Selectors for every take.
 samples = selector.take();
 
 
 Defaults
 Element         | Default Value
 --------------- | ----------------
 dataState       | Any
 condition       | null
 maxSamples      | LENGTH_UNLIMITED
 instance        | nilHandle
 nextInstance    | false
 
Parameters
<T>The concrete type of the data to be read.

Definition at line 1511 of file DataReader.java.

Member Function Documentation

◆ Content() [1/2]

Selector<T> org.omg.dds.sub.DataReader< TYPE >.Selector< T >.Content ( String  queryExpression,
List< String >  queryParameters 
)

Set the Content to filter with during the read or take.

Example
Read only samples that will be filtered according to the given queryExpression and queryParameters.


// Assume data type has an element called long_1
queryExpression = "long_1 &gt; %0 and long_1 &lt; %1";
List<String> queryParameters = new ArrayList<String>();
queryParameters.add("1");
queryParameters.add("7");
// Implicit use of Selector
samples = reader.select().Content(queryExpression,queryParameters).read();
// Explicit use of Selector
Selector<Foo> selector = reader.select();
selector.Content(queryExpression,queryParameters);
samples = selector.read();

Parameters
queryExpressionThe returned condition will only trigger on samples that pass this content-based filter expression.
queryParametersA collection of parameter values for the queryExpression.
Returns
a Selector to be able to concatenate Selector settings.

◆ Content() [2/2]

Selector<T> org.omg.dds.sub.DataReader< TYPE >.Selector< T >.Content ( String  queryExpression,
String...  queryParameters 
)

Set the Content to filter with during the read or take.

Example
Read only samples that will be filtered according to the given queryExpression and queryParameters.


// Assume data type has an element called long_1
queryExpression = "long_1 &gt; %0 and long_1 &lt; %1";
// Implicit use of Selector
samples = reader.select().Content(queryExpression,"1","7").read();
// Explicit use of Selector
Selector<Foo> selector = reader.select();
selector.Content(queryExpression,"1","7");
samples = selector.read();

Parameters
queryExpressionThe returned condition will only trigger on samples that pass this content-based filter expression.
queryParametersA set of parameter values for the queryExpression.
Returns
a Selector to be able to concatenate Selector settings.

◆ dataState()

Selector<T> org.omg.dds.sub.DataReader< TYPE >.Selector< T >.dataState ( Subscriber.DataState  state)

Set DataState to filter with during the read or take.

Example
Read only new data.


// DataState to filter only new data
DataState newData = subscriber.createDataState().withAnyInstanceState().withAnySampleState().with(ViewState.NEW);
// Implicit use of Selector
samples = reader.select().dataState(newData).read();
// Explicit use of Selector
Selector<Foo> selector = reader.select();
selector.dataState(newData);
samples = selector.read();

Parameters
statethe requested DataState of the samples
Returns
a Selector to be able to concatenate Selector settings.

◆ getCondition()

ReadCondition<T> org.omg.dds.sub.DataReader< TYPE >.Selector< T >.getCondition ( )

Returns the ReadCondition of the selector.

Returns
the ReadCondition

◆ getDataState()

Subscriber.DataState org.omg.dds.sub.DataReader< TYPE >.Selector< T >.getDataState ( )

Returns the dataState of the selector.

Returns
the dataState

◆ getEnvironment()

ServiceEnvironment org.omg.dds.core.DDSObject.getEnvironment ( )
inherited
Returns
the org.omg.dds.core.ServiceEnvironment object that directly or indirectly was used to create this object.

Implemented in org.omg.dds.core.ServiceEnvironment, org.opensplice.dds.sub.ReflectionDataReader< TYPE, OUT_TYPE >, org.opensplice.dds.core.ModifiableTimeImpl, org.opensplice.dds.pub.ReflectionDataWriter< TYPE >, org.opensplice.dds.core.DurationImpl, org.opensplice.dds.topic.ContentFilteredTopicImpl< TYPE >, org.opensplice.dds.sub.ReadConditionImpl< TYPE >, org.opensplice.dds.core.EntityQosImpl< T extends QosPolicy >, org.opensplice.dds.type.TypeSupportImpl< TYPE >, org.opensplice.dds.topic.PublicationBuiltinTopicDataImpl, org.opensplice.dds.topic.SubscriptionBuiltinTopicDataImpl, org.opensplice.dds.topic.TopicBuiltinTopicDataImpl, org.opensplice.dds.domain.DomainParticipantFactoryImpl, org.opensplice.dds.core.QosProviderImpl, org.opensplice.dds.core.status.OfferedIncompatibleQosStatusImpl, org.opensplice.dds.core.status.RequestedIncompatibleQosStatusImpl, org.opensplice.dds.core.InstanceHandleImpl, org.opensplice.dds.core.StatusConditionImpl< T extends Entity<?, ?>, org.opensplice.dds.core.status.LivelinessChangedStatusImpl, org.opensplice.dds.core.status.PublicationMatchedStatusImpl, org.opensplice.dds.core.status.SubscriptionMatchedStatusImpl, org.opensplice.dds.sub.SampleImpl< TYPE >, org.opensplice.dds.core.policy.ShareImpl, org.opensplice.dds.core.status.OfferedDeadlineMissedStatusImpl, org.opensplice.dds.core.status.SampleRejectedStatusImpl, org.opensplice.dds.core.WaitSetImpl, org.opensplice.dds.topic.ParticipantBuiltinTopicDataImpl, org.opensplice.dds.core.status.RequestedDeadlineMissedStatusImpl, org.opensplice.dds.topic.BuiltinTopicKeyImpl, org.opensplice.dds.core.GuardConditionImpl, org.opensplice.dds.core.event.AllDataDisposedEventImpl< TYPE >, org.opensplice.dds.core.policy.QosPolicyCountImpl, org.opensplice.dds.core.status.InconsistentTopicStatusImpl, org.opensplice.dds.core.status.LivelinessLostStatusImpl, org.opensplice.dds.core.status.SampleLostStatusImpl, org.opensplice.dds.core.policy.QosPolicyImpl, org.opensplice.dds.core.status.AllDataDisposedStatusImpl, org.opensplice.dds.core.IllegalArgumentExceptionImpl, org.opensplice.dds.core.InconsistentPolicyExceptionImpl, org.opensplice.dds.core.policy.PolicyFactoryImpl, org.opensplice.dds.core.policy.TypeConsistencyEnforcementImpl, org.opensplice.dds.core.PreconditionNotMetExceptionImpl, org.opensplice.dds.core.AlreadyClosedExceptionImpl, org.opensplice.dds.core.IllegalOperationExceptionImpl, org.opensplice.dds.core.ImmutablePolicyExceptionImpl, org.opensplice.dds.core.NotEnabledExceptionImpl, org.opensplice.dds.core.OutOfResourcesExceptionImpl, org.opensplice.dds.core.DDSExceptionImpl, org.opensplice.dds.core.status.DataAvailableStatusImpl, and org.opensplice.dds.core.status.DataOnReadersStatusImpl.

◆ getInstance()

InstanceHandle org.omg.dds.sub.DataReader< TYPE >.Selector< T >.getInstance ( )

Returns the current instance the selector is working on.

Returns
the current instance

◆ getMaxSamples()

int org.omg.dds.sub.DataReader< TYPE >.Selector< T >.getMaxSamples ( )

Returns the maximum number of samples of the selector.

Returns
the maximum number of samples

◆ getQueryExpression()

String org.omg.dds.sub.DataReader< TYPE >.Selector< T >.getQueryExpression ( )

Returns the query expression of the selector.

Returns
the query expression

◆ getQueryParameters()

List<String> org.omg.dds.sub.DataReader< TYPE >.Selector< T >.getQueryParameters ( )

Returns a collection of the query parameters of the selector.

Returns
a collection of the query parameters

◆ instance()

Selector<T> org.omg.dds.sub.DataReader< TYPE >.Selector< T >.instance ( InstanceHandle  handle)

Set InstanceHandle to filter with during the read or take.

Example


// Read only samples of the given instance.
InstanceHandle hdl = someValidInstanceHandle;
// Implicit use of Selector
samples = reader.select().instance(hdl).read();
// Explicit use of Selector
Selector<Foo> selector = reader.select();
samples = selector.instance(hdl).read();

Parameters
handlethe InstanceHandle to read/take for
Returns
a Selector to be able to concatenate Selector settings.

◆ maxSamples()

Selector<T> org.omg.dds.sub.DataReader< TYPE >.Selector< T >.maxSamples ( int  max)

Set maxSamples to limit the number of sample to get during the read or take.

Example
Read a maximum of three samples.


// Implicit use of Selector
samples = reader.select().maxSamples(3).read();
// Explicit use of Selector
Selector<Foo> selector = reader.select();
selector.maxSamples(3);
samples = selector.read();

Parameters
maxmaximum number of samples to read/take
Returns
a Selector to be able to concatenate Selector settings.

◆ nextInstance()

Selector<T> org.omg.dds.sub.DataReader< TYPE >.Selector< T >.nextInstance ( boolean  retrieveNextInstance)

Set next InstanceHandle to filter with during the read or take.

Example


// Read all samples, instance by instance by an implicit use of Selector
{
    // Get sample(s) of first instance
    samples = reader.select().nextInstance(true).read();
    while (samples.hasNext()) {
        // Handle the sample(s) of this instance (just the first one in this case)
        Sample sample = samples.next();
        samples = reader.select().instance(sample.getInstanceHandle()).nextInstance(true).read();
    }
}
-------------------------------------------------------------------------------------------------
// Read all samples, instance by instance by an explicit use of Selector
{
    // Get sample(s) of first instance
    Selector<Foo> selector = reader.select();
    selector.nextInstance(true);
    samples = selector.read();
    while (samples.hasNext()) {
        // Handle the sample(s) of this instance (just the first one in this case)
        Sample sample = samples.next();
        // because we use the same selector we don't need to set the nextInstance flag again.
        samples = selector.instance(sample.getInstanceHandle()).read();
    }
}

Parameters
retrieveNextInstancethis boolean indicates if we want to read/take the next instance or not.
Returns
a Selector to be able to concatenate Selector settings.

◆ read() [1/2]

Sample.Iterator<T> org.omg.dds.sub.DataReader< TYPE >.Selector< T >.read ( )

This operation works the same as the DataReader#read(), except that it is performed on this Selector with possible filters set.

Returns
A samples iterator
Exceptions
org.omg.dds.core.DDSExceptionAn internal error has occurred.
org.omg.dds.core.AlreadyClosedExceptionThe corresponding DataWriter has been closed.
org.omg.dds.core.OutOfResourcesExceptionThe Data Distribution Service ran out of resources to complete this operation.

◆ read() [2/2]

List<Sample<T> > org.omg.dds.sub.DataReader< TYPE >.Selector< T >.read ( List< Sample< T >>  samples)

This operation works the same as the DataReader#read(List), except that it is performed on this Selector with possible filters set.

Parameters
samplesThe collection where the results of the read are stored in
Returns
A samples collection
Exceptions
org.omg.dds.core.DDSExceptionAn internal error has occurred.
org.omg.dds.core.AlreadyClosedExceptionThe corresponding DataWriter has been closed.
org.omg.dds.core.OutOfResourcesExceptionThe Data Distribution Service ran out of resources to complete this operation.

◆ retrieveNextInstance()

boolean org.omg.dds.sub.DataReader< TYPE >.Selector< T >.retrieveNextInstance ( )

Returns if the selector should use the next instance or not.

Returns
the retrieveNextInstance value

◆ take() [1/2]

Sample.Iterator<T> org.omg.dds.sub.DataReader< TYPE >.Selector< T >.take ( )

This operation works the same as the DataReader#take(), except that it is performed on this Selector with possible filters set.

Returns
A samples iterator
Exceptions
org.omg.dds.core.DDSExceptionAn internal error has occurred.
org.omg.dds.core.AlreadyClosedExceptionThe corresponding DataWriter has been closed.
org.omg.dds.core.OutOfResourcesExceptionThe Data Distribution Service ran out of resources to complete this operation.

◆ take() [2/2]

List<Sample<T> > org.omg.dds.sub.DataReader< TYPE >.Selector< T >.take ( List< Sample< T >>  samples)

This operation works the same as the DataReader#take(List), except that it is performed on this Selector with possible filters set.

Parameters
samplesThe collection where the results of the take are stored in
Returns
A samples collection
Exceptions
org.omg.dds.core.DDSExceptionAn internal error has occurred.
org.omg.dds.core.AlreadyClosedExceptionThe corresponding DataWriter has been closed.
org.omg.dds.core.OutOfResourcesExceptionThe Data Distribution Service ran out of resources to complete this operation.

The documentation for this interface was generated from the following file: