Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

Detecting if a service has changed



This article explains how to know if a service content or a Data has changed.

Overview

Several methods allow to detect if a service content or a Data has changed.What is returned is a boolean with the following meaning:
  • For a Data: Has the data value been changed since its previous value before the last invocation/notification of the Service?
  • For a Service: Has at least one Data of this serice been changed since its previous value before the last invocation/notification of the Service?
Note that it is possible to configure when the service or the Data will be considered as changed.

Change behavior

The dataChangeBehavior attribute allows to specify how to detect that complex datas have changed sqince the last notification.

The content of a simple type Data will always be checked to see if the Data has changed. This attribute will specify how complex datas (arrays, structure, or unions) changes are detected:
  • inherit : the service will inherit the value specified in the framework properties
  • changed : the full graph of complex datas will be taken into account to detect if datas have changed after a service invocation
  • unchanged : complex datas will generally be considered as changed be taken into account to detect if datas have changed after a service invocation

Knowing if a Data has changed

The framework indicates if a state value has been modified since the last notification. To know if the value of a data has changed since the last notification, you can use the ServiceInstance.hasChanged(String) method.

Knowing if the content of a Service has changed

To know if the content of a Service has changed since the last notification, you can use the ServiceInstance.hasChanged() method. It means that the value of at least one of the datas of this Service has changed.

Example

Default example

By default the full graph of complex datas will be taken into account to detect if datas have changed after a service invocation. Suppose the following types specification:
      <types>
         <simpleType name="string" baseType="string" />
         <simpleType name="float" baseType="float" />
         <structType name="waypoint">
            <field name="name" type="string" />
            <field name="latitude" type="float" />
            <field name="longitude" type="float" />
         </structType>        
         <arrayType name="waypoints" type="waypoint" />
      </types>
And the service specification:
      <services>
         <publish name="flighplan" >
            <data name="waypoints" type="waypoints" />
         </publish>
      </services>
Each time the flighplan service is notified, it will be considered as changed if the waypoints arrays size has changed, or if one waypoint field has changed:
 public void receive(ServiceInstance service) {
 // hasChanged is true if the  arrays size has changed, or if one  field has changed: 
        boolean hasChanged = service.hasChanged();
      }

Changing the behavior at the framework level

If we change the Configuration file as follows:
      <files>
         <file url="applications.xml" />
         <file url="services.xml" />
         <file url="types.xml" />
         <property key="defaultChangeBehavior" value="unchanged" />
      </files>
Each time the flighplan service is notified, it will be considered as changed only if the waypoints arrays size has changed:
 public void receive(ServiceInstance service) {
 // hasChanged is true only if the  arrays size has changed: 
        boolean hasChanged = service.hasChanged();
      }

Changing the behavior at the service level

If we change back the Configuration file as follows:
      <files>
         <file url="applications.xml" />
         <file url="services.xml" />
         <file url="types.xml" />
      </files>
Now the dataChangeBehavior property has its default value, which means that by default the full graph of complex datas will be taken into account to detect if datas have changed after a service invocation as in the first example.

However if we change the service specification as follows:
      <services>
         <publish name="flighplan" dataChangeBehavior="unchanged">
            <data name="waypoints" type="waypoints" />
         </publish>
      </services>
Each time the flighplan service is notified, it will be considered as changed only if the waypoints arrays size has changed:
 public void receive(ServiceInstance service) {
 // hasChanged is true only if the  arrays size has changed: 
        boolean hasChanged = service.hasChanged();
      }

See also


Categories: concepts | development

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence