示例#1
0
 public boolean acceptInputPort(Port p) {
   if (p == null || p.getContainer() != this) {
     return false;
   }
   if (p instanceof ControlPort || !p.isInput()) {
     return false;
   }
   return PortMode.PUSH.equals(p.getMode());
 }
示例#2
0
 @Override
 public Object clone(Workspace workspace) throws CloneNotSupportedException {
   Port port = (Port) super.clone(workspace);
   port.statistics = new PortStatistics(port);
   port.modeAttr = null;
   port.operationalSourcePorts = null;
   // TODO check what must be done with buffer
   port.setMode(port.mode);
   return port;
 }
示例#3
0
  /** Create the second port needed by modulo function */
  private void _createSecondPort() throws NameDuplicationException, IllegalActionException {
    // Go looking for the port in case somebody else created the port
    // already. For example, this might
    // happen in shallow code generation.
    secondOperand = (Port) getPort("secondOperand");
    if (secondOperand == null) {
      secondOperand =
          PortFactory.getInstance().createInputPort(this, "secondOperand", Double.class);

    } else if (secondOperand.getContainer() == null) {
      secondOperand.setContainer(this);
    }
  }
示例#4
0
 /*
  * (non-Javadoc)
  * @see com.isencia.passerelle.actor.Actor#doInitialize()
  */
 @Override
 protected void doInitialize() throws InitializationException {
   // TODO Auto-generated method stub
   super.doInitialize();
   firstOperandHandler = new PortHandler(firstOperand);
   if (firstOperand.getWidth() > 0) {
     firstOperandHandler.start();
   }
   if (secondOperand != null) {
     secondOperandHandler = new PortHandler(secondOperand);
     if (secondOperand.getWidth() > 0) {
       secondOperandHandler.start();
     }
   }
 }
示例#5
0
  /*
   * (non-Javadoc)
   * @see com.isencia.passerelle.actor.Transformer#doFire(com.isencia.passerelle. message.ManagedMessage)
   */
  @Override
  protected void doFire() throws ProcessingException {

    double input1 = 0;
    final Token token = firstOperandHandler.getToken();
    if (token != null && token != Token.NIL) {
      input1 = getDoubleFromMessage(token);
      double input2 = 1.0;
      if (_function == _MODULO) {
        if (secondOperand != null) {
          final Token tokenSec = secondOperandHandler.getToken();
          if (tokenSec != null && token != Token.NIL) {
            input2 = getDoubleFromMessage(tokenSec);
          }
        }
      }
      final ManagedMessage resultMsg = createMessage();
      try {
        resultMsg.setBodyContent(
            new Double(_doFunction(input1, input2)), ManagedMessage.objectContentType);
        output.broadcast(new ObjectToken(resultMsg));
      } catch (final MessageException e) {
        ExceptionUtil.throwProcessingException("Cannot send result to output", output, e);
      } catch (final IllegalActionException e) {
        ExceptionUtil.throwProcessingException("Cannot send result to output", output, e);
      }
    } else {
      requestFinish();
    }
  }
示例#6
0
  @Override
  @SuppressWarnings("unchecked")
  protected void doInitialize() throws InitializationException {
    getLogger().trace("{} - doInitialize() - entry", getFullName());
    super.doInitialize();

    blockingInputHandlers.clear();
    blockingInputFinishRequests.clear();

    iterationCount = 0;
    currentProcessRequest = new ProcessRequest();
    currentProcessRequest.setIterationCount(++iterationCount);
    currentProcessResponse = null;

    List<Port> inputPortList = this.inputPortList();
    for (Port _p : inputPortList) {
      if (_p.isInput() && !(_p instanceof ControlPort)) {
        if (_p.isBlocking()) {
          blockingInputHandlers.add(createPortHandler(_p));
          blockingInputFinishRequests.put(_p, Boolean.FALSE);
        }
        isSource = false;
      }
    }
    for (int i = 0; i < blockingInputHandlers.size(); ++i) {
      PortHandler h = blockingInputHandlers.get(i);
      if (h.getWidth() > 0) {
        blockingInputFinishRequests.put(h.getPort(), Boolean.FALSE);
        h.start();
      } else {
        blockingInputFinishRequests.put(h.getPort(), Boolean.TRUE);
      }
    }

    try {
      triggerFirstIteration();
    } catch (IllegalActionException e) {
      throw new InitializationException(
          ErrorCode.FLOW_EXECUTION_FATAL,
          "Error triggering a fire iteration for source actor " + getFullName(),
          this,
          e);
    }

    getLogger().trace("{} - doInitialize() - exit", getFullName());
  }
示例#7
0
 public synchronized void notifySourcePortFinished(Port port) {
   logger.trace("notifySourcePortFinished() - entry - srcPort : {}", port.getFullName());
   operationalSourcePorts.remove(port);
   if (operationalSourcePorts.size() == 0) {
     requestFinish();
   }
   logger.trace("notifySourcePortFinished() - exit");
 }
示例#8
0
 @Override
 public void attributeChanged(final Attribute attribute) throws IllegalActionException {
   try {
     if (attribute == function) {
       final String functionName = function.stringValue();
       if (functionName.equals("exp")) {
         _function = _EXP;
         if (secondOperand != null) {
           secondOperand.setContainer(null);
         }
       } else if (functionName.equals("log")) {
         _function = _LOG;
         if (secondOperand != null) {
           secondOperand.setContainer(null);
         }
       } else if (functionName.equals("modulo")) {
         _function = _MODULO;
         _createSecondPort();
       } else if (functionName.equals("sign")) {
         _function = _SIGN;
         if (secondOperand != null) {
           secondOperand.setContainer(null);
         }
       } else if (functionName.equals("square")) {
         _function = _SQUARE;
         if (secondOperand != null) {
           secondOperand.setContainer(null);
         }
       } else if (functionName.equals("sqrt")) {
         _function = _SQRT;
         if (secondOperand != null) {
           secondOperand.setContainer(null);
         }
       } else {
         throw new IllegalActionException(this, "Unrecognized math function: " + functionName);
       }
     } else {
       super.attributeChanged(attribute);
     }
   } catch (final NameDuplicationException nameDuplication) {
     throw new InternalErrorException(this, nameDuplication, "Unexpected name duplication");
   }
 }
示例#9
0
 protected void doInitialize() throws InitializationException {
   super.doInitialize();
   // If something connected to the reset port, install a handler
   if (reset.getWidth() > 0) {
     resetHandler =
         createPortHandler(
             reset,
             new PortListenerAdapter() {
               public void tokenReceived() {
                 Token token = resetHandler.getToken();
                 if (token != null && !token.isNil()) {
                   getLogger().debug("{} Reset Event received", getFullName());
                   isReset = true;
                 }
               }
             });
     resetHandler.start();
   }
   setValue(getStartValue());
 }
示例#10
0
 @Override
 protected boolean doPreFire() throws ProcessingException {
   getLogger().trace("{} - doPreFire() - entry  ", getFullName());
   boolean readyToFire = super.doPreFire();
   if (readyToFire && !isSource) {
     // first read from all blocking inputs
     for (int i = 0; i < blockingInputHandlers.size(); i++) {
       PortHandler handler = blockingInputHandlers.get(i);
       Port _p = (Port) handler.getPort();
       ManagedMessage msg = null;
       // If a port is exhausted, we just pass a null msg to the request.
       // If not, we try to read another msg from it.
       // A null msg indicates that the port is exhausted.
       if (!blockingInputFinishRequests.get(_p).booleanValue()) {
         // For the moment, we only read at most one msg per PULL input port.
         // Remark that for an event-driven domain, it is possible that preFire()
         // is invoked repetitively before a fire() is possible.
         // Msg streams should be handled via PUSH ports.
         if (currentProcessRequest.getMessage(_p) == null) {
           boolean portHasMsg = false;
           boolean portExhausted = false;
           try {
             Token token = handler.getToken();
             portHasMsg = (token != null) && (token != Token.NIL);
             portExhausted = (token == null);
             if (portHasMsg) {
               msg = MessageHelper.getMessageFromToken(token);
               currentProcessRequest.addInputMessage(0, _p.getName(), msg);
             } else {
               // all blocking/PULL ports must have received a message before we can fire
               readyToFire = false;
             }
           } catch (ProcessingException e) {
             throw e;
           } catch (PasserelleException e) {
             throw new ProcessingException(
                 ErrorCode.FLOW_EXECUTION_ERROR, "Error getting message from input", _p, e);
           }
           if (portExhausted) {
             blockingInputFinishRequests.put(handler.getPort(), Boolean.TRUE);
             getLogger()
                 .debug(
                     "{} - doPreFire() - found exhausted port {} ",
                     getFullName(),
                     handler.getName());
           } else if (msg != null) {
             if (getLogger().isDebugEnabled())
               getLogger()
                   .debug(
                       "{} - doPreFire() - message {} received on port {}",
                       new Object[] {getFullName(), msg.getID(), handler.getName()});
           }
         }
       }
     }
     if (readyToFire && (!getMessageQueue().isEmpty() || !msgProviders.isEmpty())) {
       try {
         // TODO check if it's not nicer to maintain buffer time from 1st preFire() call
         // to when readyToFire, i.o. adding it after the time we've already been waiting
         // for all PULL ports having a message.
         int bufferTime = ((IntToken) bufferTimeParameter.getToken()).intValue();
         if (bufferTime > 0) {
           getLogger()
               .debug("{} - doPreFire() - sleeping for buffer time {}", getFullName(), bufferTime);
           Thread.sleep(bufferTime);
         }
       } catch (Exception e) {
         getLogger().warn(getFullName() + " - Failed to enforce buffer time", e);
       }
       // we've got at least one PUSH port that registered a msg provider
       // so we need to include all pushed msgs in the request as well
       addPushedMessages(currentProcessRequest);
     }
     readyToFire = readyToFire && currentProcessRequest.hasSomethingToProcess();
     // when all ports are exhausted, we can stop this actor
     if (!readyToFire
         && !getDirectorAdapter().isActorBusy(this)
         && areAllInputsFinished()
         && getMessageQueue().isEmpty()) {
       requestFinish();
       readyToFire = true;
     }
   }
   getLogger().trace("{} - doPreFire() - exit : {}", getFullName(), readyToFire);
   return readyToFire;
 }