Commit 5f303699 authored by Christophe Demarey's avatar Christophe Demarey

Expose converter as a Rest Service. Move client in a distinct composite.

parent e9e532f7
......@@ -113,6 +113,7 @@
<argument>-cp</argument>
<classpath />
<argument>org.ow2.frascati.explorer.fscript.FrascatiScriptExplorerLauncher</argument>
<argument>reconfig</argument>
</arguments>
</configuration>
</plugin>
......
......@@ -20,20 +20,31 @@
*/
package org.ow2.frascati.examples.reconfig.converter;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.osoa.sca.annotations.Service;
/**
* A basic currency converter.
*/
@Service
public interface CurrencyConverter {
/**
* Converts Euros to Dollars.
*
* @param value the amount of euros to convert.
*/
double euroToDollar(double value);
@GET
@Path("/euro2dollar")
double euroToDollar(@FormParam("value") double value);
/**
* Converts Dollars to Euros.
*
* @param value the amount of dollars to convert.
*/
double dollarToEuro(double value);
@GET
@Path("/dollar2euro")
double dollarToEuro(@FormParam("value") double value);
}
......@@ -42,7 +42,7 @@ public class ExchangeRateUpdaterImpl implements ExchangeRateUpdater {
public void updateExchangeRate(double newValue) throws FScriptException {
FraSCAtiScript fscript = FraSCAtiScript.getSingleton();
fscript.execute("converter = $domain/scachild::reconfig/scachild::currency-converter;");
fscript.execute("converter = $domain/scachild::reconfig/scachild::converter/scachild::currency-converter;");
fscript.execute("rate = $converter/scaproperty::exchangeRate;");
fscript.execute("set-value($rate,"+newValue+")");
}
......
<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- OW2 FraSCAti Examples : Fscript reconfiguration -->
<!-- Copyright (C) 2008-2010 INRIA, USTL -->
<!-- -->
<!-- This library is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU Lesser General Public -->
<!-- License as published by the Free Software Foundation; either -->
<!-- version 2 of the License, or (at your option) any later version. -->
<!-- -->
<!-- This library is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
<!-- Lesser General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU Lesser General Public -->
<!-- License along with this library; if not, write to the Free Software -->
<!-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Contact: frascati@ow2.org -->
<!-- -->
<!-- Author: Christophe Demarey -->
<!-- -->
<!-- Contributor(s): -->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:frascati="http://frascati.ow2.org/xmlns/sca/1.1"
name="converter">
<service name="currencyConverter" promote="currency-converter/currencyConverter">
<frascati:binding.rest uri="http://localhost:8888/converter"/>
</service>
<service name="exchangeRateUpdater" promote="exchange-rate-updater/exchangeRateUpdater"/>
<component name="currency-converter">
<implementation.java class="org.ow2.frascati.examples.reconfig.converter.CurrencyConverterImpl"/>
<service name="currencyConverter">
<interface.java interface="org.ow2.frascati.examples.reconfig.converter.CurrencyConverter"/>
</service>
<property name="exchangeRate">0.75</property>
</component>
<component name="exchange-rate-updater">
<implementation.java class="org.ow2.frascati.examples.reconfig.converter.fscript.ExchangeRateUpdaterImpl"/>
<service name="exchangeRateUpdater">
<interface.java interface="org.ow2.frascati.examples.reconfig.converter.fscript.ExchangeRateUpdater"/>
</service>
<property name="reconfigurationScript">reconfig.fscript</property>
</component>
</composite>
......@@ -25,28 +25,10 @@
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" name="reconfig">
<service name="r" promote="client/run"/>
<component name="currency-converter">
<implementation.java class="org.ow2.frascati.examples.reconfig.converter.CurrencyConverterImpl"/>
<service name="currencyConverter">
<interface.java interface="org.ow2.frascati.examples.reconfig.converter.CurrencyConverter"/>
</service>
<property name="exchangeRate">0.75</property>
<component name="converter">
<implementation.composite name="converter"/>
</component>
<component name="exchange-rate-updater">
<implementation.java class="org.ow2.frascati.examples.reconfig.converter.fscript.ExchangeRateUpdaterImpl"/>
<service name="exchangeRateUpdater">
<interface.java interface="org.ow2.frascati.examples.reconfig.converter.fscript.ExchangeRateUpdater"/>
</service>
<property name="reconfigurationScript">reconfig.fscript</property>
</component>
<component name="client">
<implementation.java class="org.ow2.frascati.examples.reconfig.Client"/>
......@@ -55,7 +37,7 @@
</service>
</component>
<wire source="client/converter" target="currency-converter/currencyConverter"/>
<wire source="client/updater" target="exchange-rate-updater/exchangeRateUpdater"/>
<wire source="client/converter" target="converter/currencyConverter"/>
<wire source="client/updater" target="converter/exchangeRateUpdater"/>
</composite>
-- Fscript file defining some fscript actions
action reconfigure-converter(newValue){
converter = $domain/scachild::reconfig/scachild::currency-converter;
converter = $domain/scachild::reconfig/scachild::converter/scachild::currency-converter;
rate = $converter/scaproperty::exchangeRate;
set-value($rate, $newValue);
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment