Ejemplo n.º 1
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);
    }
  }
Ejemplo n.º 2
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);
   }
 }
Ejemplo n.º 3
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
Ejemplo n.º 4
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);
   }
 }
Ejemplo n.º 5
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);
   }
 }
Ejemplo n.º 6
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);
    }
  }
Ejemplo n.º 7
0
  /**
   * 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);
    }
  }
Ejemplo n.º 8
0
  /**
   * Handle change requests for all parameters. An exception is thrown if the requested change is
   * not allowed.
   *
   * @param attribute The attribute that changed.
   * @exception IllegalActionException If the change is not allowed.
   */
  public void attributeChanged(Attribute attribute) throws IllegalActionException {
    if (attribute == bufferSize) {
      _bufferSize = ((IntToken) bufferSize.getToken()).intValue();
    } else if (attribute == channels) {
      int channelsValue = ((IntToken) channels.getToken()).intValue();
      if (channelsValue < 1) {
        throw new IllegalActionException(this, "Unsupported number of channels: " + channelsValue);
      }
      _channels = channelsValue;
    } else if (attribute == sampleRate) {
      _sampleRate = ((IntToken) sampleRate.getToken()).intValue();
    } else if (attribute == bytesPerSample) {
      _bytesPerSample = ((IntToken) bytesPerSample.getToken()).intValue();
      // Cache the maximum value as a double.
      _maxSample = Math.pow(2.0, (_bytesPerSample * 8)) - 1.0;
    }

    super.attributeChanged(attribute);
  }
Ejemplo n.º 9
0
  /**
   * If the specified attribute is <i>fileName</i> and there is an open file being written, then
   * close that file. The new file will be opened or created when it is next written to.
   *
   * @param attribute The attribute that has changed.
   * @exception IllegalActionException If the specified attribute is <i>fileName</i> and the
   *     previously opened file cannot be closed.
   */
  public void attributeChanged(Attribute attribute) throws IllegalActionException {

    if (attribute == interval) {
      double simu = ((DoubleToken) interval.getToken()).doubleValue();
      if (simu <= 0.0) {
        throw new IllegalActionException(
            this, "simulation_window is required to be positive. simulation_window given: " + simu);
      }
      if (attribute == initial_time) {
        double init = ((DoubleToken) initial_time.getToken()).doubleValue();
        if (init <= 0.0) {
          throw new IllegalActionException(
              this,
              "simulation_window is required to be positive. simulation_window given: " + simu);
        } else {
          super.attributeChanged(attribute);
        }
      }
    }
  }