/* * (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(); } }
/* * (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(); } } }
@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()); }
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()); }
@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; }