6. Listener

The Listener provides a generic mechanism (a callback function) for DDS to notify an application of relevant asynchronous status change events, such as incoming data, a rejected sample or a missed deadline.

The Listener is related to changes in communication status. Each DCPS entity type supports its own specialized listener.

Note

Listeners are currently not supported for the Participant, Publisher and Subscriber entities in the NodeJS DCPS API.

6.1. Attaching a listener to an entity

On entity creation, a listener can be specified. By default the listener is set to null.

A listener is defined using a javascript object. One or more listener properties can be added. For each property, the listener property name and its callback function are defined. Each entity type supports its own listener functionality.

Please see ListenerExample for a runnable code example.

Example: Creating a writer with listener for onPublicationMatched

const writer = participant.createWriter(
  topic,
  null,
  {
    onPublicationMatched: function(entity, status) {
        console.log('== onPublicationMatched listener triggered');
        console.log('    status.totalCount: ', status.totalCount);
        console.log('    status.totalCountChange: ', status.totalCountChange);

        //...
    },
  }
);

Example: Creating a reader with listener with multiple properties

const reader = participant.createReader(
  topic,
  null,
  {
    onSubscriptionMatched: function(entity, status) {
        console.log('== onSubscriptionMatched listener triggered');
        //...
    },
    onDataAvailable: function(entity) {
        console.log('== onDataAvailable listener triggered');
        //...
    },
  }
);

6.2. Listeners

This section outlines the different listener properties supported for each entity type.

For more detailed information, please refer to the Node.js DCPS API documentation, found in:

$OSPL_HOME/docs/nodejs/html

6.2.1. Topic Entity

onInconsistentTopic: function(topic, status)

This function is called when another topic exists with the same name but different characteristics.

6.2.2. Reader Entity

onRequestedDeadlineMissed: function(reader, status)

This function is called when the deadline that the Reader was expecting through its QoS policy was not respected for a specific instance.

onRequestedIncompatibleQos: function(reader, status)

This function is called when a QoS policy requested is incompatible with the offered QoS policy by the Writer entity.

onSampleRejected: function(reader, status)

This function is when a received sample was rejected. This can happen when the ResourceLimits Qos is active and the History determined by History QoS of the Reader entity is full.

onLivelinessChanged: function(reader, status)

This function is called when the liveliness of one or more Writers that were writing instances read through the Reader has changed. Some Writer have become “active” or “inactive.”

onDataAvailable: function(reader)

This function is called when new data is available for this Reader.

onSubscriptionMatched: function(reader, status)

This function is called when the Reader has found a Writer that matches the Topic and has compatible QoS, or has ceased to be matched with a Writer that was previously considered to be matched.

onSampleLost: function(reader, status)

This function is called when a sample has been lost (never received).

6.2.3. Writer Entity

onOfferedDeadlineMissed: function(writer, status)

This function is called when the deadline that the Writer has committed through its Qos policy DEADLINE was not respected for a specific instance.

onOfferedIncompatibleQos: function(writer, status)

This function is called when a Qos policy value was incompatible with what was requested.

onLivelinessLost: function(writer, status)

This function is called when the liveliness that the Writer has committed through its Qos policy LIVELINESS was not respected; thus Reader entities will consider the Writer as no longer “active”.

onPublicationMatched: function(writer, status)

This function is called when the Writer has found a Reader that matches the Topic and has compatible QoS, or has ceased to be matched with a Reader that was previously considered to be matched.

Table Of Contents

Previous topic

5. Node.js API for Vortex DDS

Next topic

7. Quality of Service (QoS)

This Page