示例#1
0
  /**
   * Send a token to all connected receivers. Tokens are in general immutable, so each receiver is
   * given a reference to the same token and no clones are made. The transfer is accomplished by
   * calling getRemoteReceivers() to determine the number of channels with valid receivers and then
   * calling send() on the appropriate channels. It would probably be faster to call put() directly
   * on the receivers. If there are no destination receivers, then nothing is sent. If the port is
   * not connected to anything, or receivers have not been created in the remote port, then just
   * return.
   *
   * <p>Some of this method is read-synchronized on the workspace. Since it is possible for a thread
   * to block while executing a put, it is important that the thread does not hold read access on
   * the workspace when it is blocked. Thus this method releases read access on the workspace before
   * calling put.
   *
   * @param token The token to send
   * @exception IllegalActionException If the token to be sent cannot be converted to the type of
   *     this port
   * @exception NoRoomException If a send to one of the channels throws it.
   */
  public void broadcast(Token token) throws IllegalActionException, NoRoomException {

    if (logger.isTraceEnabled()) {
      logger.trace("broadcast() - entry : " + token);
    }

    statistics.acceptSentMessage(null);

    Receiver[][] farReceivers;
    // ptolemy debug listener stuff etc
    if (_debugging) {
      _debug("broadcast " + token);
    }
    try {
      _workspace.getReadAccess();
      _checkType(token);
      farReceivers = getRemoteReceivers();
      if (farReceivers == null) {
        return;
      }
    } finally {
      _workspace.doneReading();
    }
    // NOTE: This does not call send() here, because send()
    // repeats the above on each call.
    for (int i = 0; i < farReceivers.length; i++) {
      if (farReceivers[i] == null) continue;
      putAtFarReceivers(token, farReceivers[i]);
    }

    if (logger.isTraceEnabled()) {
      logger.trace("broadcast() - exit");
    }
  }
示例#2
0
  /**
   * Send the specified portion of a token array to all receivers connected to the specified
   * channel, checking the type and converting the token if necessary. The first <i>vectorLength</i>
   * tokens of the token array are sent. If the port is not connected to anything, or receivers have
   * not been created in the remote port, or the channel index is out of range, or the port is not
   * an output port, then just silently return. This behavior makes it easy to leave output ports
   * unconnected when you are not interested in the output.
   *
   * <p>To improve efficiency for the common case where the type of the tokens to send matches the
   * type of this port and all connected ports, this method assumes that all of the tokens in the
   * specified portion of the token array are of the same type. If this is not the case, then the
   * non-vectorized send() method should be used instead. The implementation only actually checks
   * the type of the first token in the array, and then assumes that the remaining tokens are of the
   * same type.
   *
   * <p>If the type of the tokens in the specified portion of the token array is the type of this
   * port, or the tokens in the specified portion of the token array can be converted to that type
   * losslessly, the tokens in the specified portion of the token array are sent to all receivers
   * connected to the specified channel. Otherwise, IllegalActionException is thrown. Before putting
   * the tokens in the specified portion of the token array into the destination receivers, this
   * method also checks the type of the remote input port, and converts the tokens if necessary. The
   * conversion is done by calling the convert() method of the type of the remote input port.
   *
   * <p>Some of this method is read-synchronized on the workspace. Since it is possible for a thread
   * to block while executing a put, it is important that the thread does not hold read access on
   * the workspace when it is blocked. Thus this method releases read access on the workspace before
   * calling put.
   *
   * @param channelIndex The index of the channel, from 0 to width-1
   * @param tokenArray The token array to send
   * @param vectorLength The number of elements of the token array to send.
   * @exception NoRoomException If there is no room in the receiver.
   * @exception IllegalActionException If the tokens to be sent cannot be converted to the type of
   *     this port, or if the <i>vectorLength</i> argument is greater than the length of the
   *     <i>tokenArray</i> argument.
   */
  public void send(int channelIndex, Token[] tokenArray, int vectorLength)
      throws IllegalActionException, NoRoomException {
    if (logger.isTraceEnabled()) {
      logger.trace(
          "{} - send(array) - entry : channel : {} token : {} length : {}",
          new Object[] {this.getFullName(), channelIndex, tokenArray, vectorLength});
    }
    if (vectorLength > tokenArray.length) {
      throw new IllegalActionException(
          this, "Not enough data supplied to send specified number of samples.");
    }
    Receiver[][] farReceivers;
    if (_debugging) {
      _debug("send to channel " + channelIndex + " token array of length " + vectorLength);
    }

    if (isDebugged()) {
      event(
          new IOPortEvent(
              this, IOPortEvent.SEND, IOPortEvent.ALLCHANNELS, true, tokenArray, vectorLength));
    }

    Token token = null;
    try {
      try {
        _workspace.getReadAccess();
        // check types
        for (int i = 0; i < vectorLength; i++) {
          token = tokenArray[i];
          _checkType(token);
        }
        // Note that the getRemoteReceivers() method doesn't throw
        // any non-runtime exception.
        farReceivers = getRemoteReceivers();
        if (farReceivers == null || farReceivers[channelIndex] == null) {
          return;
        }
      } finally {
        _workspace.doneReading();
      }
      putAtFarReceivers(tokenArray, vectorLength, farReceivers[channelIndex]);
    } catch (ArrayIndexOutOfBoundsException ex) {
      // NOTE: This may occur if the channel index is out of range.
      // This is allowed, just do nothing.
    }

    logger.trace("{} - send(array) - exit", this.getFullName());
  }
