/** Override the base class to call stopFire() on the referenced model. */
  public void stopFire() {
    if (_model instanceof Executable) {
      ((Executable) _model).stopFire();
    }

    super.stopFire();
  }
  /** Override the base class to call terminate() on the referenced model. */
  public void terminate() {
    if (_model instanceof Executable) {
      ((Executable) _model).terminate();
    }

    super.terminate();
  }
Beispiel #3
0
  /**
   * Initialize the integrator. Check for the existence of a director and an ODE solver. Set the
   * state to the value given by <i>initialState</i>.
   *
   * @exception IllegalActionException If there is no director, or the director has no ODE solver,
   *     or the initialState parameter does not contain a valid token, or the superclass throws it.
   */
  public void initialize() throws IllegalActionException {
    ContinuousDirector dir = (ContinuousDirector) getDirector();

    if (dir == null) {
      throw new IllegalActionException(this, " no director available");
    }

    ContinuousODESolver solver = dir._getODESolver();

    if (solver == null) {
      throw new IllegalActionException(this, " no ODE solver available");
    }

    super.initialize();
    _lastRound = -1;
    _tentativeState = ((DoubleToken) initialState.getToken()).doubleValue();
    _state = _tentativeState;

    if (_debugging) {
      _debug("Initialize: initial state = " + _tentativeState);
    }

    // The number of auxiliary variables that are used depends on
    // the solver.
    int n = solver.getIntegratorAuxVariableCount();
    if ((_auxVariables == null) || (_auxVariables.length != n)) {
      _auxVariables = new double[n];
    }
  }
Beispiel #4
0
  /**
   * Read one RecordToken from the input port and send its fields to the output ports. If the input
   * does not have a token, suspend firing and return.
   *
   * @exception IllegalActionException If there is no director.
   */
  public void fire() throws IllegalActionException {
    super.fire();
    Director director = getDirector();

    if (director == null) {
      throw new IllegalActionException(this, "No director!");
    }

    if (input.hasToken(0)) {
      RecordToken record = (RecordToken) input.get(0);
      Iterator labels = record.labelSet().iterator();

      while (labels.hasNext()) {
        String label = (String) labels.next();
        Token value = record.get(label);
        IOPort port = (IOPort) getPort(label);

        // since the record received may contain more fields than the
        // output ports, some fields may not have a corresponding
        // output port.
        if (port != null) {
          port.send(0, value);
        }
      }
    }
  }
Beispiel #5
0
  public void fire() throws IllegalActionException {
    super.fire();

    try {
      if (trigQuery.hasToken(0)) {
        trigQuery.get(0);

        System.out.println("Send peer discovery message...");

        // send a query message that is
        // - propagated within the group
        // - for peer discovery
        // - no attribute/value matching
        // - each response contains at most 5 peers
        _discoveryService.getRemoteAdvertisements(null, DiscoveryService.PEER, null, null, 5);

        System.out.println("Send actor query message...");
        _actorQueryMessage.setQueryId(_actorQueryMessage.getQueryId() + 1);
        _resolverService.sendQuery(null, _actorQueryMessage);
      }

      if (_inToken != null) {
        queryResult.send(0, _inToken);
        _inToken = null;
        System.out.println("send data ");
      }
    } catch (Exception e) {
      System.out.println("Error : " + e);
    }
  }
  public void pruneDependencies() {
    super.pruneDependencies();

    removeDependency(trigger, emmode);
    removeDependency(shutdown, emmode);
    removeDependency(emstop_input, emmode);
  }
Beispiel #7
0
 /**
  * Initialize.
  *
  * @exception IllegalActionException If a derived class throws it.
  */
 public void initialize() throws IllegalActionException {
   super.initialize();
   _readThread = null;
   _postfireReturns = true;
   // Force reinitialization of the pool.
   attributeChanged(initialPool);
 }
  @Override
  public void fire() throws IllegalActionException {
    super.fire();
    Token t = input.get(0);

    if (r.nextInt(100) > Integer.parseInt(discardage.getValueAsString())) output.send(0, t);
  }
Beispiel #9
0
  /** Initialize state-holding variables */
  public void initialize() throws IllegalActionException {
    super.initialize();

    // OST por aqui
    lastFired = inputreq[0];

    for (int i = 0; i < 5; i++) {
      state[i] = 0;
    }

    for (int i = 0; i < 5; i++) {
      freeoutput[i] = true;
    }

    for (int i = 0; i < 5; i++) {
      txack[i] = false;
    }

    // check whether requesting ports have connections
    // if positive, set state to REQUESTING

    for (int i = 0; i < 5; i++) {
      if (inputreq[i].getWidth() > 0) {
        state[i] = REQUESTING;
      }
    }
  }
Beispiel #10
0
  /**
   * If the specified attribute is <i>SNRThresholdInDB</i>, or <i>powerThreshold</i> then check that
   * a non-negative number is given. Otherwise, defer to the base class.
   *
   * @param attribute The attribute that changed.
   * @exception IllegalActionException If the change is not acceptable to this container.
   */
  public void attributeChanged(Attribute attribute) throws IllegalActionException {
    if (attribute == SNRThresholdInDB) {
      double SNRThresholdInDBValue = ((DoubleToken) SNRThresholdInDB.getToken()).doubleValue();

      if (SNRThresholdInDBValue <= 0.0) {
        throw new IllegalActionException(
            this,
            "SNRThresholdInDB is required to be positive. "
                + "Attempt to set it to: "
                + SNRThresholdInDBValue);
      } else {
        // Convert to linear scale.
        _SNRThresholdInDB = Math.pow(10, SNRThresholdInDBValue / 10);
      }
    } else if (attribute == powerThreshold) {
      _powerThreshold = ((DoubleToken) powerThreshold.getToken()).doubleValue();

      if (_powerThreshold < 0.0) {
        throw new IllegalActionException(
            this,
            "powerThreshold is required to be nonnegative. "
                + "Attempt to set it to: "
                + _powerThreshold);
      }
    } else {
      super.attributeChanged(attribute);
    }
  }
Beispiel #11
0
 /**
  * If the specified attribute is <i>initialState</i>, then reset the state of the integrator to
  * its value.
  *
  * @param attribute The attribute that has changed.
  * @exception IllegalActionException If the new parameter value is not valid.
  */
 public void attributeChanged(Attribute attribute) throws IllegalActionException {
   if (attribute == initialState) {
     _tentativeState = ((DoubleToken) initialState.getToken()).doubleValue();
     _state = _tentativeState;
   } else {
     super.attributeChanged(attribute);
   }
 }
  /**
   * Override the setContainer() method to call wrapup() if container is not equal to the result of
   * getContainer(). If this method did not override super.setContainer(), then when the actor is
   * deleted while the model is running, wrapup() would never get called.
   */
  public void setContainer(CompositeEntity container)
      throws IllegalActionException, NameDuplicationException {
    if (container != getContainer()) {
      wrapup();
    }

    super.setContainer(container);
  }
Beispiel #13
0
 /**
  * React to a change in an attribute.
  *
  * @param attribute The changed parameter.
  * @exception IllegalActionException If the parameter set is not valid.
  */
 public void attributeChanged(Attribute attribute) throws IllegalActionException {
   String tmp = null;
   if (attribute == serverName) {
     // --------------    the user has changed serverName -----------
     String strServerName = serverName.getExpression();
     if (_serverNameString == null) {
       // the value is loaded from the moml file
       // don't cal the _createSubmission
       _serverNameString = strServerName;
       log.info("_serverNameString is set according to original value of moml file.");
       if (!strServerName.equals("")) {
         _appMetadata = AppMetadataParser.parseAppMetadata(strServerName);
         if (_appMetadata == null) {
           // something bad happen while getting the appMetadata
           log.error("Failed to parse metadata at " + strServerName);
           throw new IllegalActionException(
               this, "The selected URL does not point to a valid Opal service");
         }
       }
     } else if (!strServerName.equals(_serverNameString)) {
       // the user changed the value, we have to update the actor
       log.info("Got a new server name: " + strServerName);
       _appMetadata = AppMetadataParser.parseAppMetadata(strServerName);
       if (_appMetadata != null) {
         if (_appMetadata.isArgMetadataEnable())
           // complex submission form
           _createSubmission(_appMetadata);
         else
           // simple submission form
           _createSimpleSubmission(_appMetadata);
         _addDocumentation(_appMetadata);
       } else {
         // something bad happen while getting the appMetadata
         log.error("Failed to parse metadata at " + strServerName);
         throw new IllegalActionException(
             this, "The selected URL does not point to a valid Opal service");
       }
       _serverNameString = strServerName;
       this.propagateValues();
     }
   } else if (attribute == numberFiles) {
     // --------------    the user has changed the number of files -----------
     int numFiles = 1;
     try {
       numFiles = Integer.parseInt(numberFiles.stringValue());
     } catch (NumberFormatException e) {
       throw new IllegalActionException(
           this, "The numberFiles parameter is not a valid integer, please correct the value");
     }
     if (numFiles != _numberFiles) {
       _updateUploadFileNumber(numFiles);
       _numberFiles = numFiles;
     }
   } else {
     log.debug("the user has changed: " + attribute.toString());
   }
   super.attributeChanged(attribute);
 } // attributeChanged
