Commit ffb50c31 authored by Philippe Merle's avatar Philippe Merle
Browse files

Updated how to bootstrap FraSCAti.

Following Java code lines illustrate how to instantiate FraSCAti: 

  import org.ow2.frascati.FraSCAti;
  ...
  FraSCAti frascati = FraSCAti.newFraSCAti();

This static method uses three Java system properties:
- 'org.ow2.frascati.class': The FraSCAti class to instantiate.
  Possible values are:
  * org.ow2.frascati.FraSCAti (default value)
- 'org.ow2.frascati.bootstrap': The FraSCAti composite to bootstrap.
  Possible values are:
  * org.ow2.frascati.bootstrap.FraSCAti (default value)
  * org.ow2.frascati.bootstrap.FraSCAtiJDT (FraSCAti plus Juliac and JDT)
  * org.ow2.frascati.bootstrap.FraSCAtiFractal (FraSCAti plus <implementation.fractal>)
- 'org.ow2.frascati.composite': The FraSCAti composite to load.
  Possible values are:
  * org.ow2.frascati.FraSCAti (default value)

This is now easy to add a new FraSCAti bootstrap composite. See an example into
frascati/modules/frascati-implementation-fractal/
parent 2361ba98
Assembly Factory 1.3
--------------------
* Updated how to bootstrap FraSCAti.
Following Java code lines illustrate how to instantiate FraSCAti:
import org.ow2.frascati.FraSCAti;
...
FraSCAti frascati = FraSCAti.newFraSCAti();
This static method uses three Java system properties:
- 'org.ow2.frascati.class': The FraSCAti class to instantiate.
Possible values are:
* org.ow2.frascati.FraSCAti (default value)
- 'org.ow2.frascati.bootstrap': The FraSCAti composite to bootstrap.
Possible values are:
* org.ow2.frascati.bootstrap.FraSCAti (default value)
* org.ow2.frascati.bootstrap.FraSCAtiJDT (FraSCAti plus Juliac and JDT)
* org.ow2.frascati.bootstrap.FraSCAtiFractal (FraSCAti plus <implementation.fractal>)
- 'org.ow2.frascati.composite': The FraSCAti composite to load.
Possible values are:
* org.ow2.frascati.FraSCAti (default value)
This is now easy to add a new FraSCAti bootstrap composite. See an example into
frascati/modules/frascati-implementation-fractal/
* Moved to Apache CXF 2.2.9.
* Added a new example illustrating how to implement SCA components with OW2 Fractal. See:
......
......@@ -37,9 +37,9 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.ow2.frascati.assembly.factory.AssemblyFactory;
import org.ow2.frascati.assembly.factory.RuntimeFactory;
import org.ow2.frascati.FraSCAti;
import org.ow2.frascati.assembly.factory.Launcher;
import org.ow2.frascati.bootstrap.FraSCAtiJDT;
import org.ow2.frascati.util.FrascatiException;
/**
......@@ -216,26 +216,22 @@ public class FactoryCommandLine {
e.printStackTrace();
}
}
AssemblyFactory f = null;
Launcher launcher = null;
try {
if ( cmd.isFscriptEnabled() )
try {
f = (AssemblyFactory) Class.forName(FRASCATISCRIPT_FACTORY).newInstance();
} catch (Exception e) {
throw new FrascatiException(e);
}
else
f = new RuntimeFactory();
// TODO must be configurable from pom.xml files.
if(cmd.isFscriptEnabled()) {
System.setProperty(FraSCAti.FRASCATI_CLASS_PROPERTY_NAME, FRASCATISCRIPT_FACTORY);
}
System.setProperty(FraSCAti.FRASCATI_BOOTSTRAP_PROPERTY_NAME, FraSCAtiJDT.class.getCanonicalName());
// TODO
// TODO Reactive this feature.
// f.getService(f.getFactory(), "juliac", JuliacConfiguration.class).setOutputDir(new File(cmd.getBaseDir()));
launcher = new Launcher(compositeName, f, urls);
FraSCAti frascati = FraSCAti.newFraSCAti();
launcher = new Launcher(compositeName, frascati, urls);
} catch (FrascatiException e) {
System.err.println("Cannot instantiate the FraSCAti factory!");
System.err.println("Exiting ...");
......
......@@ -26,31 +26,30 @@
package org.ow2.frascati.intent.availability.test;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.objectweb.fractal.api.Component;
import org.osoa.sca.ServiceUnavailableException;
import org.ow2.frascati.assembly.factory.AssemblyFactory;
import org.ow2.frascati.tinfi.TinfiDomain;
import org.ow2.frascati.FraSCAti;
public class AvailabilityTestCase {
AssemblyFactory factory;
protected static FraSCAti frascati;
@Before
public void init() throws Exception {
factory = new AssemblyFactory();
@BeforeClass
public static void init() throws Exception {
frascati = FraSCAti.newFraSCAti();
}
@Test
public void availability() throws Exception {
// Load the availability-test composite.
Component scaComposite = factory.getComposite("availability-test");
Component scaComposite = frascati.getComposite("availability-test");
// Obtain the service to test.
ServiceInterface si = TinfiDomain.getService(scaComposite, ServiceInterface.class, "Service");
ServiceInterface si = frascati.getService(scaComposite, "Service", ServiceInterface.class);
workThrownIllegalArgumentException(si, -1000);
workThrownIllegalArgumentException(si, -500);
......@@ -72,9 +71,9 @@ public class AvailabilityTestCase {
@Test
public void availability1s() throws Exception {
// Load the availability-test composite.
Component scaComposite = factory.getComposite("availability-1s-test");
Component scaComposite = frascati.getComposite("availability-1s-test");
// Obtain the service to test.
ServiceInterface si = TinfiDomain.getService(scaComposite, ServiceInterface.class, "Service");
ServiceInterface si = frascati.getService(scaComposite, "Service", ServiceInterface.class);
workThrownIllegalArgumentException(si, -1000);
workThrownIllegalArgumentException(si, -500);
......@@ -96,9 +95,9 @@ public class AvailabilityTestCase {
@Test
public void availability2s() throws Exception {
// Load the availability-test composite.
Component scaComposite = factory.getComposite("availability-2s-test");
Component scaComposite = frascati.getComposite("availability-2s-test");
// Obtain the service to test.
ServiceInterface si = TinfiDomain.getService(scaComposite, ServiceInterface.class, "Service");
ServiceInterface si = frascati.getService(scaComposite, "Service", ServiceInterface.class);
workThrownIllegalArgumentException(si, -1000);
workThrownIllegalArgumentException(si, -500);
......@@ -120,9 +119,9 @@ public class AvailabilityTestCase {
@Test
public void availability3s() throws Exception {
// Load the availability-test composite.
Component scaComposite = factory.getComposite("availability-3s-test");
Component scaComposite = frascati.getComposite("availability-3s-test");
// Obtain the service to test.
ServiceInterface si = TinfiDomain.getService(scaComposite, ServiceInterface.class, "Service");
ServiceInterface si = frascati.getService(scaComposite, "Service", ServiceInterface.class);
workThrownIllegalArgumentException(si, -1000);
workThrownIllegalArgumentException(si, -500);
......@@ -144,9 +143,9 @@ public class AvailabilityTestCase {
@Test
public void availability4s() throws Exception {
// Load the availability-test composite.
Component scaComposite = factory.getComposite("availability-4s-test");
Component scaComposite = frascati.getComposite("availability-4s-test");
// Obtain the service to test.
ServiceInterface si = TinfiDomain.getService(scaComposite, ServiceInterface.class, "Service");
ServiceInterface si = frascati.getService(scaComposite, "Service", ServiceInterface.class);
workThrownIllegalArgumentException(si, -1000);
workThrownIllegalArgumentException(si, -500);
......@@ -169,9 +168,9 @@ public class AvailabilityTestCase {
@Test
public void availability5s() throws Exception {
// Load the availability-test composite.
Component scaComposite = factory.getComposite("availability-5s-test");
Component scaComposite = frascati.getComposite("availability-5s-test");
// Obtain the service to test.
ServiceInterface si = TinfiDomain.getService(scaComposite, ServiceInterface.class, "Service");
ServiceInterface si = frascati.getService(scaComposite, "Service", ServiceInterface.class);
workThrownIllegalArgumentException(si, -1000);
workThrownIllegalArgumentException(si, -500);
......@@ -195,9 +194,9 @@ public class AvailabilityTestCase {
@Test
public void availability10s() throws Exception {
// Load the availability-test composite.
Component scaComposite = factory.getComposite("availability-10s-test");
Component scaComposite = frascati.getComposite("availability-10s-test");
// Obtain the service to test.
ServiceInterface si = TinfiDomain.getService(scaComposite, ServiceInterface.class, "Service");
ServiceInterface si = frascati.getService(scaComposite, "Service", ServiceInterface.class);
workThrownIllegalArgumentException(si, -1000);
workThrownIllegalArgumentException(si, -500);
......
......@@ -25,19 +25,14 @@
package examples.chat.client.gui;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.osoa.sca.annotations.Scope;
import org.ow2.frascati.assembly.factory.AssemblyFactory;
import org.ow2.frascati.tinfi.TinfiDomain;
import org.ow2.frascati.FraSCAti;
import org.ow2.frascati.util.FrascatiException;
import examples.chat.Chat;
......@@ -53,8 +48,6 @@ public class ChatGUI
implements Runnable {
/** A reference to the Chat service. */
protected static Chat service;
/** Logger for this class */
protected static Logger log = Logger.getLogger("examples.chat.client.gui.ChatGUI");
/**
* Default constructor.
......@@ -108,13 +101,10 @@ public class ChatGUI
String compositeName = "chat-gui-client",
serviceName = "chatService";
Component c = new AssemblyFactory().getComposite(compositeName);
try {
service = TinfiDomain.getService(c, Chat.class, serviceName);
} catch(NoSuchInterfaceException nsie) {
log.log(Level.SEVERE, "The SCA composite '" + compositeName + "' has no service '" + serviceName + "'!", nsie);
}
FraSCAti frascati = FraSCAti.newFraSCAti();
Component c = frascati.getComposite(compositeName);
service = frascati.getService(c, serviceName, Chat.class);
// Run the GUI
launch(ChatGUI.class, args);
......
......@@ -50,13 +50,6 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-fscript</artifactId>
<version>${frascati.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
/***
* 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.test;
import org.junit.Before;
import org.ow2.frascati.fscript.FrascatiScriptFactory;
import org.ow2.frascati.util.FrascatiException;
/**
* An utility class used to run tests on FraSCAti runtime with FScript enable.
*
* @author Christophe Demarey
*/
public abstract class FraSCAtiScriptTestCase extends FraSCAtiTestCase {
/**
* Load a composite
*
* @param name
* the composite name
* @throws FrascatiException
*/
@Before
@Override
public void loadComposite() throws FrascatiException {
String compositeName = getComposite();
System.out.println("Loading " + compositeName + " composite...");
scaComposite = new FrascatiScriptFactory().getComposite(compositeName);
}
}
......@@ -29,11 +29,8 @@ import org.junit.After;
import org.junit.Before;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.ow2.frascati.assembly.factory.AssemblyFactory;
import org.ow2.frascati.tinfi.TinfiDomain;
import org.ow2.frascati.FraSCAti;
import org.ow2.frascati.util.FrascatiException;
/**
......@@ -42,6 +39,8 @@ import org.ow2.frascati.util.FrascatiException;
*/
public abstract class FraSCAtiTestCase {
protected FraSCAti frascati;
/**
* The SCA composite to test
*/
......@@ -57,8 +56,9 @@ public abstract class FraSCAtiTestCase {
@Before
public void loadComposite() throws FrascatiException {
String compositeName = getComposite();
System.out.println("Loading " + compositeName + " composite...");
scaComposite = new AssemblyFactory().getComposite(compositeName);
System.out.println("Loading SCA composite '" + compositeName + "'...");
frascati = FraSCAti.newFraSCAti();
scaComposite = frascati.getComposite(compositeName);
}
/**
......@@ -71,11 +71,11 @@ public abstract class FraSCAtiTestCase {
* @return the service named <code>serviceName</code> or null
*/
protected <T> T getService(Class<T> cl, String serviceName) {
System.out.println("Getting service " + serviceName + "...");
System.out.println("Getting SCA service '" + serviceName + "'...");
try {
return TinfiDomain.getService(scaComposite, cl, serviceName);
} catch (NoSuchInterfaceException e) {
System.err.println("No such service: " + serviceName);
return frascati.getService(scaComposite, serviceName, cl);
} catch (Exception e) {
System.err.println("No such SCA service: " + serviceName);
return null;
}
}
......@@ -89,9 +89,11 @@ public abstract class FraSCAtiTestCase {
* if the lifecycle controller of the component is not found
*/
@After
public void close() throws IllegalLifeCycleException,
NoSuchInterfaceException {
TinfiDomain.close(scaComposite);
public void close() throws FrascatiException
{
if(scaComposite != null) {
frascati.close(scaComposite);
}
}
// ---------------------------------------------------------------------------
......
......@@ -27,7 +27,7 @@
package org.ow2.frascati.examples.helloworld.spring;
import org.objectweb.fractal.api.Component;
import org.ow2.frascati.assembly.factory.AssemblyFactory;
import org.ow2.frascati.FraSCAti;
public class Main {
......@@ -35,17 +35,17 @@ public class Main {
{
System.out.println("\n\n\nStarting the OW2 FraSCAti Helloworld Spring Example\n\n\n");
AssemblyFactory factory = new AssemblyFactory();
FraSCAti frascati = FraSCAti.newFraSCAti();
Component scaComposite = factory.getComposite("helloworld-spring");
Component scaComposite = frascati.getComposite("helloworld-spring");
java.lang.Runnable hello = factory.getService(scaComposite, "r", java.lang.Runnable.class);
java.lang.Runnable hello = frascati.getService(scaComposite, "r", java.lang.Runnable.class);
// performs some calls
hello.run();
// close the SCA composite.
factory.close(scaComposite);
frascati.close(scaComposite);
System.out.println("\n\n\n");
}
......
......@@ -43,6 +43,9 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<logging.conf.file>../../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<org.ow2.frascati.class>org.ow2.frascati.FraSCAti</org.ow2.frascati.class>
<org.ow2.frascati.bootstrap>org.ow2.frascati.bootstrap.FraSCAtiFractal</org.ow2.frascati.bootstrap>
<org.ow2.frascati.composite>org.ow2.frascati.FraSCAti</org.ow2.frascati.composite>
</properties>
<!-- ===== -->
......@@ -60,10 +63,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<version>2.5</version>
<configuration>
<skipTests>false</skipTests>
<useSystemClassLoader>false</useSystemClassLoader>
<skipTests>false</skipTests>
<useSystemClassLoader>false</useSystemClassLoader>
<systemPropertyVariables>
<org.ow2.frascati.class>${org.ow2.frascati.class}</org.ow2.frascati.class>
<org.ow2.frascati.bootstrap>${org.ow2.frascati.bootstrap}</org.ow2.frascati.bootstrap>
<org.ow2.frascati.composite>${org.ow2.frascati.composite}</org.ow2.frascati.composite>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
......@@ -115,6 +123,11 @@
<service>${service.name}</service>
<method>${method.name}</method>
<methodParams>${method.params}</methodParams>
<systemPropertyVariables>
<org.ow2.frascati.class>${org.ow2.frascati.class}</org.ow2.frascati.class>
<org.ow2.frascati.bootstrap>${org.ow2.frascati.bootstrap}</org.ow2.frascati.bootstrap>
<org.ow2.frascati.composite>${org.ow2.frascati.composite}</org.ow2.frascati.composite>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
......
......@@ -36,19 +36,15 @@ import java.util.Arrays;
import java.util.List;
import java.util.Set;
import javax.xml.namespace.QName;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.ow2.frascati.assembly.factory.AssemblyFactory;
import org.ow2.frascati.FraSCAti;
import org.ow2.frascati.assembly.factory.api.ClassLoaderManager;
import org.ow2.frascati.assembly.factory.api.CompositeManager;
import org.ow2.frascati.assembly.factory.api.ProcessingContext;
import org.ow2.frascati.assembly.factory.api.ProcessingMode;
import org.ow2.frascati.assembly.factory.processor.ProcessingContextImpl;
import org.ow2.frascati.component.factory.api.MembraneGeneration;
/**
......@@ -230,17 +226,17 @@ public class FrascatiCompilerMojo extends AbstractMojo {
currentThread.setContextClassLoader(new URLClassLoader(urls, oldThreadContextClassLoader));
try {
// Create a new instance of OW2 FraSCAti Assembly Factory.
AssemblyFactory assemblyFactory = new AssemblyFactory();
// Create a new OW2 FraSCAti instance.
FraSCAti frascati = FraSCAti.newFraSCAti();
// Declare all Java sources to compile.
MembraneGeneration membraneGeneration = assemblyFactory.getMembraneGeneration();
MembraneGeneration membraneGeneration = frascati.getMembraneGeneration();
for(String src : srcs) {
membraneGeneration.addJavaSource(src);
}
// Get the class loader of OW2 FraSCAti Assembly Factory.
ClassLoaderManager classLoaderManager = assemblyFactory.getClassLoaderManager();
// Get the OW2 FraSCAti class loader manager.
ClassLoaderManager classLoaderManager = frascati.getClassLoaderManager();
// Add project resources if any into the class loader.
File fr = new File(baseDir.getAbsolutePath() + File.separator + "src/main/resources");
......@@ -255,17 +251,12 @@ public class FrascatiCompilerMojo extends AbstractMojo {
}
classLoaderManager.loadLibraries(srcUrl);
// Get the composite manager service of OW2 FraSCAti Assembly Factory.
CompositeManager componentManager = assemblyFactory.getCompositeManager();
// Prepare the processing context
ProcessingContext processingContext = new ProcessingContextImpl(classLoaderManager.getClassLoader());
processingContext.setProcessingMode(ProcessingMode.compile);
// Process SCA composites.
for (String composite: getComposites()) {
getLog().info("Compiling the SCA composite " + composite);
componentManager.processComposite(new QName(composite), processingContext);
getLog().info("Compiling the SCA composite '" + composite + "'");
// Prepare the processing context
ProcessingContext processingContext = frascati.newProcessingContext(ProcessingMode.compile);
frascati.processComposite(composite, processingContext);
getLog().info("SCA composite '" + composite + "' compiled successfully.");
}
......
......@@ -43,9 +43,10 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.codehaus.classworlds.ClassRealm;
import org.ow2.frascati.assembly.factory.AssemblyFactory;
import org.ow2.frascati.FraSCAti;
import org.ow2.frascati.assembly.factory.Launcher;
import org.ow2.frascati.assembly.factory.RuntimeFactory;
import org.ow2.frascati.bootstrap.FraSCAtiJDT;
import org.ow2.frascati.fscript.FrascatiScriptFactory;
import org.ow2.frascati.util.FrascatiException;
......@@ -239,11 +240,14 @@ public class FrascatiLauncherMojo extends AbstractMojo {
String[] methodParams = getMethodParams();
try {
AssemblyFactory factory = (useFscript) ?
( new FrascatiScriptFactory() )
: ( new RuntimeFactory() );
// TODO must be configurable from pom.xml files.
if(useFscript) {
System.setProperty(FraSCAti.FRASCATI_CLASS_PROPERTY_NAME, FrascatiScriptFactory.class.getCanonicalName());
}
System.setProperty(FraSCAti.FRASCATI_BOOTSTRAP_PROPERTY_NAME, FraSCAtiJDT.class.getCanonicalName());
Launcher launcher = new Launcher(composite, factory);
FraSCAti frascati = FraSCAti.newFraSCAti();
Launcher launcher = new Launcher(composite, frascati);
if ( isEmpty(service) ) { // Run in a server mode
getLog().info("FraSCAti is running in a server mode...");
......
/**
* OW2 FraSCAti Assembly Factory
* OW2 FraSCAti
* Copyright (C) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
......@@ -28,18 +28,18 @@ package org.ow2.frascati.test;
import org.junit.Test;
import org.ow2.frascati.assembly.factory.AssemblyFactory;
import org.ow2.frascati.FraSCAti;
/**
* JUnit test case for OW2 FraSCAti Assembly Factory class.
* JUnit test case for OW2 FraSCAti class.
*
* @author Philippe Merle.
*/
public class AssemblyFactoryTest {
public class FraSCAtiTest {
@Test
public void newAssemblyFactory() throws Exception {
new AssemblyFactory().getFactory();
public void newFraSCAti() throws Exception {
FraSCAti.newFraSCAti();
}
}
......@@ -85,22 +85,17 @@
<artifactId>maven-juliac-plugin</artifactId>