Пример #1
0
  /**
   * This method is applied whenever messages are received by this operator.
   *
   * @param msg the message itself
   * @param from the operator from which the message has been sent
   * @return the post-processed message after processing and forwarding the merged message of all
   *     operands, which has been received from the succeeding operators
   */
  public Message receive(Message message, final BasicOperator from) {
    Message msg = message;
    if (from != null) {
      Map<BasicOperator, Message> received = this.messages.get(msg.getId());
      if (received == null) {
        received = new HashMap<BasicOperator, Message>();
        this.messages.put(msg.getId(), received);
      }
      received.put(from, msg);

      final HashSet<BasicOperator> operatorsWithoutCycles = new HashSet<BasicOperator>();
      operatorsWithoutCycles.addAll(this.precedingOperators);
      operatorsWithoutCycles.removeAll(this.cycleOperands);

      if (!received.keySet().containsAll(operatorsWithoutCycles)) {
        return null;
      }

      if (received.keySet().containsAll(this.precedingOperators)) {
        this.messages.remove(msg.getId());
      }
      msg = msg.merge(received.values(), this);
    }
    msg = msg.preProcess(this);
    msg = forwardMessage(msg);
    if (msg == null) return null;
    else return msg.postProcess(this);
  }
Пример #2
0
 /**
  * This method sends a message.
  *
  * @param msg the message to be sent
  * @return the received (and post-processed) message from the succeeding operators
  */
 public Message sendMessage(final Message msg) {
   Message msgResult = this.forwardMessage(msg.preProcess(this));
   // postprocess anyway one message, does not matter if the resultant msg is null or not to allow
   // processing right after initialization
   if (msgResult == null) {
     return msg.postProcess(this);
   } else {
     return msgResult.postProcess(this);
   }
 }