Beispiel #14
0
  /**
   * If there is no variable with the specified name, then create one. This is done in
   * preinitialize() so that we can set up a type constraint that ensures that the type of the
   * variable is at least that of the input port.
   *
   * @exception IllegalActionException If the superclass throws it, or if there is no container.
   */
  public void preinitialize() throws IllegalActionException {
    super.preinitialize();

    Attribute attribute = getModifiedVariable();

    if (attribute instanceof Variable) {
      ((Variable) attribute).setTypeAtLeast(input);
    }
  }
Beispiel #15
0
  /**
   * Report an exception if it occurred in a background run.
   *
   * @exception IllegalActionException If there is no director, or if a background run threw an
   *     exception.
   */
  public void wrapup() throws IllegalActionException {
    super.wrapup();

    if (_throwable != null) {
      Throwable throwable = _throwable;
      _throwable = null;
      throw new IllegalActionException(this, throwable, "Background run threw an exception");
    }
  }
Beispiel #16
0
  /**
   * Check whether the current director is a GRDirector. If not, throw an illegal action exception.
   *
   * @exception IllegalActionException If the current director is not a GRDirector.
   */
  public void initialize() throws IllegalActionException {
    super.initialize();
    _isSceneGraphInitialized = false;

    /*
     * if (!(getDirector() instanceof GRDirector)) { throw new
     * IllegalActionException(this,
     * "GR Actors can only be used under a GR Director"); }
     */
  }
  /**
   * Does up to three things, in this order: Set new remote address value, Set new remote socket
   * number, transmit data as a UDP packet over the ethernet. The first two can, of course, affect
   * where the datagram goes. Any remote address/socket values supplied are saved and become the
   * defaults for next time.
   */
  public void fire() throws IllegalActionException {
    super.fire();
    String address = null;

    for (int jj = 0; jj < remoteAddress.getWidth(); jj++) {
      if (remoteAddress.hasToken(jj)) {
        address = ((StringToken) (remoteAddress.get(jj))).stringValue();
      }
    }

    if (address != null) {
      try {
        _address = InetAddress.getByName(address);
      } catch (UnknownHostException ex) {
        throw new IllegalActionException(
            this, ex, "The input remote " + "address specifies an unknown host");
      }
    }

    for (int jj = 0; jj < remoteSocketNumber.getWidth(); jj++) {
      if (remoteSocketNumber.hasToken(jj)) {
        // Valid socket numbers are 0..65535,
        // so keep only lower 16 bits.
        _remoteSocketNumber = 65535 & ((IntToken) remoteSocketNumber.get(jj)).intValue();
      }
    }

    if (data.hasToken(0)) {
      ArrayToken dataArrayToken = (ArrayToken) data.get(0);

      byte[] dataBytes = new byte[dataArrayToken.length()];

      for (int j = 0; j < dataArrayToken.length(); j++) {
        UnsignedByteToken token = (UnsignedByteToken) dataArrayToken.getElement(j);
        dataBytes[j] = token.byteValue();
      }

      DatagramPacket packet =
          new DatagramPacket(dataBytes, dataBytes.length, _address, _remoteSocketNumber);

      try {
        _socket.send(packet);
      } catch (IOException ex) {
        // ignore, UDP does not guarantee success
        // throw new InternalErrorException("socket.send failed");
        // FIXME  I don't believe that!  I think send guarantees that
        // it will send!!  Just not that anyone is listening.
        //    (yet when I ran it with 'throw...' uncommented
        //     then it threw it right away!? )
        // Would TCP stall here awaiting reply??  I doubt it!
      }

      triggerOutput.broadcast(new Token());
    }
  }
