ResponseModule
will not have any graphical interface and will:RequestModule
will have a graphical interface and will:request
service in a services.xml
XML file:request
part of the service carries the numeric valueresponse
part of the service carries another numeric value<services> <requestResponse name="request" id="1" > <request> <data name="query" type="int" /> </request> <response> <data name="response" type="int" /> </response> </requestResponse> </services>
int
type is an inttypes.xml
XML file:<types> <simpleType name="int" baseType="int" /> </types>
applications.xml
XML file:RequestAppli
only contains the RequestModule
. This Module:request
requestrequest
responseResponseAppli
only contains the ResponseModule
. This Module:request
requestrequest
response. The associated value is the value associated with the request multiplied by 10<applications> <application name="requestAppli" id="1"> <modules> <module name="RequestModule" id="1" > <interfaces> <requestSend service="request" timeOut="200ms"/> </interfaces> </module> </modules> </application> <application name="responseAppli" id="2"> <modules> <module name="ResponseModule" id="1" > <interfaces> <requestReceived service="request" /> </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.
query
response
valuepublic class RequestGUI extends JFrame { private JSpinner spinner = null; private JButton button = null; private JLabel label = null; private RequestModule module = null; public RequestGUI(RequestModule module) { super("Request GUI"); this.module = module; } public void updateCount(int count) { // will be called when receiving the response 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 JButton("Send Request"); SpinnerNumberModel spModel = new SpinnerNumberModel(0, 0, 100, 1); spinner = new JSpinner(spModel); label = new JLabel("0"); label.setHorizontalAlignment(JLabel.CENTER); pane.add(spinner); pane.add(Box.createHorizontalStrut(50)); pane.add(button); pane.add(Box.createHorizontalStrut(50)); pane.add(label); pane.add(Box.createHorizontalStrut(50)); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // send the request module.publish(spModel.getNumber().intValue()); } }); } }The result is:
publish(int value)
method to send the requestsubscribe(ServiceInstance service)
method to receive the responsepublic class RequestModule { private ServiceInstance requestService = null; private RequestGUI gui = null; public void init(Module module) { requestService = module.getService("request"); gui = new RequestGUI(this); gui.setup(); gui.pack(); gui.setVisible(true); } public void subscribe(ServiceInstance service) { int count = requestService.getData("response").getValueAsInt(); gui.updateCount(count); } public void publish(int value) { requestService.setDataIntValue("query", value); requestService.invoke(); } }
<applications> <application name="requestAppli" id="1"> <deployment> <lib url="request.jar" /> </deployment> <modules> <module name="RequestModule" id="1" > <implementation path="my.package.RequestModule" > <initEntryPoint method="init" /> <defaultReceiveEntryPoint method="subscribe" /> </implementation> <interfaces> <requestSend service="request" timeOut="200ms"/> </interfaces> </module> </modules> </application>
publish(int value)
method to receive the request and send the responsepublic class ResponseModule { public void init(Module module) { requestService = module.getProviderService("request"); } public void subscribe(ServiceInstance service) { // get the query value int i = service.getData("query").getValueAsInt(); // compute the response (in this case arbitrary equal to 10 * query value) service.setDataIntValue("response", i * 10); // invoke the service for the response service.invoke(); } }
<application name="responseAppli" id="2"> <deployment> <lib url="response.jar" /> </deployment> <modules> <module name="ResponseModule" id="1" > <implementation path="org.da.samples.protoframework.response.ResponseModule" > <initEntryPoint method="init" / > <defaultReceiveEntryPoint method="subscribe" / > </implementation > <interfaces> <requestReceived service="request" /> </interfaces> </module> </modules> </application>
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