PublishModule
will not have any graphical interface and will:EventModule
will have a graphical interface and will:services.xml
XML file:event
service carries the state of the toggle button. It is an event Service because the service should only be invoked when the state of the toggle button changespublished
service carries the value. It is a publish Service because the service should be invoked cyclically<services> <event name="event" > <data name="event" type="bool" /> </event> <publish name="published" > <data name="value" type="int" /> </publish> </services>
bool
type is a booleanint
type is an inttypes.xml
XML file:<types> <simpleType name="bool" baseType="boolean" /> <simpleType name="int" baseType="int" /> </types>
applications.xml
XML file:eventAppli
only contains the EventModule
. This Module:event
servicepublished
servicepublishAppli
only contains the PublishModule
. This Module:published
serviceevent
service<applications> <application name="eventAppli" > <modules> <module name="EventModule" > <interfaces> <eventSend service="event" attach="attach"/> <subscribe service="published" /> </interfaces> </module> </modules> </application> <application name="publishAppli" > <modules> <module name="PublishModule" > <interfaces> <eventReceived service="event"/> <cyclic service="published" frequency="200ms" attach="attach"/> </interfaces> </module> </modules> </application> </applications>For now we did not bridge our services to any implementation for our two applications. This will be done in the next step.
published
serviceevent
servicepublished
service to be invoked cyclically every 200 milliseconds in the module XML specification:<cyclic service="published" frequency="200ms" attach="attach"/>We will create a
PublishModule
class to implement the behavior of this Module:subscribe
method will be notified of the event
Service. Depending on the value of the event
data, a step
variable will have a 1 or -1 valuepublish
method will be invoked cyclically for the published
Service. The current value will be incremented or decremented, and the Service will be notified with this current valuepublic 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(); } }
PublishModule
, we must specify in the applications.xml
XML file the bridge between this module and its implementation:publishAppli
PublishModule
<application name="publishAppli" > <deployment> <lib url="samples1Publish.jar" /> </deployment> <modules> <module name="PublishModule" > <implementation path="org.da.samples.protoframework.publish.PublishModule" > ... </implementation> </module> </modules> </application>We must also specify:
init
method will be called at the initialization of the Modulesubscribe
method will be called each time the Module is notified from the event
Servicepublish
method will be called cyclically for the published
Service<implementation path="org.da.samples.protoframework.publish.PublishModule" > <initEntryPoint method="init" /> <defaultReceiveEntryPoint method="subscribe" /> <defaultSendEntryPoint method="publish" /> </implementation>
event
servicepublished
serviceEventModule
class to implement the behavior of this Module. The graphical representation will be in a separate subclass of JFrame to show the toggle button and the label showing the current value:subscribe
method will be notified of the published
Service. The value will set the text of the labelpublish
method will be invoked when the user clicks on the toggle button, to send the for the event
Servicepublic class EventModule { private ServiceInstance eventService = null; private ServiceInstance publishService = null; private EventGUI gui = null; public void init(Module module) { eventService = module.getService("event"); publishService = module.getService("published"); gui = new EventGUI(this); gui.setup(); gui.pack(); gui.setVisible(true); } public void subscribe(ServiceInstance service) { int count = publishService.getData("value").getValueAsInt(); gui.updateCount(count); } public void publish(boolean b) { eventService.setDataBooleanValue("event", b); eventService.invoke(); } }The associated GUI class has nothing specific to the framework:
public class EventGUI extends JFrame { private JToggleButton button = null; private JLabel label = null; private EventModule module = null; public EventGUI(EventModule module) { super("Event GUI"); this.module = module; } public void updateCount(int count) { label.setText(Integer.toString(count)); label.invalidate(); label.repaint(); } public void setup() { Container pane = this.getContentPane(); pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS)); button = new JToggleButton("Positive Step"); label = new JLabel("0"); label.setHorizontalAlignment(JLabel.CENTER); pane.add(button); pane.add(Box.createHorizontalStrut(50)); pane.add(label); pane.add(Box.createHorizontalStrut(50)); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (button.isSelected()) { button.setText("Negative Step"); } else { button.setText("Positive Step"); } module.publish(button.isSelected()); } }); } }
EventModule
, we must specify in the applications.xml
XML file the bridge between this module and its implementation:eventAppli
EventModule
<application name="eventAppli"> <deployment> <lib url="samplesEvent.jar" /> </deployment> <modules> <module name="EventModule" > <implementation path="org.da.samples.protoframework.event.EventModule" > ... </implementation> </module> </modules> </application>We must also specify:
init
method will be called at the initialization of the Modulesubscribe
method will be called each time the Module is notified from the published
Service<implementation path="org.da.samples.protoframework.publish.PublishModule" > <initEntryPoint method="init" /> <defaultReceiveEntryPoint method="subscribe" /> </implementation>
applications.xml
XML file:<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>In the last step, we will specify the filelist configuration of the system, including:
types.xml
definitionservices.xml
definitionapplications.xml
definition<files> <file url="applications.xml" /> <file url="services.xml" /> <file url="types.xml" /> </files>
filelist.xml
file for our configuration: java -jar protoframework.jar config=filelist.xml
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence