Пример #1
0
 /**
  * @param token
  * @param cd
  * @return @throws MessageException
  * @throws NumberFormatException
  * @throws DevFailed
  * @throws ProcessingException
  * @throws
  */
 private double getDoubleFromMessage(final Token token) throws ProcessingException {
   double result = 0;
   ManagedMessage message;
   Object input = null;
   try {
     message = MessageHelper.getMessageFromToken(token);
     input = message.getBodyContent();
     if (input instanceof Number) {
       result = ((Number) input).doubleValue();
     } else if (input instanceof TangoAttribute) {
       result = Double.parseDouble(((TangoAttribute) input).readAsString("", ""));
     } else {
       result = Double.parseDouble(input.toString());
     }
   } catch (final NumberFormatException e) {
     ExceptionUtil.throwProcessingException("Input type not supported", input, e);
   } catch (final PasserelleException e) {
     ExceptionUtil.throwProcessingException("Error reading msg content", input, e);
   } catch (final DevFailed e) {
     // e.printStackTrace();
     ExceptionUtil.throwProcessingException(
         TangoToPasserelleUtil.getDevFailedString(e, this), input, e);
   }
   return result;
 }
Пример #2
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();
    }
  }
Пример #3
0
 protected String getAuditTrailMessage(ManagedMessage message, Port port) {
   try {
     return "sent message with count " + message.getBodyContentAsString();
   } catch (MessageException e) {
     getLogger().error("Error converting msg to string", e);
     return "";
   }
 }
Пример #4
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;
 }