Beispiel #18
0
  /**
   * Reap one packet from the ORB, unstuff it as an OrbImagePacket, and output the resulting
   * ImageToken (containing a java.awt.Image object). Note that this whole actor can be implemented
   * as a composite actor utilizing ObjectToRecord, RecordDisassembler, and something that forms
   * ImageTokens from java.awt.Image.
   */
  public void fire() throws IllegalActionException {
    super.fire();
    try {
      OrbRawPacket pkt = (OrbRawPacket) (_orb.reap(false));
      OrbImagePacket imgPkt = (OrbImagePacket) (OrbImagePacket.unstuff(pkt));
      output.broadcast(new AWTImageToken(imgPkt.image));

    } catch (Exception e) {
      throw new IllegalActionException(this, e.getMessage());
    }
  }
Beispiel #19
0
 /** Initialize the component and connect to the ORB. */
 public void initialize() throws IllegalActionException {
   try {
     super.initialize();
     _orb = new Orb(StringToken.convert(orbname.getToken()).stringValue(), "r");
     _orb.select(StringToken.convert(srcname.getToken()).stringValue());
     _orb.after(0);
   } catch (Exception e) {
     throw new IllegalActionException(
         this, "Couldn't connect to Orb." + " (" + e.getMessage() + ")");
   }
 }
Beispiel #20
0
  /**
   * If the <i>enable</i> input is connected, then if it has a true token, produce the next output.
   * If it is not connected, produce the next output unconditionally. Whether it is connected is
   * determined by checking the width of the port.
   *
   * @exception IllegalActionException If there is no director.
   */
  public void fire() throws IllegalActionException {
    super.fire();
    if ((!enable.isOutsideConnected())
        || (enable.hasToken(0) && ((BooleanToken) enable.get(0)).booleanValue())) {
      ArrayToken valuesArray = (ArrayToken) values.getToken();

      if (_currentIndex < valuesArray.length()) {
        output.send(0, valuesArray.getElement(_currentIndex));
        _outputProduced = true;
      }
    }
  }
Beispiel #21
0
 /**
  * Override the base class to compile a regular expression when it is changed.
  *
  * @param attribute The attribute that changed.
  * @exception IllegalActionException If the specified attribute is <i>pattern</i> and the regular
  *     expression fails to compile.
  */
 public void attributeChanged(Attribute attribute) throws IllegalActionException {
   if (attribute == pattern) {
     _patternValue = ((StringToken) pattern.getToken()).stringValue();
     // FIXME: What is the following about???
     if (_patternValue.equals("\\r")) {
       _patternValue = "\r";
     }
     _pattern = null;
   } else {
     super.attributeChanged(attribute);
   }
 }
Beispiel #22
0
  /**
   * Consumes packet header Consumes clock token Checks for buffers requesting arbitration
   *
   * @exception IllegalActionException If there is no director.
   */
  public boolean prefire() throws IllegalActionException {
    super.prefire();

    // reads clock signal, if available

    if (wakeup.hasToken(0)) {
      wakeup.get(0);
      clocked = true;
    }

    return true;
  }
  /**
   * Consume one double token from each of the two input ports (x and y), and output one new double
   * token on each of the two output ports (magnitude and angle). The output is a polar form
   * representation of the Cartesian pair given at the inputs. The angle is in radians.
   *
   * @exception IllegalActionException If there is no director.
   */
  @Override
  public void fire() throws IllegalActionException {
    super.fire();
    double xValue = ((DoubleToken) x.get(0)).doubleValue();
    double yValue = ((DoubleToken) y.get(0)).doubleValue();

    double magnitudeValue = Math.sqrt(xValue * xValue + yValue * yValue);
    double angleValue = Math.atan2(yValue, xValue);

    magnitude.send(0, new DoubleToken(magnitudeValue));
    angle.send(0, new DoubleToken(angleValue));
  }
Beispiel #24
0
 /**
  * Override the base class to reset the resource pool to match the specified initialPool value.
  *
  * @param attribute The attribute that changed.
  * @exception IllegalActionException If the change is not acceptable to this container (not thrown
  *     in this base class).
  */
 public void attributeChanged(Attribute attribute) throws IllegalActionException {
   if (attribute == initialPool) {
     ArrayToken pool = (ArrayToken) initialPool.getToken();
     // Reset the pool.
     _pool.clear();
     // Copy the tokens into the pool.
     for (int i = 0; i < pool.length(); i++) {
       _pool.add(pool.getElement(i));
     }
   } else {
     super.attributeChanged(attribute);
   }
 }
