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

Groovy modules



Groovy modules are modules which are scripted in the Groovy scripting language. Note that Groovy modules can have the same syntax as the Java language.

Deployment

These modules do not need a deployment in their parent application because they are scripted.

Declaration

These modules are declared by the top-level groovyModule element. For example:
      <groovyModule name="FlightManagementSystem" id="1" >

Groovy module implementation

The groovyImplementation element declares the groovy script file which implements the script. For example:

      <groovyModule name="FlightManagementSystem" id="1" >
         <groovyImplementation path="fms.groovy" />
      </groovyModule>
The path attribute refer to the file which implements the groovy script. The path of this file is by default relative to the application.xml file which declares the module.

Groovy script

The Groovy scripts have the following default (and empty) methods:
  • init: called once after the framework has been initialized
  • start: called when the module is started
  • end: called when the module is shutdown
  • subscribe: called when the module is notified from a Service invocation
      public default void init(Module module) {
      }

      public default void start(Module module) {
      }

      public default void start() {
      }

      public default void end() {
      }

      public default void subscribe(ServiceInstance instance) {
      }

Default send EntryPoint

The defaultSendEntryPoint element defines the default method which will be called by default when invoking automatically a Service[1]
some publish Services can be called cyclically
The signature of this method must be: <method_name>(ServiceInstance service). The method will be called each time a Service invoked automatically is invoked (just before sending its result).

It can be used to perform computations before invoking the Service (for example, setting values to datas).

For example:
      <groovyModule name="FlightManagementSystem" id="1" >
         <groovyImplementation path="fms.groovy" >
            <defaultSendEntryPoint method="publish" />
         </groovyImplementation>
      </module>

Getting or Setting a Data value

Getting or setting a Data value is identical to how it is perfoemd with Java modules. See Data manipulation.

Example

In the following example, the FlightManagementSystem module:
  • subscribe to the position publish service
  • subscribe to the directTo event service
  • provides the computeFlightPlan request-response service
      <groovyModule name="FlightManagementSystem" id="1" >
         <groovyImplementation path="fms.groovy" />
         <interfaces>
            <subscribe service="position" />
            <eventReceived service="directTo"/>
            <requestReceived service="computeFlightPlan"/>
         </interfaces>
      </groovyModule>


We could have the following code for the script:
      public void subscribe(ServiceInstance service) {
        if (service.getName().equals("position")) {
        // get position
        ...
        } else if (service.getName().equals("directTo")) {
        // compute directTo
        ...
        } else if (service.getName().equals("computeFlightPlan")) {
        // compute FlightPlan and sends the response
        ...
        }
      }

Notes

  1. ^ some publish Services can be called cyclically

See also


Categories: concepts

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