示例#3
0
  /**
   * Send a token to the specified channel, checking the type and converting the token if necessary.
   * If the port is not connected to anything, or receivers have not been created in the remote
   * port, or the channel index is out of range, or the port is not an output port, then just
   * silently return. This behavior makes it easy to leave output ports unconnected when you are not
   * interested in the output. If the type of the specified token is the type of this port, or the
   * token can be converted to that type losslessly, the token is sent to all receivers connected to
   * the specified channel. Otherwise, IllegalActionException is thrown. Before putting the token
   * into the destination receivers, this method also checks the type of the remote input port, and
   * converts the token if necessary. The conversion is done by calling the convert() method of the
   * type of the remote input port.
   *
   * <p>Some of this method is read-synchronized on the workspace. Since it is possible for a thread
   * to block while executing a put, it is important that the thread does not hold read access on
   * the workspace when it is blocked. Thus this method releases read access on the workspace before
   * calling put.
   *
   * @param channelIndex The index of the channel, from 0 to width-1.
   * @param token The token to send.
   * @exception IllegalActionException If the token to be sent cannot be converted to the type of
   *     this port, or if the token is null.
   * @exception NoRoomException If there is no room in the receiver.
   */
  public void send(int channelIndex, Token token) throws IllegalActionException, NoRoomException {
    if (logger.isTraceEnabled()) {
      logger.trace(
          "{} - send() - entry : channel : {} token : {}",
          new Object[] {this.getFullName(), channelIndex, token});
    }
    if (token == null) {
      throw new IllegalActionException(this, "Cannot send a null token.");
    }

    if (!(PasserelleToken.POISON_PILL == token)) {
      statistics.acceptSentMessage(null);
    }

    Receiver[][] farReceivers;
    if (_debugging) {
      _debug("send to channel " + channelIndex + ": " + token);
    }

    if (isDebugged()) {
      event(new IOPortEvent(this, IOPortEvent.SEND, IOPortEvent.ALLCHANNELS, true, token));
    }

    try {
      try {
        _workspace.getReadAccess();
        _checkType(token);

        // Note that the getRemoteReceivers() method doesn't throw
        // any non-runtime exception.
        farReceivers = getRemoteReceivers();
        if (farReceivers == null
            || farReceivers.length <= channelIndex
            || farReceivers[channelIndex] == null) {
          return;
        }
      } finally {
        _workspace.doneReading();
      }

      putAtFarReceivers(token, farReceivers[channelIndex]);
    } catch (ArrayIndexOutOfBoundsException ex) {
      // NOTE: This may occur if the channel index is out of range.
      // This is allowed, just do nothing.
    }

    logger.trace("{} - send() - exit", this.getFullName());
  }
示例#4
0
  /**
   * Send the specified portion of a token array to all receivers connected to this port. The first
   * <i>vectorLength</i> tokens of the token array are sent.
   *
   * <p>Tokens are in general immutable, so each receiver is given a reference to the same token and
   * no clones are made. If the port is not connected to anything, or receivers have not been
   * created in the remote port, or the channel index is out of range, or the port is not an output
   * port, then just silently return. This behavior makes it easy to leave output ports unconnected
   * when you are not interested in the output. The transfer is accomplished by calling the
   * vectorized put() method of the remote receivers. If the port is not connected to anything, or
   * receivers have not been created in the remote port, then just return.
   *
   * <p>Some of this method is read-synchronized on the workspace. Since it is possible for a thread
   * to block while executing a put, it is important that the thread does not hold read access on
   * the workspace when it is blocked. Thus this method releases read access on the workspace before
   * calling put.
   *
   * @param tokenArray The token array to send
   * @param vectorLength The number of elements of the token array to send.
   * @exception NoRoomException If there is no room in the receiver.
   * @exception IllegalActionException If the tokens to be sent cannot be converted to the type of
   *     this port
   */
  public void broadcast(Token[] tokenArray, int vectorLength)
      throws IllegalActionException, NoRoomException {

    if (logger.isTraceEnabled()) {
      logger.trace(
          "{} - broadcast(array) - entry : {} length : {}",
          new Object[] {this.getFullName(), tokenArray, vectorLength});
    }
    Receiver[][] farReceivers;
    if (_debugging) {
      _debug("broadcast token array of length " + vectorLength);
    }

    if (isDebugged()) {
      event(
          new IOPortEvent(
              this, IOPortEvent.SEND, IOPortEvent.ALLCHANNELS, true, tokenArray, vectorLength));
    }

    Token token = null;
    try {
      _workspace.getReadAccess();
      // check types
      for (int i = 0; i < tokenArray.length; i++) {
        token = tokenArray[i];
        _checkType(token);
      }
      farReceivers = getRemoteReceivers();
      if (farReceivers == null) {
        return;
      }
    } finally {
      _workspace.doneReading();
    }
    // NOTE: This does not call send() here, because send()
    // repeats the above on each call.
    for (int i = 0; i < farReceivers.length; i++) {
      if (farReceivers[i] == null) continue;

      putAtFarReceivers(tokenArray, vectorLength, farReceivers[i]);
    }

    logger.trace("{} - broadcast(array) - exit", this.getFullName());
  }
示例#5
0
  /**
   * Send a token to the specified channel, checking the type and converting the token if necessary.
   * If the port is not connected to anything, or receivers have not been created in the remote
   * port, or the channel index is out of range, or the port is not an output port, then just
   * silently return. This behavior makes it easy to leave output ports unconnected when you are not
   * interested in the output. If the type of the specified token is the type of this port, or the
   * token can be converted to that type losslessly, the token is sent to all receivers connected to
   * the specified channel. Otherwise, IllegalActionException is thrown. Before putting the token
   * into the destination receivers, this method also checks the type of the remote input port, and
   * converts the token if necessary. The conversion is done by calling the convert() method of the
   * type of the remote input port.
   *
   * <p>Some of this method is read-synchronized on the workspace. Since it is possible for a thread
   * to block while executing a put, it is important that the thread does not hold read access on
   * the workspace when it is blocked. Thus this method releases read access on the workspace before
   * calling put.
   *
   * @param channelIndex The index of the channel, from 0 to width-1.
   * @param token The token to send.
   * @exception IllegalActionException If the token to be sent cannot be converted to the type of
   *     this port, or if the token is null.
   * @exception NoRoomException If there is no room in the receiver.
   */
  public void send(int channelIndex, Token token) throws IllegalActionException, NoRoomException {
    if (logger.isTraceEnabled()) {
      logger.trace("send() - entry : channel : " + channelIndex + " token : " + token);
    }
    if (token == null) {
      throw new IllegalActionException(this, "Cannot send a null token.");
    }

    statistics.acceptSentMessage(null);

    Receiver[][] farReceivers;
    if (_debugging) {
      _debug("send to channel " + channelIndex + ": " + token);
    }
    try {
      try {
        _workspace.getReadAccess();
        _checkType(token);

        // Note that the getRemoteReceivers() method doesn't throw
        // any non-runtime exception.
        farReceivers = getRemoteReceivers();
        if (farReceivers == null
            || farReceivers.length <= channelIndex
            || farReceivers[channelIndex] == null) {
          return;
        }
      } finally {
        _workspace.doneReading();
      }

      putAtFarReceivers(token, farReceivers[channelIndex]);
    } catch (ArrayIndexOutOfBoundsException ex) {
      // NOTE: This may occur if the channel index is out of range.
      // This is allowed, just do nothing.
    }

    if (logger.isTraceEnabled()) {
      logger.trace("send() - exit");
    }
  }
示例#6
0
  /**
   * Send the specified portion of a token array to all receivers connected to this port. The first
   * <i>vectorLength</i> tokens of the token array are sent.
   *
   * <p>Tokens are in general immutable, so each receiver is given a reference to the same token and
   * no clones are made. If the port is not connected to anything, or receivers have not been
   * created in the remote port, or the channel index is out of range, or the port is not an output
   * port, then just silently return. This behavior makes it easy to leave output ports unconnected
   * when you are not interested in the output. The transfer is accomplished by calling the
   * vectorized put() method of the remote receivers. If the port is not connected to anything, or
   * receivers have not been created in the remote port, then just return.
   *
   * <p>Some of this method is read-synchronized on the workspace. Since it is possible for a thread
   * to block while executing a put, it is important that the thread does not hold read access on
   * the workspace when it is blocked. Thus this method releases read access on the workspace before
   * calling put.
   *
   * @param tokenArray The token array to send
   * @param vectorLength The number of elements of the token array to send.
   * @exception NoRoomException If there is no room in the receiver.
   * @exception IllegalActionException If the tokens to be sent cannot be converted to the type of
   *     this port
   */
  public void broadcast(Token[] tokenArray, int vectorLength)
      throws IllegalActionException, NoRoomException {

    if (logger.isTraceEnabled()) {
      logger.trace("broadcast(array) - entry : " + tokenArray + " length :" + vectorLength);
    }
    Receiver[][] farReceivers;
    if (_debugging) {
      _debug("broadcast token array of length " + vectorLength);
    }
    Token token = null;
    try {
      _workspace.getReadAccess();
      // check types
      for (int i = 0; i < tokenArray.length; i++) {
        token = tokenArray[i];
        _checkType(token);
      }
      farReceivers = getRemoteReceivers();
      if (farReceivers == null) {
        return;
      }
    } finally {
      _workspace.doneReading();
    }
    // NOTE: This does not call send() here, because send()
    // repeats the above on each call.
    for (int i = 0; i < farReceivers.length; i++) {
      if (farReceivers[i] == null) continue;

      putAtFarReceivers(tokenArray, vectorLength, farReceivers[i]);
    }

    if (logger.isTraceEnabled()) {
      logger.trace("broadcast(array) - exit");
    }
  }
示例#7
0
  /**
   * Send a token to all connected receivers. Tokens are in general immutable, so each receiver is
   * given a reference to the same token and no clones are made. The transfer is accomplished by
   * calling getRemoteReceivers() to determine the number of channels with valid receivers and then
   * calling send() on the appropriate channels. It would probably be faster to call put() directly
   * on the receivers. If there are no destination receivers, then nothing is sent. If the port is
   * not connected to anything, or receivers have not been created in the remote port, then just
   * return.
   *
   * <p>Some of this method is read-synchronized on the workspace. Since it is possible for a thread
   * to block while executing a put, it is important that the thread does not hold read access on
   * the workspace when it is blocked. Thus this method releases read access on the workspace before
   * calling put.
   *
   * @param token The token to send
   * @exception IllegalActionException If the token to be sent cannot be converted to the type of
   *     this port
   * @exception NoRoomException If a send to one of the channels throws it.
   */
  public void broadcast(Token token) throws IllegalActionException, NoRoomException {
    logger.trace("{} - broadcast() - entry : {} ", this.getFullName(), token);

    if (!(PasserelleToken.POISON_PILL == token)) {
      statistics.acceptSentMessage(null);
    }

    Receiver[][] farReceivers;
    // ptolemy debug listener stuff etc
    if (_debugging) {
      _debug("broadcast " + token);
    }

    if (isDebugged()) {
      event(new IOPortEvent(this, IOPortEvent.SEND, IOPortEvent.ALLCHANNELS, true, token));
    }

    try {
      _workspace.getReadAccess();
      _checkType(token);
      farReceivers = getRemoteReceivers();
      if (farReceivers == null) {
        return;
      }
    } finally {
      _workspace.doneReading();
    }
    // NOTE: This does not call send() here, because send()
    // repeats the above on each call.
    for (int i = 0; i < farReceivers.length; i++) {
      if (farReceivers[i] == null) continue;
      putAtFarReceivers(token, farReceivers[i]);
    }

    logger.trace("{} - broadcast() - exit", this.getFullName());
  }