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

Third tutorial



In the first tutorial, one module increments or decrements a value by a step of 1 cyclically. In this tutorial, we will set the step factor by a property.

Overview

We have two modules:
  • One module increments or decrements a value cyclically by a step
  • Another module allows to click on a toggle to set if the first module should increment or decrement the value. It also shows the value

tuto1
We will change the PublishModule by setting the step by using a factor property.

XML configuration

Only the applications.xml XML file will be modified to specify an init EntryPoint. We will also define an int property for the factor.

Applications definition


We will change the applications.xml XML file, by adding a factor property:
      <applications>
         <application name="eventAppli" id="1">
            <deployment>
               <lib url="samples1Event.jar" />
            </deployment>
            <modules>
               <module name="EventModule" id="1" >
                  <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" id="2">
            <deployment>
               <lib url="samples1Publish.jar" />
            </deployment>
            <modules>
               <module name="PublishModule" id="1" >
                  <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>
                  <properties>
                     <property key="factor" type="int" />
                  </properties>
               </module>
            </modules>
         </application>
      </applications>

Add a properties file

We will add a properties file to specify the properties. For example:
      <properties>
         <application name="publishAppli" >
            <module name="PublishModule" >
               <moduleProperty key="factor" value="10" />
            </module>
         </application>
      </properties>
This file must be specified in the filelist configuration:
      <files>
         <file url="applications.xml" />
         <file url="services.xml" />
         <file url="types.xml" />
         <file url="properties.xml" />
      </files>

Code the PublishModule

We will change the PublishModule to get a factor from the module property.
      public class PublishModule {
        private ServiceInstance eventService = null;
        private ServiceInstance publishService = null;
        private int count = 1;
        private int step = 1;
      - private factor = 1;

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

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

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

See also


Categories: tutorials

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