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

FrameworkOwner tutorial



The first tutorial presented the coding and configuration of a very simple system with two modules. In this Framework Owner tutorial, we reuse the implementation of the first tutorial, but we replace the PublishModule by an Owner module.

The framework will be created and started by the Framework Owner application, and all the code which was performed in the PublishModule will be performed in this FrameworkOwner application.

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 replace the PublishModule module at the configuration level by an Owner module. The framework will be created and started by a Java class which will implement the Framework Owner interface.

Architecture

We won't change anything for the services configuration of the first tutorial, but we will replace the PublishModule in the applications configuration by an Owner module:
  • The eventAppli only contains the EventModule. This Module:
    • sends the event service
    • subscribes to the published service
  • The publishAppli only contains the Owner module. This Module will defer all calls to our Framework Owner class which will be notified for:
    • sending cyclically the published service
    • being notified from the event service

frameworkOwnerTutorial

XML configuration

We will only change the applications.xml XML file, by replacing the previous PublishModule configuration by an ownerModule:
         <applications>
            <application name="eventAppli" id="1">
               <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">
               <modules>
                  <ownerModule name="PublishModule" id="1" >
                     <interfaces>
                        <eventReceived service="event"/>
                        <cyclic service="published" frequency="200ms" attach="attach"/>
                     </interfaces>
                  </ownerModule>
               </modules>
            </application>
         </applications>

Code the FrameworkOwner

The FrameworkOwner must implement the FrameworkOwner interface. We will create an OwnerMain class which will:
  • Create and start the framework
  • sends cyclically the published service
  • subscribes to the event service

Creating and starting the framework

We will create and start the framework in the Main method of our new class. The "config" key will specify the Framework configuration.
      public static void main(String[] args) {
        URL config = <the URL of the framework configuration>

        OwnerMain owner = new OwnerMain();
        Framework framework = new Framework(owner);
        framework.setup(config);
        framework.start();
      }

Subscribing to the event service

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

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

Sending cyclically the published service

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

Complete code for the FrameworkOwner

      public class OwnerMain implements FrameworkOwner {
        private ServiceInstance eventService = null;
        private ServiceInstance publishService = null;
        private int count = 1;
        private int step = 1;

        public OwnerMain() {
        }

        public void init(OwnerModule 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();
        }

        public static void main(String[] args) {
          URL config = <the URL of the framework configuration>

          OwnerMain owner = new OwnerMain();
          Framework framework = new Framework(owner);
          framework.setup(config);
          framework.start();
        }
      }

Starting the application

As soon as the application is started, the framework will be started. Note that you should put the framework on the classpath of your application.

See also


Categories: tutorials

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