示例#1
0
  /**
   * Read the control token input, transfer input tokens, and invoke prefire() of the selected
   * refinement.
   *
   * @exception IllegalActionException If there is no director, or if the director's prefire()
   *     method throws it, or if this actor is not opaque.
   */
  public boolean prefire() throws IllegalActionException {
    if (_debugging) {
      _debug("Calling prefire()");
    }

    try {
      _workspace.getReadAccess();
      super.prefire();

      Case container = (Case) getContainer();
      // Read from port parameters, including the control port.
      Iterator portParameters = container.attributeList(PortParameter.class).iterator();
      while (portParameters.hasNext()) {
        PortParameter portParameter = (PortParameter) portParameters.next();
        portParameter.update();
      }

      String controlValue = container.control.getToken().toString();
      ComponentEntity refinement = container.getEntity(controlValue);
      if (!(refinement instanceof Refinement)) {
        refinement = container._default;
      }
      container._current = (Refinement) refinement;

      // Transfer input tokens.
      for (Iterator inputPorts = container.inputPortList().iterator();
          inputPorts.hasNext() && !_stopRequested; ) {
        IOPort port = (IOPort) inputPorts.next();

        if (!(port instanceof ParameterPort)) {
          Receiver[][] insideReceivers = port.deepGetReceivers();
          for (int i = 0; i < port.getWidth(); i++) {
            if (port.hasToken(i)) {
              Token token = port.get(i);
              if ((insideReceivers != null) && (insideReceivers[i] != null)) {
                for (int j = 0; j < insideReceivers[i].length; j++) {
                  if (insideReceivers[i][j].getContainer().getContainer() == refinement) {
                    insideReceivers[i][j].put(token);
                    if (_debugging) {
                      _debug(
                          getFullName(),
                          "transferring input from "
                              + port.getFullName()
                              + " to "
                              + (insideReceivers[i][j]).getContainer().getFullName());
                    }
                  }
                }
              }
            }
          }
        }
      }
      if (_stopRequested) {
        return false;
      }
      return container._current.prefire();
    } finally {
      _workspace.doneReading();
    }
  }
示例#2
0
  /**
   * Interconnect all the remote actors in the same manner as the model's topology. In other words,
   * the connections defined by the model's topology are created virtually over the distributed
   * platform. For each actor, a portReceiverMap is created. A portReceiverMap is a data structure
   * representing for a given port the receivers it contains. In case the port is and input port it
   * consists of a set of receivers ID's i.e. (inputport, (ID1, ..., IDn). In case of an outputport,
   * it contains a map of services to receiver's IDs, i.e. (outputport, ((service1, (ID1, ..., IDi),
   * ..., (servicen, (IDj, ..., IDr))). This structure is sent over the network to the corresponding
   * service. The types of the port are also set on the remote actor.
   *
   * @exception IllegalActionException If the remote receivers can't be created.
   */
  private void connectActors() throws IllegalActionException {
    if (VERBOSE) {
      System.out.println("Connecting Actors");
      System.out.println(">> Creating Ports Receivers Map: ");
    }

    for (Iterator keysIterator = actorsThreadsMap.keySet().iterator(); keysIterator.hasNext(); ) {
      ComponentEntity actor = (ComponentEntity) keysIterator.next();

      HashMap portsReceiversMap = new HashMap();
      HashMap portTypes = new HashMap();

      Iterator allPorts = actor.portList().iterator();

      while (allPorts.hasNext()) {
        IOPort currentPort = (IOPort) allPorts.next();
        Receiver[][] receivers = new Receiver[0][0];

        if (currentPort.isOutput()) {
          receivers = currentPort.getRemoteReceivers();
        }

        if (currentPort.isInput()) {
          receivers = currentPort.getReceivers();
        }

        if (!currentPort.connectedPortList().isEmpty()) {
          portTypes.put(currentPort.getName(), ((TypedIOPort) currentPort).getType());
        }

        if (receivers.length > 0) {
          if (VERBOSE) {
            System.out.print(
                "Port: "
                    + currentPort.getFullName()
                    + "\n"
                    + DistributedUtilities.receiversArrayToString(receivers));
          }

          if (currentPort.isOutput()) {
            portsReceiversMap.put(currentPort.getName(), createServicesReceiversMap(receivers));
          }

          if (currentPort.isInput()) {
            portsReceiversMap.put(
                currentPort.getName(), DistributedUtilities.convertReceiversToIntegers(receivers));
          }
        }
      }

      ServiceItem server = ((ClientThread) actorsThreadsMap.get(actor)).getService();
      DistributedActor distributedActor = (DistributedActor) server.service;

      try {
        if (VERBOSE) {
          System.out.println(
              "Setting connections to: "
                  + actor.getFullName()
                  + " in: "
                  + server.serviceID.toString());
          System.out.println(
              "Setting port Types: " + actor.getFullName() + " in: " + server.serviceID.toString());
        }

        distributedActor.setConnections(portsReceiversMap);
        distributedActor.setPortTypes(portTypes);
      } catch (RemoteException e) {
        KernelException.stackTraceToString(e);
      }
    }
  }