PublishModule
by an Owner module.PublishModule
will be performed in this FrameworkOwner application.
PublishModule
module increments or decrements a value cyclicallyEventModule
module allows to click on a toggle to set if the first module should increment or decrement the value, and shows the valuePublishModule
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.
services
configuration of the first tutorial, but we will replace the PublishModule
in the applications configuration by an Owner module:eventAppli
only contains the EventModule
. This Module:event
servicepublished
servicepublishAppli
only contains the Owner module. This Module will defer all calls to our Framework Owner class which will be notified for:published
serviceevent
serviceapplications.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>
OwnerMain
class which will:published
serviceevent
serviceMain
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(); }
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; } }
public void publish(ServiceInstance service) { publishService.setDataIntValue("value", count); count += step; publishService.invoke(); }
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(); } }
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence