Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
frascati
frascati
Commits
a9b25716
Commit
a9b25716
authored
Mar 08, 2013
by
Philippe Merle
Browse files
Added a new example illustrating how to reconfigure a reference with multiplicity 0..N.
parent
f9542b9d
Changes
6
Hide whitespace changes
Inline
Side-by-side
examples/runners/README.txt
0 → 100644
View file @
a9b25716
============================================================================
OW2 FraSCAti Examples: Runners
Copyright (C) 2013 Inria, University of Lille 1
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: Philippe Merle
Contributor(s):
============================================================================
Runners:
--------
This example illustrates how to reconfigure a reference with multiplicity 0..N.
Compilation with Maven:
-----------------------
mvn install
Execution with Maven:
---------------------
mvn -Prun (standalone execution)
mvn -Pexplorer (with FraSCAti Explorer)
mvn -Pexplorer-fscript (with FraSCAti Explorer and FScript plugin)
mvn -Pfscript-console (with FraSCAti FScript Console)
mvn -Pfscript-console-explorer (with FraSCAti Explorer and FScript Console)
mvn -Pexplorer-jdk6 (with FraSCAti Explorer and JDK6)
examples/runners/pom.xml
0 → 100644
View file @
a9b25716
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: Runners
*
* Copyright (c) 2013 Inria, University of Lille 1
*
* 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: Philippe Merle
*
* Contributor(s):
-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.ow2.frascati.examples
</groupId>
<artifactId>
parent
</artifactId>
<version>
1.5-SNAPSHOT
</version>
</parent>
<artifactId>
runners
</artifactId>
<packaging>
jar
</packaging>
<name>
OW2 FraSCAti Examples: Runners
</name>
<properties>
<composite.file>
runners
</composite.file>
<service.name>
Runnable
</service.name>
<method.name>
run
</method.name>
</properties>
<dependencies>
<dependency>
<groupId>
org.ow2.frascati
</groupId>
<artifactId>
frascati-binding-ws
</artifactId>
<version>
${frascati.version}
</version>
</dependency>
</dependencies>
</project>
examples/runners/src/main/java/org/ow2/frascati/examples/runners/Runner.java
0 → 100644
View file @
a9b25716
/**
* OW2 FraSCAti Examples: Runners
* Copyright (C) 2013 Inria, University of Lille 1
*
* 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: Philippe Merle
*
* Contributor(s):
*
*/
package
org.ow2.frascati.examples.runners
;
import
org.oasisopen.sca.annotation.ComponentName
;
import
org.oasisopen.sca.annotation.Scope
;
import
org.oasisopen.sca.annotation.Service
;
@Scope
(
"COMPOSITE"
)
@Service
(
Runnable
.
class
)
public
class
Runner
implements
Runnable
{
/**
* The name of the SCA component.
*/
@ComponentName
protected
String
componentName
;
public
void
run
()
{
System
.
out
.
println
(
"Runner(name="
+
this
.
componentName
+
") runs."
);
}
}
examples/runners/src/main/java/org/ow2/frascati/examples/runners/RunnerMultiple.java
0 → 100644
View file @
a9b25716
/**
* OW2 FraSCAti Examples: Runners
* Copyright (C) 2013 Inria, University of Lille 1
*
* 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: Philippe Merle
*
* Contributor(s):
*
*/
package
org.ow2.frascati.examples.runners
;
import
org.objectweb.fractal.fraclet.annotations.Lifecycle
;
import
org.objectweb.fractal.fraclet.types.Step
;
import
org.oasisopen.sca.annotation.Init
;
import
org.oasisopen.sca.annotation.Service
;
import
org.oasisopen.sca.annotation.Reference
;
@Service
(
Runnable
.
class
)
// TODO: This annotation should be removed as already defined into class Runner.
public
class
RunnerMultiple
extends
Runner
{
/**
* Method called at the end of the initialization of the SCA component.
*/
@Init
public
void
init
()
{
System
.
out
.
println
(
"INIT on component "
+
this
.
componentName
);
}
/**
* Method called each time Fractal LifecycleController startFc() is invoked.
*/
@Lifecycle
(
step
=
Step
.
START
)
public
void
start
()
{
System
.
out
.
println
(
"START on component "
+
this
.
componentName
);
}
private
java
.
util
.
List
<
Runnable
>
runnables
;
/**
* Method called to set the reference 'runnables'.
*/
@Reference
(
name
=
"runnables"
)
public
void
setRunnables
(
java
.
util
.
List
<
Runnable
>
runnables
)
{
System
.
out
.
println
(
"SET reference 'runnables' of component "
+
this
.
componentName
+
" with a list of "
+
runnables
.
size
()
+
" elements."
);
this
.
runnables
=
runnables
;
}
/**
* Method called each time Fractal BindingController bindFc("runnablesXXX", o) is invoked.
*/
public
java
.
util
.
List
<
Runnable
>
getRunnables
()
{
System
.
out
.
println
(
"GET reference 'runnables' of "
+
this
.
componentName
+
"."
);
return
this
.
runnables
;
}
@Override
public
void
run
()
{
super
.
run
();
for
(
Runnable
runnable
:
this
.
runnables
)
{
runnable
.
run
();
}
}
}
examples/runners/src/main/resources/runners.composite
0 → 100755
View file @
a9b25716
<?xml version="1.0" encoding="UTF-8"?>
<!-- OW2 FraSCAti Examples: Runners -->
<!-- Copyright (C) 2013 Inria, University of Lille 1 -->
<!-- -->
<!-- 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: Philippe Merle -->
<!-- -->
<!-- Contributor(s): -->
<!-- -->
<sca:composite
xmlns:sca=
"http://www.osoa.org/xmlns/sca/1.0"
name=
"runners"
>
<sca:service
name=
"Runnable"
promote=
"RunnerMultiple/Runnable"
/>
<sca:component
name=
"RunnerMultiple"
>
<sca:implementation.java
class=
"org.ow2.frascati.examples.runners.RunnerMultiple"
/>
<sca:reference
name=
"runnables"
multiplicity=
"0..n"
target=
"A/Runnable B/Runnable C/Runnable"
>
<sca:interface.java
interface=
"java.lang.Runnable"
/>
</sca:reference>
</sca:component>
<sca:component
name=
"A"
>
<sca:implementation.java
class=
"org.ow2.frascati.examples.runners.Runner"
/>
</sca:component>
<sca:component
name=
"B"
>
<sca:implementation.java
class=
"org.ow2.frascati.examples.runners.Runner"
/>
</sca:component>
<sca:component
name=
"C"
>
<sca:implementation.java
class=
"org.ow2.frascati.examples.runners.Runner"
/>
</sca:component>
<sca:component
name=
"D"
>
<sca:implementation.java
class=
"org.ow2.frascati.examples.runners.Runner"
/>
<sca:service
name=
"Runnable"
>
<sca:binding.ws
uri=
"/D"
/>
</sca:service>
</sca:component>
</sca:composite>
examples/runners/src/test/java/org/ow2/frascati/examples/runners/test/RunnerTest.java
0 → 100644
View file @
a9b25716
/**
* OW2 FraSCAti Examples: Runners
* Copyright (C) 2013 Inria, University of Lille 1
*
* 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: Philippe Merle
*
* Contributor(s):
*
*/
package
org.ow2.frascati.examples.runners.test
;
import
org.junit.Test
;
import
org.objectweb.fractal.api.Component
;
import
org.objectweb.fractal.bf.BindingFactory
;
import
org.objectweb.fractal.util.Fractal
;
import
org.ow2.frascati.FraSCAti
;
public
class
RunnerTest
{
@Test
public
void
runnerReconfiguration
()
throws
Exception
{
// Initialize FraSCAti.
FraSCAti
frascati
=
FraSCAti
.
newFraSCAti
();
// Load the SCA composite 'runners'.
Component
composite
=
frascati
.
getComposite
(
"runners.composite"
);
// Obtain its Runnable service.
Runnable
runnable
=
frascati
.
getService
(
composite
,
"Runnable"
,
Runnable
.
class
);
// RunnerMultiple, A, B, and C components will be invoked.
runnable
.
run
();
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
System
.
out
.
println
();
}
// Search components named 'RunnerMultiple' and 'D'.
Component
componentRunnerMultiple
=
null
;
Component
componentD
=
null
;
// Iterate over all sub components of the loaded composite.
for
(
Component
component
:
Fractal
.
getContentController
(
composite
).
getFcSubComponents
())
{
// Get the name of the current sub component.
String
componentName
=
Fractal
.
getNameController
(
component
).
getFcName
();
if
(
"RunnerMultiple"
.
equals
(
componentName
))
{
componentRunnerMultiple
=
component
;
}
if
(
"D"
.
equals
(
componentName
))
{
componentD
=
component
;
}
}
// Get the Runnable service of component D.
Runnable
runnableD
=
(
Runnable
)
componentD
.
getFcInterface
(
"Runnable"
);
// TODO: This is strange: bindFc() could be invoked without calling stopFc() before.
// Fractal.getLifeCycleController(componentRunnerMultiple).stopFc();
// Connect the 'runnables' reference of the RunnerMultiple component to the 'Runnable' service of the component D.
Fractal
.
getBindingController
(
componentRunnerMultiple
).
bindFc
(
"runnables-D"
,
runnableD
);
// Fractal.getLifeCycleController(componentRunnerMultiple).startFc();
// RunnerMultiple, A, B, C, and D components will be invoked.
runnable
.
run
();
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
System
.
out
.
println
();
}
// Get the FraSCAti Binding Factory.
BindingFactory
bf
=
(
BindingFactory
)
frascati
.
getFrascatiComposite
().
getFcInterface
(
"binding-factory"
);
// Hints for creating a Web Service binding.
java
.
util
.
Map
<
String
,
Object
>
hints
=
new
java
.
util
.
HashMap
<
String
,
Object
>();
hints
.
put
(
"plugin.id"
,
"ws"
);
// TODO: This hint should be removed to simplify the usage of the FraSCAti Binding Factory.
hints
.
put
(
"classloader"
,
this
.
getClass
().
getClassLoader
());
hints
.
put
(
"uri"
,
"http://localhost:8765/D"
);
// TODO: This is strange: bind() could be invoked without calling stopFc() before.
// Fractal.getLifeCycleController(componentRunnerMultiple).stopFc();
// Bind the runnables reference to a Web Service.
bf
.
bind
(
componentRunnerMultiple
,
"runnables-D-WS-1"
,
hints
);
// Fractal.getLifeCycleController(componentRunnerMultiple).startFc();
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
System
.
out
.
println
();
}
// TODO: This is strange: bind() could be invoked without calling stopFc() before.
// Fractal.getLifeCycleController(componentRunnerMultiple).stopFc();
// Bind the runnables reference to a Web Service.
bf
.
bind
(
componentRunnerMultiple
,
"runnables-D-WS-2"
,
hints
);
// Fractal.getLifeCycleController(componentRunnerMultiple).startFc();
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
System
.
out
.
println
();
}
// RunnerMultiple, A, B, C, D, D, and D will be invoked.
// D is invoked three times as it was bound three times but with three different binding names.
runnable
.
run
();
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
System
.
out
.
println
();
}
frascati
.
close
(
composite
);
frascati
.
close
();
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment