Interface MessageObserver


public interface MessageObserver
Interface for objects that needs to be notified when new encoded messages are available.
Since:
11.0
Author:
Luc Maisonobe
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    messageAvailable(String mountPoint, ParsedMessage message)
    Notify that an encoded message is available.
  • Method Details

    • messageAvailable

      void messageAvailable(String mountPoint, ParsedMessage message)
      Notify that an encoded message is available.

      Beware that this method will be called from an internal dedicated stream-reading thread. Implementations must take to:

      • not perform long processing there to avoid blocking the stream-reading thread
      • take care of thread-safety when extracting data from the message

      The only filtering that can be specified when adding an observer to a NtripClient is based on message type and mount point. If additional filtering is needed (for example on message content like satellites ids, it must be performed by the observer itself when notified (see example below).

      The recommended way to implement this method is to simply build a domain object from the message fields (for example a gnss propagator) and to store it in the observer class as an instance field using a AtomicReference as follows:

       public class GPSProvider implements PVCoordinatesProvider, RTCMMessageObserver {
      
           private final int                                filteringId;
           private final AtomicReference<GPSPropagator> propagator;
      
           public void messageAvailable(String mountPoint, ParsedMessage message) {
               MessageXXX msg = (MessageXXX) message;
               GPSPropagator oldPropagator = propagator.get();
               if (msg.getSatId() == filteringId) {
                   GPSPropagator newPropagator = new GPSPropagator(msg.get...(),
                                                                   msg.get...(),
                                                                   msg.get...());
                   // only set propagator if no other observer was notified
                   // while we were asleep
                   propagator.compareAndSet(oldPropagator, newPropagator);
               }
           }
      
           public TimeStampedPVCoordinates getPVCoordinates(AbsoluteDate date, Frame frame) {
               GPSPropagator lastAvailablePropagator = propagator.get();
               // use the retrieved propagator to compute position-velocity
           }
      
       }
       
      Parameters:
      mountPoint - mount point from which the message comes
      message - last available message