Beispiel #25
0
  /**
   * Perform pattern matching and substring replacement, and output the modified string. If no match
   * is found, output the unmodified stringToEdit string.
   *
   * @exception IllegalActionException If there is no director.
   */
  public void fire() throws IllegalActionException {
    super.fire();

    replacement.update();
    stringToEdit.update();
    pattern.update();

    String replacementValue = ((StringToken) replacement.getToken()).stringValue();
    String stringToEditValue = ((StringToken) stringToEdit.getToken()).stringValue();
    boolean replaceAllTokens = ((BooleanToken) replaceAll.getToken()).booleanValue();
    boolean regularExpressionValue = ((BooleanToken) regularExpression.getToken()).booleanValue();

    if (regularExpressionValue) {
      if (_pattern == null) {
        try {
          String patternValue = ((StringToken) pattern.getToken()).stringValue();
          _pattern = Pattern.compile(patternValue);
        } catch (PatternSyntaxException ex) {
          String patternValue = ((StringToken) pattern.getToken()).stringValue();
          throw new IllegalActionException(
              this, ex, "Failed to compile regular expression \"" + patternValue + "\"");
        }
      }
      Matcher match = _pattern.matcher(stringToEditValue);
      String outputString = "";

      // Unfortunately, the String class throws runtime exceptions
      // if something goes wrong, so we have to catch them.
      try {
        if (replaceAllTokens) {
          outputString = match.replaceAll(replacementValue);
        } else {
          outputString = match.replaceFirst(replacementValue);
        }
      } catch (Exception ex) {
        throw new IllegalActionException(this, ex, "String replace failed.");
      }

      output.send(0, new StringToken(outputString));
    } else {
      // No regular expression.
      String outputString;
      if (replaceAllTokens) {
        outputString = stringToEditValue.replaceAll(_patternValue, replacementValue);
      } else {
        outputString = stringToEditValue.replace(_patternValue, replacementValue);
      }
      output.send(0, new StringToken(outputString));
    }
  }
Beispiel #26
0
  /**
   * Override the base class to open the model specified if the attribute is modelFileOrURL, or for
   * other parameters, to cache their values.
   *
   * @param attribute The attribute that changed.
   * @exception IllegalActionException If the change is not acceptable to this container (not thrown
   *     in this base class).
   */
  public void attributeChanged(Attribute attribute) throws IllegalActionException {
    if (attribute == modelFileOrURL) {
      // Open the file and read the MoML to create a model.
      URL url = modelFileOrURL.asURL();

      if (url != null) {
        // By specifying no workspace argument to the parser, we
        // are asking it to create a new workspace for the referenced
        // model. This is necessary because the execution of that
        // model will proceed through its own sequences, and it
        // will need to get write permission on the workspace.
        // Particularly if it is executing in a new thread, then
        // during the fire() method of this actor it would be
        // inappropriate to grant write access on the workspace
        // of this actor.
        MoMLParser parser = new MoMLParser();

        try {
          _model = parser.parse(null, url);
        } catch (Exception ex) {
          throw new IllegalActionException(this, ex, "Failed to read model.");
        }

        // Create a manager, if appropriate.
        if (_model instanceof CompositeActor) {
          _manager = new Manager(_model.workspace(), "Manager");
          ((CompositeActor) _model).setManager(_manager);

          if (_debugging) {
            _debug("** Created new manager.");
          }
        }
      } else {
        // URL is null... delete the current model.
        _model = null;
        _manager = null;
        _throwable = null;
      }
    } else if (attribute == maxOutputLength) {
      IntToken length = (IntToken) maxOutputLength.getToken();

      if (length.intValue() > 0) {
        _outputLength = length.intValue();
      } else {
        throw new IllegalActionException(this, "output array length is less than or equal 0?!");
      }
    } else {
      super.attributeChanged(attribute);
    }
  }
  /**
   * Override the base class to reinitialize the state if the <i>localSocketNumber</i>,
   * <i>defaultRemoteAddress</i> or <i>defaultRemoteSocketNumber</i> parameter has changed.
   *
   * <p>If the parameter changed is <i>localSocketNumber</i>, then if the model is running (as
   * evidenced by socket != null) then close socket and reopen with new socket number (even if it is
   * the same as the old socket number). Do not close the socket until a new one has been
   * successfully opened. If <i>defaultRemoteAddress</i> or <i>defaultRemoteSocketNumber</i> is
   * changed, simply update these parameters, checking, in the case of the address, that it passes
   * lookup anc conversion to an IP address. If the <i>encoding</i> parameter is changed, set the
   * private encoding settings to the new values.
   *
   * @param attribute The attribute that changed.
   * @exception IllegalActionException If the socket cannot be created.
   */
  public void attributeChanged(Attribute attribute) throws IllegalActionException {
    if (attribute == localSocketNumber) {
      synchronized (this) {
        if (_socket != null) {
          if (_debugging) {
            _debug("Current socket port is " + _socket.getLocalPort());
          }

          _localSocketNumber = ((IntToken) (localSocketNumber.getToken())).intValue();

          if (_debugging) {
            _debug("Socket number is " + _localSocketNumber);
          }

          try {
            if (_debugging) {
              _debug("Try create socket for port " + _localSocketNumber);
            }

            DatagramSocket newSocket = new DatagramSocket(_localSocketNumber);

            if (_debugging) {
              _debug("A socket is created!!");
            }

            _socket.close();
            _socket = newSocket;
          } catch (SocketException ex) {
            throw new IllegalActionException(
                this, ex, "Cannot create socket on the given " + "local socket number.");
          }
        }
      }
    } else if (attribute == defaultRemoteAddress) {
      String address = ((StringToken) defaultRemoteAddress.getToken()).stringValue();

      try {
        _address = InetAddress.getByName(address);
      } catch (UnknownHostException ex) {
        throw new IllegalActionException(
            this, ex, "The default remote " + "address specifies an unknown host");
      }
    } else if (attribute == defaultRemoteSocketNumber) {
      _remoteSocketNumber = ((IntToken) defaultRemoteSocketNumber.getToken()).intValue();
      _remoteSocketNumber &= 65535; // Truncate to 16 bits.
    } else {
      super.attributeChanged(attribute);
    }
  }
