/** @param componentType */
  private void addFunctionalInterfaces() {
    InterfaceType[] itfTypes = this.componentParameters.getComponentType().getFcInterfaceTypes();
    this.fItfs = new HashMap<String, Interface>(itfTypes.length + (itfTypes.length / 2));

    try {
      for (int j = 0; j < itfTypes.length; j++) {
        if (!itfTypes[j].isFcCollectionItf()) {
          // itfs members of collection itfs are dynamically generated
          Interface interface_reference =
              RepresentativeInterfaceClassGenerator.instance()
                  .generateFunctionalInterface(
                      itfTypes[j].getFcItfName(), this, (PAGCMInterfaceType) itfTypes[j]);

          // all calls are to be reified
          if (interface_reference != null) {
            this.fItfs.put(interface_reference.getFcItfName(), interface_reference);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException("cannot create interface references : " + e.getMessage());
    }
  }
Beispiel #2
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);
      }
    }
  }