7. Lifespan

The Lifespan QoS establishes the maximum validity period of the samples saved on an entity’s history. When the lifespan period elapses, the corresponding sample is automatically removed.

Unlike other QoS, such as Deadline or Liveliness, this test does not provide the means to inform the user that the sample is being removed, which makes this test more complicated to illustrate. For this reason, two publishers and two subscribers will be created, and making only one of them use Lifespan, the effect of using this QoS can be graphically seen.

7.1. Step-by-step example implementation

First, launch an instance and create the two publishers:

  1. Create a red square publisher:

    • Start eProsima Shapes Demo (this instance will be referred to as Instance1).

    • Click on Publish.

    • Select SQUARE option for Shape and RED for Color.

    • Select TRANSIENT_LOCAL option for the Durability.

    • Make sure that RELIABLE checkbox is marked.

    • Set History to 100.

    • Leave the Lifespan Duration to infinite.

  2. Create an orange triangle publisher on the previous Shapes Demo instance:

    • Click on Publish.

    • Select TRIANGLE option for Shape and ORANGE for Color.

    • Select TRANSIENT_LOCAL option for the Durability.

    • Make sure that RELIABLE checkbox is marked.

    • Set History to 100.

    • Set Lifespan Duration to 50.

After that, change the write rate to 1000:

  1. On Instance1:

    • Click on Options.

    • Select Preferences.

    • Set the update interval to 1000.

Initial state

Now, create two subscribers:

  1. Create a square subscriber:

    • Start eProsima Shapes Demo (this instance will be referred to as Instance2).

    • Click on Subscribe.

    • Select SQUARE option for Shape.

    • Select TRANSIENT_LOCAL option for the Durability.

    • Make sure that RELIABLE checkbox is marked.

    • Set History to 100.

    • Leave the Lifespan Duration to infinite.

  2. Create a triangle subscriber:

    • Start eProsima Shapes Demo (this instance will be referred to as Instance3).

    • Click on Subscribe.

    • Select TRIANGLE option for Shape.

    • Select TRANSIENT_LOCAL option for the Durability.

    • Make sure that RELIABLE checkbox is marked.

    • Set History to 100.

    • Set Lifespan Duration to 50.

When a new subscriber matches with the publisher, due to the TRANSIENT_LOCAL durability, all the samples stored on the publisher history are sent automatically to the new subscriber.

Furthermore, on Instance2 and Instance3, the square subscriber history is filled rapidly, while the triangle subscriber is filled at the same speed as the orange triangle publisher sends new samples. This is because in the second case, samples in the orange triangle publisher history were removed by the QoS, and are no longer available to be sent to the subscriber, while the red square publisher history samples were kept.

State 1