Exemplo n.º 1
0
 private Component wrapWithSynchronousCompositeOfTypeB(int index, Component wrappee)
     throws Exception {
   Component wrapper = Setup.createSynchronousCompositeOfTypeB("sync_composite_b" + index);
   GCM.getContentController(wrapper).addFcSubComponent(wrappee);
   GCM.getBindingController(wrapper).bindFc("i2", wrappee.getFcInterface("i2"));
   return wrapper;
 }
Exemplo n.º 2
0
 private Component wrapWithCompositeOfTypeA(int index, Component wrappee) throws Exception {
   Component wrapper = Setup.createCompositeOfTypeA("composite_a" + index);
   GCM.getContentController(wrapper).addFcSubComponent(wrappee);
   GCM.getBindingController(wrapper).bindFc("i1", wrappee.getFcInterface("i1"));
   GCM.getBindingController(wrappee).bindFc("i2", wrapper.getFcInterface("i2"));
   return wrapper;
 }
  @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);
    }
  }
Exemplo n.º 4
0
  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;
  }
Exemplo n.º 5
0
  @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());
  }
  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();
  }
Exemplo n.º 7
0
 /**
  * Binds a client interface of a GCM component to a web service.
  *
  * @param args The arguments of the procedure call. Must contain as first element the {@link
  *     GCMInterfaceNode} representing the client interface of the GCM component to bind to the web
  *     service and as second element the web service URL to bind to.
  * @param ctx The execution context in which to execute the procedure.
  * @return <code>null</code>.
  * @throws ScriptExecutionError If any error occurred during the execution of the procedure.
  */
 public Object apply(List<Object> args, Context ctx) throws ScriptExecutionError {
   if (args.get(0) instanceof GCMInterfaceNode) {
     Interface clientItf = ((GCMInterfaceNode) args.get(0)).getInterface();
     String wsURL = (String) args.get(1);
     try {
       BindingController bc = GCM.getBindingController(clientItf.getFcItfOwner());
       bc.bindFc(clientItf.getFcItfName(), wsURL);
     } catch (NoSuchInterfaceException nsie) {
       throw new ScriptExecutionError(
           Diagnostic.error(
               SourceLocation.UNKNOWN,
               "Unable to bind interface \'"
                   + clientItf.getFcItfName()
                   + "\' to the web service located at "
                   + wsURL,
               nsie));
     } catch (IllegalBindingException ibe) {
       throw new ScriptExecutionError(
           Diagnostic.error(
               SourceLocation.UNKNOWN,
               "Unable to bind interface \'"
                   + clientItf.getFcItfName()
                   + "\' to the web service located at "
                   + wsURL,
               ibe));
     } catch (IllegalLifeCycleException ilce) {
       throw new ScriptExecutionError(
           Diagnostic.error(
               SourceLocation.UNKNOWN,
               "Unable to bind interface \'"
                   + clientItf.getFcItfName()
                   + "\' to the web service located at "
                   + wsURL,
               ilce));
     }
   }
   return null;
 }
  private void registerMethods() {
    PAActiveObject.setImmediateService(
        "getGCMStatistics",
        new Class[] {String.class, String.class, (new Class<?>[] {}).getClass()});
    PAActiveObject.setImmediateService("getAllGCMStatistics");

    statistics = Collections.synchronizedMap(new HashMap<String, Object>());
    keysList = new HashMap<String, String>();
    NameController nc = null;
    try {
      nc = GCM.getNameController(owner);
    } catch (NoSuchInterfaceException e) {
      e.printStackTrace();
    }
    String name = nc.getFcName();
    Object[] itfs = owner.getFcInterfaces();
    for (int i = 0; i < itfs.length; i++) {
      Interface itf = (Interface) itfs[i];
      InterfaceType itfType = (InterfaceType) itf.getFcItfType();
      try {
        if (!Utils.isControllerItfName(itf.getFcItfName()) && (!itfType.isFcClientItf())) {
          List<MonitorController> subcomponentMonitors = new ArrayList<MonitorController>();
          if (isComposite()) {
            Iterator<Component> bindedComponentsIterator = null;
            if (!((GCMInterfaceType) itfType).isGCMMulticastItf()) {
              List<Component> bindedComponent = new ArrayList<Component>();
              bindedComponent.add(
                  ((PAInterface) ((PAInterface) itf).getFcItfImpl()).getFcItfOwner());
              bindedComponentsIterator = bindedComponent.iterator();
            } else {
              try {
                PAMulticastControllerImpl multicastController =
                    (PAMulticastControllerImpl)
                        ((PAInterface) GCM.getMulticastController(owner)).getFcItfImpl();
                Iterator<PAInterface> delegatee =
                    multicastController.getDelegatee(itf.getFcItfName()).iterator();
                List<Component> bindedComponents = new ArrayList<Component>();
                while (delegatee.hasNext()) {
                  bindedComponents.add(delegatee.next().getFcItfOwner());
                }
                bindedComponentsIterator = bindedComponents.iterator();
              } catch (NoSuchInterfaceException e) {
                e.printStackTrace();
              }
            }
            try {
              while (bindedComponentsIterator.hasNext()) {
                MonitorController monitor =
                    GCM.getMonitorController(bindedComponentsIterator.next());
                monitor.startGCMMonitoring();
                subcomponentMonitors.add(monitor);
              }
            } catch (NoSuchInterfaceException e) {
              e.printStackTrace();
            }
          }
          Class<?> klass =
              ClassLoader.getSystemClassLoader().loadClass(itfType.getFcItfSignature());
          Method[] methods = klass.getDeclaredMethods();
          for (Method m : methods) {
            Class<?>[] parametersTypes = m.getParameterTypes();
            String key =
                PAMonitorControllerHelper.generateKey(
                    itf.getFcItfName(), m.getName(), parametersTypes);
            keysList.put(m.getName(), key);
            if (subcomponentMonitors.isEmpty()) {
              statistics.put(
                  key,
                  new MethodStatisticsPrimitiveImpl(
                      itf.getFcItfName(), m.getName(), parametersTypes));
            } else {
              statistics.put(
                  key,
                  new MethodStatisticsCompositeImpl(
                      itf.getFcItfName(), m.getName(), parametersTypes, subcomponentMonitors));
            }
            controllerLogger.debug(
                m.getName() + " (server) added to monitoring on component " + name + "!!!");
          }
        }
      } catch (ClassNotFoundException e) {
        throw new ProActiveRuntimeException("The interface " + itfType + "cannot be found", e);
      }
    }
  }
  /**
   * 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());
      }
    }
  }