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

Autodescripted modules tutorial



The first tutorial presented the coding and configuration of a very simple system with two modules. In this tutorial, we will change the definition of one of the modules to encapsulate it as an autodescripted module.

Overview

In the first tutorial, we had two modules:
  • The PublishModule module increments or decrements a value cyclically
  • The EventModule module allows to click on a toggle to set if the first module should increment or decrement the value, and shows the value
We will encapsulate the PublishModule as an autodescripted module.

Architecture

Rather than directly defining the implementation of the PublishModule in the applications definition, we will point to a jar file specifying the module implementation in its manifest.

autodescriptutorial

Specification of the autodescripted module

Autodescripted module application definition

The original description of the application containing our PublishModule module was:
   <applications>
      ...
      <application name="publishAppli">
      <deployment>
             <lib url="samplesPublish.jar" />
          </deployment>
          <modules>
             <module name="PublishModule" >
                <implementation path="org.da.samples.protoframework.publish.PublishModule" >
                   <initEntryPoint method="init" />
                   <defaultReceiveEntryPoint method="subscribe" />
                   <defaultSendEntryPoint method="publish" />
                </implementation>
                <interfaces>
                   <eventReceived service="event"/>
                   <cyclic service="published" frequency="200ms" attach="attach"/>
                </interfaces>
             </module>
          </modules>
      </application>
   <applications>
We will keep the same definition, but:
  • We don't need to set the application deployment in our case, because the application description descript what is in the jar file we are
  • We also don't need to enclose our PublishModule module, because an autodescripted module only cotnains one module
We will therefore have the following specification:
      <application name="publishAppli">
          <modules>
             <module name="PublishModule" >
                <implementation path="org.da.samples.protoframework.publish.PublishModule" >
                   <initEntryPoint method="init" />
                   <defaultReceiveEntryPoint method="subscribe" />
                   <defaultSendEntryPoint method="publish" />
                </implementation>
                <interfaces>
                   <eventReceived service="event"/>
                   <cyclic service="published" frequency="200ms" attach="attach"/>
                </interfaces>
             </module>
          </modules>
      </application>

Services and types definition

The services and type does not need to change from the first tutorial.

The Services:
      <services>
         <event name="event" id="1" >
            <data name="event" type="bool" />
         </event>
         <publish name="published" id="2" >
            <data name="value" type="int" />
         </publish>
      </services>
The Types:
      <types>
         <simpleType name="bool" baseType="boolean" />
         <simpleType name="int" baseType="int" />
      </types>

Code of the PublishModule

The code does not need to change at all from the first tutorial:
      public class PublishModule {
        private ServiceInstance eventService = null;
        private ServiceInstance publishService = null;
        private int count = 1;
        private int step = 1;

        public void init(Module module) {
          eventService = module.getService("event");
          publishService = module.getService("published");
        }

        public void subscribe(ServiceInstance service) {
          boolean evt = eventService.getData("event").getValueAsBoolean();
          if (evt) {
            step = -1;
          } else {
            step = 1;
          }
        }

        public void publish(ServiceInstance service) {
          publishService.setDataIntValue("value", count);
          count += step;
          publishService.invoke();
        }
      }

Content of the Jar file

We just have to add a Manifest to the already existing samplesPublish.jar jar file:

To be able to get the auto-description of the module, we will create a Manifest with the following attributes:
      Modules: applications.xml
      Services: services.xml
      Types: types.xml

Usage of the autodescripted module

The original description of the applications configuration was:
      <applications>
         <application name="eventAppli" >
            <deployment>
               <lib url="samplesEvent.jar" />
            </deployment>
            <modules>
               <module name="EventModule" >
                  <implementation path="org.da.samples.protoframework.event.EventModule" >
                     <initEntryPoint method="init" />
                     <defaultReceiveEntryPoint method="subscribe" />
                  </implementation>
                  <interfaces>
                     <eventSend service="event" attach="attach"/>
                     <subscribe service="published" />
                  </interfaces>
               </module>
            </modules>
         </application>
      <application name="publishAppli" >
            <deployment>
               <lib url="samplesPublish.jar" />
            </deployment>
            <modules>
               <module name="PublishModule" >
                  <implementation path="org.da.samples.protoframework.publish.PublishModule" >
                     <initEntryPoint method="init" />
                     <defaultReceiveEntryPoint method="subscribe" />
                     <defaultSendEntryPoint method="publish" />
                  </implementation>
                  <interfaces>
                     <eventReceived service="event"/>
                     <cyclic service="published" frequency="200ms" attach="attach"/>
                  </interfaces>
               </module>
            </modules>
         </application>
      </applications>
To use our newly created autodescripted module, we now have a much more simple description for the PublishModule module:
      <applications>
         <application name="eventAppli" >
            <deployment>
               <lib url="samplesEvent.jar" />
            </deployment>
            <modules>
               <module name="EventModule" >
                  <implementation path="org.da.samples.protoframework.event.EventModule" >
                     <initEntryPoint method="init" />
                     <defaultReceiveEntryPoint method="subscribe" />
                  </implementation>
                  <interfaces>
                     <eventSend service="event" attach="attach"/>
                     <subscribe service="published" />
                  </interfaces>
               </module>
            </modules>
         </application>
         <application name="publishAppli" >
            <deployment>
               <lib url="samplesPublish.jar" />
            </deployment>
         </application >   
      </applications>

See also


Categories: tutorials

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