org.objectweb.proactive.examples.components.userguide.starter.Service
package org.objectweb.proactive.examples.components.userguide.starter; public interface Service { public void print(String msg); }
org.objectweb.proactive.examples.components.userguide.starter.ServerImpl
package org.objectweb.proactive.examples.components.userguide.starter; public class ServerImpl implements Service { public void print(String msg) { System.err.println("=> Server: " + msg); } }
org.objectweb.proactive.examples.components.userguide.starter.Server.fractal
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE definition PUBLIC "-//objectweb.org//DTD Fractal ADL 2.0//EN"
"classpath://org/objectweb/proactive/core/component/adl/xml/proactive.dtd">
<definition name="org.objectweb.proactive.examples.components.userguide.starter.Server">
<interface name="s" role="server" signature=
"org.objectweb.proactive.examples.components.userguide.starter.Service"/>
<content class="org.objectweb.proactive.examples.components.userguide.starter.ServerImpl"/>
<controller desc="primitive"/>
</definition>
org.objectweb.proactive.examples.components.userguide.starter.ClientImpl.java
package org.objectweb.proactive.examples.components.userguide.starter; import org.objectweb.fractal.api.control.BindingController; public class ClientImpl implements Runnable, BindingController { private Service service; public ClientImpl() { // the following instruction was removed, because ProActive requires empty no-args constructors // otherwise this instruction is executed also at the construction of the stub //System.err.println("CLIENT created"); } public void run() { System.err.println("---- Calling service method ----"); service.print("hello world"); } public String[] listFc() { return new String[] { "s" }; } public Object lookupFc(final String cItf) { if (cItf.equals("s")) { return service; } return null; } public void bindFc(final String cItf, final Object sItf) { if (cItf.equals("s")) { service = (Service) sItf; } } public void unbindFc(final String cItf) { if (cItf.equals("s")) { service = null; } } }
org.objectweb.proactive.examples.components.userguide.starter.Client.fractal
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE definition PUBLIC "-//objectweb.org//DTD Fractal ADL 2.0//EN"
"classpath://org/objectweb/proactive/core/component/adl/xml/proactive.dtd">
<definition name="org.objectweb.proactive.examples.components.userguide.starter.Client">
<interface name="m" role="server" signature="java.lang.Runnable"/>
<interface name="s" role="client" signature=
"org.objectweb.proactive.examples.components.userguide.starter.Service"/>
<content class="org.objectweb.proactive.examples.components.userguide.starter.ClientImpl"/>
<controller desc="primitive"/>
</definition>
org.objectweb.proactive.examples.components.userguide.starter.Main.java
package org.objectweb.proactive.examples.components.userguide.starter; import java.util.HashMap; import org.objectweb.fractal.adl.Factory; import org.objectweb.fractal.api.Component; import org.objectweb.fractal.api.control.BindingController; import org.objectweb.fractal.util.Fractal; import org.objectweb.proactive.core.component.adl.FactoryFactory; import org.objectweb.proactive.core.component.adl.Registry; import org.objectweb.proactive.core.config.PAProperties; import org.objectweb.proactive.extensions.gcmdeployment.PAGCMDeployment; import org.objectweb.proactive.gcmdeployment.GCMApplication; public class Main { public static void main(String[] args) throws Exception { PAProperties.FRACTAL_PROVIDER.setValue("org.objectweb.proactive.core.component.Fractive"); GCMApplication gcma = PAGCMDeployment .loadApplicationDescriptor(Main.class .getResource( "/org/objectweb/proactive/examples/components/userguide/starter/applicationDescriptor.xml")); gcma.startDeployment(); Factory factory = FactoryFactory.getFactory(); HashMap<String, GCMApplication> context = new HashMap<String, GCMApplication>(1); context.put("deployment-descriptor", gcma); // creates server component Component server = (Component) factory.newComponent( "org.objectweb.proactive.examples.components.userguide.starter.Server", context); // creates client component Component client = (Component) factory.newComponent( "org.objectweb.proactive.examples.components.userguide.starter.Client", context); // bind components BindingController bc = ((BindingController) client.getFcInterface("binding-controller")); bc.bindFc("s", server.getFcInterface("s")); // start components Fractal.getLifeCycleController(server).startFc(); Fractal.getLifeCycleController(client).startFc(); // launch the application ((Runnable) client.getFcInterface("m")).run(); // stop components Fractal.getLifeCycleController(client).stopFc(); Fractal.getLifeCycleController(server).stopFc(); Registry.instance().clear(); gcma.kill(); } }
org.objectweb.proactive.examples.components.userguide.starter.deploymentDescriptor.xml
<?xml version="1.0" encoding="UTF-8"?>
<GCMDeployment xmlns="urn:gcm:deployment:1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:gcm:deployment:1.0
http://proactive.inria.fr/schemas/gcm/1.0/ExtensionSchemas.xsd ">
<environment>
<javaPropertyVariable name="user.home"/>
</environment>
<resources>
<host refid="localhost"/>
</resources>
<infrastructure>
<hosts>
<host id="localhost" os="unix" hostCapacity="1" vmCapacity="2">
<homeDirectory base="root" relpath="${user.home}" />
</host>
</hosts>
</infrastructure>
</GCMDeployment>
org.objectweb.proactive.examples.components.userguide.starter.applicationDescriptor.xml
<?xml version="1.0" encoding="UTF-8"?> <GCMApplication xmlns="urn:gcm:application:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:gcm:application:1.0 http://proactive.inria.fr/schemas/gcm/1.0/ApplicationDescriptorSchema.xsd"> <environment> <javaPropertyVariable name="proactive.home" /> <javaPropertyVariable name="java.home" /> <javaPropertyVariable name="user.dir" /> </environment> <application> <proactive base="root" relpath="${proactive.home}"> <configuration> <java base="root" relpath="${java.home}/bin/java"/> <proactiveClasspath type="append"> <pathElement base="proactive" relpath="classes/Examples"/> <pathElement base="proactive" relpath="dist/lib/clover.jar"/> </proactiveClasspath> </configuration> <virtualNode id="VN"> <nodeProvider refid="main-VN" /> </virtualNode> </proactive> </application> <resources> <nodeProvider id="main-VN"> <file path="deploymentDescriptor.xml" /> </nodeProvider> </resources> </GCMApplication>
© 1997-2008 INRIA Sophia Antipolis All Rights Reserved