WaitSet Class Reference
[Conditions and WaitSets]

<<interface>> Allows an application to wait until one or more of the attached com.rti.dds.infrastructure.Condition objects has a trigger_value of true or else until the timeout expires. More...

Inherits AbstractNativeObject.

List of all members.

Public Member Functions

 WaitSet ()
 Default no-argument constructor.
 WaitSet (WaitSetProperty_t prop)
 <<eXtension>> Constructor for a com.rti.dds.infrastructure.WaitSet that may delay for more while specifying that will be woken up after the given number of events or delay period, whichever happens first
void wait (ConditionSeq active_conditions, Duration_t timeout)
 Allows an application thread to wait for the occurrence of certain conditions.
void attach_condition (Condition cond)
 Attaches a com.rti.dds.infrastructure.Condition to the com.rti.dds.infrastructure.WaitSet.
void detach_condition (Condition cond)
 Detaches a com.rti.dds.infrastructure.Condition from the com.rti.dds.infrastructure.WaitSet.
void get_conditions (ConditionSeq attached_conditions)
 Retrieves the list of attached com.rti.dds.infrastructure.Condition (s).
void set_property (WaitSetProperty_t prop)
 <<eXtension>> Sets the com.rti.dds.infrastructure.WaitSetProperty_t, to configure the associated com.rti.dds.infrastructure.WaitSet to return after one or more trigger events have occurred.
void get_property (WaitSetProperty_t prop)
 <<eXtension>> Retrieves the com.rti.dds.infrastructure.WaitSetProperty_t configuration of the associated com.rti.dds.infrastructure.WaitSet.
void delete ()
 Destructor.


Detailed Description

<<interface>> Allows an application to wait until one or more of the attached com.rti.dds.infrastructure.Condition objects has a trigger_value of true or else until the timeout expires.

Usage

com.rti.dds.infrastructure.Condition (s) (in conjunction with wait-sets) provide an alternative mechanism to allow the middleware to communicate communication status changes (including arrival of data) to the application.

DDSWaitSetConditions.png

com.rti.dds.infrastructure.WaitSet and com.rti.dds.infrastructure.Condition (s)

This mechanism is wait-based. Its general use pattern is as follows:

Usually the first step is done in an initialization phase, while the others are put in the application main loop.

As there is no extra information passed from the middleware to the application when a wait returns (only the list of triggered com.rti.dds.infrastructure.Condition objects), com.rti.dds.infrastructure.Condition objects are meant to embed all that is needed to react properly when enabled. In particular, com.rti.dds.infrastructure.Entity-related conditions are related to exactly one com.rti.dds.infrastructure.Entity and cannot be shared.

The blocking behavior of the com.rti.dds.infrastructure.WaitSet is illustrated below.

DDSWaitSetBlocking.png

com.rti.dds.infrastructure.WaitSet blocking behavior

The result of a WaitSet.wait operation depends on the state of the com.rti.dds.infrastructure.WaitSet, which in turn depends on whether at least one attached com.rti.dds.infrastructure.Condition has a trigger_value of true. If the wait operation is called on com.rti.dds.infrastructure.WaitSet with state BLOCKED, it will block the calling thread. If wait is called on a com.rti.dds.infrastructure.WaitSet with state UNBLOCKED, it will return immediately. In addition, when the com.rti.dds.infrastructure.WaitSet transitions from BLOCKED to UNBLOCKED it wakes up any threads that had called wait on it.

A key aspect of the com.rti.dds.infrastructure.Condition/com.rti.dds.infrastructure.WaitSet mechanism is the setting of the trigger_value of each com.rti.dds.infrastructure.Condition.

Trigger State of a com.rti.dds.infrastructure.StatusCondition

The trigger_value of a com.rti.dds.infrastructure.StatusCondition is the boolean OR of the ChangedStatusFlag of all the communication statuses (see Status Kinds) to which it is sensitive. That is, trigger_value == false only if all the values of the ChangedStatusFlags are false.

The sensitivity of the com.rti.dds.infrastructure.StatusCondition to a particular communication status is controlled by the list of enabled_statuses set on the condition by means of the com.rti.dds.infrastructure.StatusCondition.set_enabled_statuses operation.

Trigger State of a com.rti.dds.subscription.ReadCondition

Similar to the com.rti.dds.infrastructure.StatusCondition, a com.rti.dds.subscription.ReadCondition also has a trigger_value that determines whether the attached com.rti.dds.infrastructure.WaitSet is BLOCKED or UNBLOCKED. However, unlike the com.rti.dds.infrastructure.StatusCondition, the trigger_value of the com.rti.dds.subscription.ReadCondition is tied to the presence of at least a sample managed by RTI Connext with com.rti.dds.subscription.SampleStateKind and com.rti.dds.subscription.ViewStateKind matching those of the com.rti.dds.subscription.ReadCondition. Furthermore, for the com.rti.dds.subscription.QueryCondition to have a trigger_value == true, the data associated with the sample must be such that the query_expression evaluates to true.

The fact that the trigger_value of a com.rti.dds.subscription.ReadCondition depends on the presence of samples on the associated com.rti.dds.subscription.DataReader implies that a single take operation can potentially change the trigger_value of several com.rti.dds.subscription.ReadCondition or com.rti.dds.subscription.QueryCondition conditions. For example, if all samples are taken, any com.rti.dds.subscription.ReadCondition and com.rti.dds.subscription.QueryCondition conditions associated with the com.rti.dds.subscription.DataReader that had their trigger_value==TRUE before will see the trigger_value change to FALSE. Note that this does not guarantee that com.rti.dds.infrastructure.WaitSet objects that were separately attached to those conditions will not be woken up. Once we have trigger_value==TRUE on a condition, it may wake up the attached com.rti.dds.infrastructure.WaitSet, the condition transitioning to trigger_value==FALSE does not necessarily 'unwakeup' the WaitSet as 'unwakening' may not be possible in general.

The consequence is that an application blocked on a com.rti.dds.infrastructure.WaitSet may return from the wait with a list of conditions, some of which are not no longer 'active'. This is unavoidable if multiple threads are concurrently waiting on separate com.rti.dds.infrastructure.WaitSet objects and taking data associated with the same com.rti.dds.subscription.DataReader entity.

To elaborate further, consider the following example: A com.rti.dds.subscription.ReadCondition that has a sample_state_mask = {SampleStateKind.NOT_READ_SAMPLE_STATE} will have trigger_value of true whenever a new sample arrives and will transition to false as soon as all the newly-arrived samples are either read (so their sample state changes to READ) or taken (so they are no longer managed by RTI Connext). However if the same com.rti.dds.subscription.ReadCondition had a sample_state_mask = { SampleStateKind.READ_SAMPLE_STATE, SampleStateKind.NOT_READ_SAMPLE_STATE }, then the trigger_value would only become false once all the newly-arrived samples are taken (it is not sufficient to read them as that would only change the sample state to READ), which overlaps the mask on the com.rti.dds.subscription.ReadCondition.

Trigger State of a com.rti.dds.infrastructure.GuardCondition

The trigger_value of a com.rti.dds.infrastructure.GuardCondition is completely controlled by the application via the operation com.rti.dds.infrastructure.GuardCondition.set_trigger_value.

Important: The com.rti.dds.infrastructure.WaitSet allocates native resources. When com.rti.dds.infrastructure.WaitSet is no longer being used, user should call WaitSet.delete explicitly to properly cleanup all native resources.

See also:
Status Kinds

com.rti.dds.infrastructure.StatusCondition, com.rti.dds.infrastructure.GuardCondition

com.rti.dds.infrastructure.Listener


Constructor & Destructor Documentation

WaitSet (  ) 

Default no-argument constructor.

Construct a new com.rti.dds.infrastructure.WaitSet.

Important: The com.rti.dds.infrastructure.WaitSet allocates native resources. When the com.rti.dds.infrastructure.WaitSet is no longer being used, users should call WaitSet.delete explicitly to properly clean up all native resources.

Exceptions:
RETCODE_OUT_OF_RESOURCES if a new com.rti.dds.infrastructure.WaitSet could not be allocated.

WaitSet ( WaitSetProperty_t  prop  ) 

<<eXtension>> Constructor for a com.rti.dds.infrastructure.WaitSet that may delay for more while specifying that will be woken up after the given number of events or delay period, whichever happens first

Constructs a new com.rti.dds.infrastructure.WaitSet.

Important: The com.rti.dds.infrastructure.WaitSet allocates native resources. When the com.rti.dds.infrastructure.WaitSet is no longer being used, users should call WaitSet.delete explicitly to properly clean up all native resources.

Parameters:
prop <<in>> Property of wait set controlling when the wait set should be woken up
Exceptions:
RETCODE_OUT_OF_RESOURCES if a new com.rti.dds.infrastructure.WaitSet could not be allocated.


Member Function Documentation

void wait ( ConditionSeq  active_conditions,
Duration_t  timeout 
)

Allows an application thread to wait for the occurrence of certain conditions.

If none of the conditions attached to the com.rti.dds.infrastructure.WaitSet have a trigger_value of true, the wait operation will block suspending the calling thread.

The result of the wait operation is the list of all the attached conditions that have a trigger_value of true (i.e., the conditions that unblocked the wait).

Note: The resolution of the timeout period is constrained by the resolution of the system clock.

The wait operation takes a timeout argument that specifies the maximum duration for the wait. If this duration is exceeded and none of the attached com.rti.dds.infrastructure.Condition objects is true, wait will return with the return code RETCODE_TIMEOUT. In this case, the resulting list of conditions will be empty.

RETCODE_TIMEOUT will not be returned when the timeout duration is exceeded if attached com.rti.dds.infrastructure.Condition objects are true, or in the case of a com.rti.dds.infrastructure.WaitSet waiting for more than one trigger event, if one or more trigger events have occurred.

It is not allowable for for more than one application thread to be waiting on the same com.rti.dds.infrastructure.WaitSet. If the wait operation is invoked on a com.rti.dds.infrastructure.WaitSet that already has a thread blocking on it, the operation will return immediately with the value RETCODE_PRECONDITION_NOT_MET.

Parameters:
active_conditions <<inout>> a valid non-null com.rti.dds.infrastructure.ConditionSeq object. Note that RTI Connext will not allocate a new object if active_conditions is null; the method will return RETCODE_PRECONDITION_NOT_MET.
timeout <<in>> a wait timeout
Exceptions:
One of the Standard Return Codes or RETCODE_PRECONDITION_NOT_MET or RETCODE_TIMEOUT.

void attach_condition ( Condition  cond  ) 

Attaches a com.rti.dds.infrastructure.Condition to the com.rti.dds.infrastructure.WaitSet.

It is possible to attach a com.rti.dds.infrastructure.Condition on a com.rti.dds.infrastructure.WaitSet that is currently being waited upon (via the wait operation). In this case, if the com.rti.dds.infrastructure.Condition has a trigger_value of true, then attaching the condition will unblock the com.rti.dds.infrastructure.WaitSet.

Parameters:
cond <<in>> Contition to be attached.
Exceptions:
One of the Standard Return Codes, or RETCODE_OUT_OF_RESOURCES.

void detach_condition ( Condition  cond  ) 

Detaches a com.rti.dds.infrastructure.Condition from the com.rti.dds.infrastructure.WaitSet.

If the com.rti.dds.infrastructure.Condition was not attached to the com.rti.dds.infrastructure.WaitSet the operation will return RETCODE_BAD_PARAMETER.

Parameters:
cond <<in>> Condition to be detached.
Exceptions:
One of the Standard Return Codes, or RETCODE_PRECONDITION_NOT_MET.

void get_conditions ( ConditionSeq  attached_conditions  ) 

Retrieves the list of attached com.rti.dds.infrastructure.Condition (s).

Parameters:
attached_conditions <<inout>> a com.rti.dds.infrastructure.ConditionSeq object where the list of attached conditions will be returned
Exceptions:
One of the Standard Return Codes, or RETCODE_PRECONDITION_NOT_MET.

void set_property ( WaitSetProperty_t  prop  ) 

<<eXtension>> Sets the com.rti.dds.infrastructure.WaitSetProperty_t, to configure the associated com.rti.dds.infrastructure.WaitSet to return after one or more trigger events have occurred.

Parameters:
prop <<in>>
Exceptions:
One of the Standard Return Codes

void get_property ( WaitSetProperty_t  prop  ) 

<<eXtension>> Retrieves the com.rti.dds.infrastructure.WaitSetProperty_t configuration of the associated com.rti.dds.infrastructure.WaitSet.

Parameters:
prop <<out>>
Exceptions:
One of the Standard Return Codes

void delete (  ) 

Destructor.

Releases the resources asociated with this com.rti.dds.infrastructure.WaitSet.

Calling this method multiple times on the same com.rti.dds.infrastructure.WaitSet is safe; subsequent deletions will have no effect.


RTI Connext Java API Version 4.5f Copyright © 17 Mar 2012 Real-Time Innovations, Inc