Commit 32d36fe2 authored by Christophe Demarey's avatar Christophe Demarey
Browse files

Add a reconfiguration component using fscript.

parent 2a2c852b
......@@ -48,6 +48,13 @@
</properties>
<dependencies>
<!-- FraSCAti Explorer -->
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-explorer-fscript-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......@@ -66,4 +73,34 @@
<version>1.0.3</version>
</dependency>
</dependencies>
<!-- ========= -->
<!-- Profiles -->
<!-- ========= -->
<profiles>
<profile>
<id>explorer</id>
<build>
<defaultGoal>exec:exec</defaultGoal>
<plugins>
<!-- Run the Explorer -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dfractal.provider=org.objectweb.fractal.julia.Julia</argument>
<argument>-cp</argument>
<classpath />
<argument>org.ow2.frascati.explorer.fscript.FrascatiScriptExplorerLauncher</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
/***
* OW2 FraSCAti Examples: Fscript reconfiguration
* Copyright (C) 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):
*
*/
package org.ow2.frascati.examples.reconfig.converter.explorer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import javax.swing.JButton;
import javax.swing.JTextField;
import org.objectweb.fractal.fscript.FScriptException;
import org.ow2.frascati.examples.reconfig.converter.fscript.ExchangeRateUpdater;
import org.ow2.frascati.explorer.gui.AbstractSelectionPanel;
/**
* Is the FraSCAti Explorer plugin to show {@link ExchangeRateUpdater} instances.
*
* @author Christophe Demarey
*/
@SuppressWarnings("serial")
public class UpdaterPanel extends AbstractSelectionPanel<ExchangeRateUpdater> {
private NumberFormat nf; // used to format double display
private JTextField jTextFieldValue;
private JButton jButtonUpdate;
/**
* Default constructor creates the panel.
*/
public UpdaterPanel() {
super();
nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(4);
jTextFieldValue = new JTextField();
jTextFieldValue.setColumns(10);
jButtonUpdate = new JButton("Update");
// layout
this.add(jTextFieldValue);
this.add(jButtonUpdate);
// actions
jButtonUpdate.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (jTextFieldValue.getText().length() > 0) {
double newValue = Double.parseDouble( jTextFieldValue.getText() );
try {
selected.updateExchangeRate(newValue);
} catch (FScriptException e1) {
System.out.println("Reconfiguration failed!");
e1.printStackTrace();
}
}
}
});
}
}
/***
* 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
*
* Authors: Christophe Demarey
*/
package org.ow2.frascati.examples.reconfig.converter.fscript;
import org.objectweb.fractal.fscript.FScriptException;
/**
* This service allows to dynamically update the exchange rate of the currency
* converter component.
*
* @author Christophe Demarey
*/
public interface ExchangeRateUpdater {
void updateExchangeRate(double newValue) throws FScriptException;
}
/***
* 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
*
* Authors: Christophe Demarey
*/
package org.ow2.frascati.examples.reconfig.converter.fscript;
import org.objectweb.fractal.fscript.FScriptException;
import org.ow2.frascati.fscript.FraSCAtiScript;
/**
* A SCA component used to dynamically reconfigure another SCA component: the
* currency converter.
*
* The FScript plugin <b>MUST</b> be activated!
*
* @author Christophe Demarey.
*/
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("rate = $converter/scaproperty::exchangeRate;");
fscript.execute("set-value($rate,"+newValue+")");
}
}
......@@ -40,4 +40,10 @@
</panel>
</node>
<node type-name="org.ow2.frascati.examples.reconfig.converter.fscript.ExchangeRateUpdater">
<panel>
<code>org.ow2.frascati.examples.reconfig.converter.explorer.UpdaterPanel</code>
</panel>
</node>
</explorer>
......@@ -34,4 +34,12 @@
<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>
</component>
</composite>
Supports Markdown
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