Beispiel #28
0
  /**
   * Read the search parameter, if it matches "Search 50" then we've "got" data. Let the Loop Actor
   * know it can stop searching
   */
  public void fire() throws IllegalActionException {
    super.fire();

    if (search.getWidth() > 0 && search.hasToken(0)) {
      String searchStr = ((StringToken) search.get(0)).stringValue();
      if (searchStr.equals("Search 50")) {
        System.out.println("Found DATA!");
        resultsOutput.broadcast(new StringToken("Results Found"));

      } else {
        System.out.println("Didn't Match! " + searchStr);
        resultsOutput.broadcast(new StringToken("No Data"));
      }
    }
  }
Beispiel #29
0
  /**
   * Read a token from each input port. If the token from the <i>control</i> input is true, then
   * output the token consumed from the <i>input</i> port on the <i>trueOutput</i> port, otherwise
   * output the token on the <i>falseOutput</i> port.
   *
   * @exception IllegalActionException If there is no director.
   */
  public void fire() throws IllegalActionException {
    super.fire();
    if (control.hasToken(0)) {
      _control = ((BooleanToken) control.get(0)).booleanValue();
    }

    if (input.hasToken(0)) {
      Token token = input.get(0);

      if (_control) {
        trueOutput.send(0, token);
      } else {
        falseOutput.send(0, token);
      }
    }
  }
  /**
   * If there is at least one token on the input ports, multiply tokens from the <i>multiply</i>
   * port, divide by tokens from the <i>divide</i> port, and send the result to the output port. At
   * most one token is read from each channel, so if more than one token is pending, the rest are
   * left for future firings. If none of the input channels has a token, do nothing. If none of the
   * multiply channels have tokens, then the tokens on the divide channels are divided into a one
   * token of the same type as the denominator.
   *
   * @exception IllegalActionException If there is no director, or if multiplication and division
   *     are not supported by the available tokens.
   */
  @Override
  public void fire() throws IllegalActionException {
    super.fire();
    Token numerator = null;
    try {
      for (int i = 0; i < multiply.getWidth(); i++) {
        if (multiply.hasToken(i)) {
          if (numerator == null) {
            numerator = multiply.get(i);
          } else {
            numerator = numerator.multiply(multiply.get(i));
          }
        }
      }

      Token denominator = null;

      for (int i = 0; i < divide.getWidth(); i++) {
        if (divide.hasToken(i)) {
          if (denominator == null) {
            denominator = divide.get(i);
          } else {
            denominator = denominator.multiply(divide.get(i));
          }
        }
      }

      if (numerator == null) {
        if (denominator == null) {
          return;
        }

        // For the benefit of copernicus, this means that
        // numerator always has the same type.
        numerator = multiply.getType().convert(denominator.one());
      }

      if (denominator != null) {
        numerator = numerator.divide(denominator);
      }
    } catch (Exception e) {
      throw new IllegalActionException(this, e.getCause(), e.getMessage());
    }

    output.send(0, numerator);
  }