@org.junit.Test public void action() throws Exception { initializeComponentSystems(); // System.out.println("testing unwrapped system"); GCM.getGCMLifeCycleController(systemWithoutWrapping).stopFc(); GCM.getGCMLifeCycleController(systemWithoutWrapping).startFc(); result1 = ((I1) systemWithoutWrapping.getFcInterface("i1")).processInputMessage(new Message("foo")); // waiting for the future is only for having an ordered logging output PAFuture.waitFor(result1); Thread.sleep(2000); // System.out.println("testing wrapped system without shortcuts"); GCM.getGCMLifeCycleController(systemWithWrappingWithoutShortcuts).stopFc(); GCM.getGCMLifeCycleController(systemWithWrappingWithoutShortcuts).startFc(); result2 = ((I1) systemWithWrappingWithoutShortcuts.getFcInterface("i1")) .processInputMessage(new Message("foo")); PAFuture.waitFor(result2); Thread.sleep(2000); // System.out.println("testing wrapped system with shortcuts -- fist invocation"); // first call, which performs tensioning result3 = ((I1) systemWithWrappingWithShortcuts.getFcInterface("i1")) .processInputMessage(new Message("foo")); PAFuture.waitFor(result3); Thread.sleep(2000); GCM.getGCMLifeCycleController(systemWithWrappingWithShortcuts).stopFc(); GCM.getGCMLifeCycleController(systemWithWrappingWithShortcuts).startFc(); // second call, which goes directly through the shortcut // System.out.println("testing wrapped system with shortcuts -- second invocation"); result4 = ((I1) systemWithWrappingWithShortcuts.getFcInterface("i1")) .processInputMessage(new Message("foo")); PAFuture.waitFor(result4); Thread.sleep(2000); // TODO manage shortcuts with reconfigurations // reset while shortcut exists // resetComponentSystem(); // initializeComponentSystems(); // first call, which performs tensioning // result5 = ((I1) // systemWithWrappingWithShortcuts.getFcInterface("i1")).processInputMessage(new // Message("foo")); // a shortcut is now realized. Compare with previous result // result6 = ((I1) // systemWithWrappingWithShortcuts.getFcInterface("i1")).processInputMessage(new // Message("foo")); Assert.assertEquals(expectedResult, (PAFuture.getFutureValue(result4)).getMessage()); Assert.assertEquals(expectedResult, (PAFuture.getFutureValue(result3)).getMessage()); Assert.assertEquals(expectedResult, (PAFuture.getFutureValue(result2)).getMessage()); Assert.assertEquals(expectedResult, (PAFuture.getFutureValue(result1)).getMessage()); }
@org.junit.Before public void deployHelloWorldComponent() { try { url = AbstractWebServicesFactory.getLocalUrl(); Component boot = Utils.getBootstrapComponent(); GCMTypeFactory tf = GCM.getGCMTypeFactory(boot); GenericFactory cf = GCM.getGenericFactory(boot); ComponentType typeComp = tf.createFcType( new InterfaceType[] { tf.createFcItfType( "hello-world", HelloWorldItf.class.getName(), false, false, false), tf.createFcItfType( "good-bye-world", GoodByeWorldItf.class.getName(), false, false, false) }); String controllersConfigFileLocation = AbstractPAWebServicesControllerImpl.getControllerFileUrl("cxf").getPath(); ControllerDescription cd = new ControllerDescription( "composite", Constants.PRIMITIVE, controllersConfigFileLocation); comp = cf.newFcInstance( typeComp, cd, new ContentDescription(HelloWorldComponent.class.getName(), null)); GCM.getGCMLifeCycleController(comp).startFc(); // Deploying the service in the Active Object way WebServicesFactory wsf = AbstractWebServicesFactory.getWebServicesFactory("cxf"); ws = wsf.getWebServices(url); ws.exposeComponentAsWebService(comp, "server", new String[] {"hello-world"}); ws.exposeComponentAsWebService(comp, "server2"); // Deploying the service using the web service controller wsc = org.objectweb.proactive.extensions.webservices.component.Utils.getPAWebServicesController( comp); wsc.initServlet(); wsc.setUrl(url); wsc.exposeComponentAsWebService("server3", new String[] {"hello-world"}); wsc.exposeComponentAsWebService("server4"); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }
private void initializeComponentSystems() throws Exception { // system without wrapped components Component unwrappedA = Setup.createPrimitiveA(); Component unwrappedB = Setup.createPrimitiveB1(); GCM.getBindingController(unwrappedA).bindFc("i2", unwrappedB.getFcInterface("i2")); GCM.getGCMLifeCycleController(unwrappedA).startFc(); GCM.getGCMLifeCycleController(unwrappedB).startFc(); systemWithoutWrapping = unwrappedA; // system with wrapping but without shortcuts Component wrappedAWithoutShortcuts = Setup.createPrimitiveA(); for (int i = 0; i < NB_WRAPPERS; i++) { wrappedAWithoutShortcuts = wrapWithCompositeOfTypeA(NB_WRAPPERS - i, wrappedAWithoutShortcuts); } Component wrappedBWithoutShortcuts = Setup.createPrimitiveB1(); for (int i = 0; i < NB_WRAPPERS; i++) { wrappedBWithoutShortcuts = wrapWithCompositeOfTypeB(NB_WRAPPERS - i, wrappedBWithoutShortcuts); } GCM.getBindingController(wrappedAWithoutShortcuts) .bindFc("i2", wrappedBWithoutShortcuts.getFcInterface("i2")); GCM.getGCMLifeCycleController(wrappedAWithoutShortcuts).startFc(); GCM.getGCMLifeCycleController(wrappedBWithoutShortcuts).startFc(); systemWithWrappingWithoutShortcuts = wrappedAWithoutShortcuts; // system with wrapping and with shortcuts Component wrappedAWithShortcuts = Setup.createPrimitiveA(); for (int i = 0; i < NB_WRAPPERS; i++) { wrappedAWithShortcuts = wrapWithSynchronousCompositeOfTypeA(NB_WRAPPERS - i, wrappedAWithShortcuts); } Component wrappedBWithShortcuts = Setup.createPrimitiveB1(); for (int i = 0; i < NB_WRAPPERS; i++) { wrappedBWithShortcuts = wrapWithSynchronousCompositeOfTypeB(NB_WRAPPERS - i, wrappedBWithShortcuts); } GCM.getBindingController(wrappedAWithShortcuts) .bindFc("i2", wrappedBWithShortcuts.getFcInterface("i2")); GCM.getGCMLifeCycleController(wrappedAWithShortcuts).startFc(); GCM.getGCMLifeCycleController(wrappedBWithShortcuts).startFc(); systemWithWrappingWithShortcuts = wrappedAWithShortcuts; }
public static void main(String[] args) throws ADLException, IllegalLifeCycleException, NoSuchInterfaceException, ProActiveException, DistributedEtalisException, IOException { CentralPAPropertyRepository.JAVA_SECURITY_POLICY.setValue("proactive.java.policy"); CentralPAPropertyRepository.GCM_PROVIDER.setValue( "org.objectweb.proactive.core.component.Fractive"); // Start component. Factory factory = FactoryFactory.getFactory(); HashMap<String, Object> context = new HashMap<String, Object>(); Component root = (Component) factory.newComponent("DistributedEtalis", context); GCM.getGCMLifeCycleController(root).startFc(); // Register component. Registry registry = LocateRegistry.getRegistry(); Fractive.registerByName(root, "dEtalis1"); // Configure component. ConfigApi configApi = ((ConfigApi) root.getFcInterface(ConfigApi.class.getSimpleName())); configApi.setConfig(new DetalisConfigLocal("play-epsparql-clic2call-historical-data.trig")); // Subscribe to print complex events to local console. // testApi = ((eu.play_project.dcep.distributedetalis.api.DistributedEtalisTestApi) // root.getFcInterface(DistributedEtalisTestApi.class.getSimpleName())); // try { // subscriber = PAActiveObject.newActive(ComplexEventSubscriber.class, new Object[] {}); // } catch (ActiveObjectCreationException e) { // e.printStackTrace(); // } catch (NodeException e) { // e.printStackTrace(); // } // testApi.attach(subscriber); System.out.println("Press 3x RETURN to shutdown the application"); System.in.read(); System.in.read(); System.in.read(); }
/** * Runs the activity as defined in @see ComponentRunActive. The default behaviour is to serve * non-functional requests in FIFO order, until the component is started. Then the functional * activity (as defined in @see InitActive, @see RunActive and @see EndActive) begins. * * <p>When redefining the @see RunActive#runActivity(Body) method, the @see Body#isActive() * returns true as long as the lifecycle of the component is @see LifeCycleController#STARTED. * When the lifecycle of the component is @see LifeCycleController#STOPPED, @see Body#isActive() * returns false. */ @Override public void runActivity(Body body) { if ((componentRunActive != null) && (componentRunActive != this)) { componentRunActive.runActivity(body); } else { // this is the default activity of the active object // the activity of the component has been initialized and started, now // what we have to do is to manage the life cycle, i.e. start and stop the // activity // that can be redefined on the reified object. try { Service componentService = new Service(body); NFRequestFilterImpl nfRequestFilter = new NFRequestFilterImpl(); MembraneControllerRequestFilter memRequestFilter = new MembraneControllerRequestFilter(); while (body.isActive()) { ComponentBody componentBody = (ComponentBody) body; /* * While the membrane is stopped, serve calls only on the Membrane Controller */ while (Utils.getPAMembraneController(componentBody.getPAComponentImpl()) .getMembraneState() .equals(PAMembraneController.MEMBRANE_STOPPED)) { componentService.blockingServeOldest(memRequestFilter); } while (LifeCycleController.STOPPED.equals( GCM.getGCMLifeCycleController(componentBody.getPAComponentImpl()).getFcState())) { PriorityController pc = GCM.getPriorityController(componentBody.getPAComponentImpl()); NF3RequestFilter nf3RequestFilter = new NF3RequestFilter(pc); if (componentService.getOldest(nf3RequestFilter) != null) { // NF3 bypass all other request // System.err.println( // "STOPPED ComponentActivity : NF3"); componentService.blockingServeOldest(nf3RequestFilter); } else { componentService.blockingServeOldest(nfRequestFilter); } if (!body.isActive()) { // in case of a migration break; } } if (!body.isActive()) { // in case of a migration break; } // 3.1. init object Activity // life cycle started : starting activity of the object if (functionalInitActive != null) { functionalInitActive.initActivity(body); // functionalInitActive = null; // we won't do it again } ((ComponentBody) body).startingFunctionalActivity(); // 3.2 while object activity // componentServe (includes filter on priority) functionalRunActive.runActivity(body); ((ComponentBody) body).finishedFunctionalActivity(); if (functionalEndActive != null) { functionalEndActive.endActivity(body); } /* * While the membrane is started, serve non-functional calls with priority (the * same as for Lifecycle Stopped) */ while (Utils.getPAMembraneController(componentBody.getPAComponentImpl()) .getMembraneState() .equals(PAMembraneController.MEMBRANE_STARTED)) { PriorityController pc = GCM.getPriorityController(componentBody.getPAComponentImpl()); NF3RequestFilter nf3RequestFilter = new NF3RequestFilter(pc); if (componentService.getOldest(nf3RequestFilter) != null) { // NF3 bypass all other request // System.err.println( // "STOPPED ComponentActivity : NF3"); componentService.blockingServeOldest(nf3RequestFilter); } else { componentService.blockingServeOldest(nfRequestFilter); } if (!body.isActive()) { // Don't know if this is OK // in case of a migration break; } } } } catch (NoSuchInterfaceException e) { logger.error( "could not retreive an interface, probably the life cycle controller of this component; terminating the component. Error message is : " + e.getMessage()); } } }