コード例 #1
0
  /**
   * *************************************************************************** BEGIN: Methods to
   * handle specificActor communication
   *
   * <p>taken from original communication pattern from Alex
   * ***************************************************************************
   */
  public static void answerSpecificActor(BasicActor gridActor, ActorRef sender) {
    if (!gridActor.detectCircle()) {
      gridActor.reportToParentEnabled = false;
      sender.tell(
          new DirectAnswerMessage(gridActor.getCurrentTimeStep(), gridActor.upStreamTrace, 0.0),
          gridActor.getSelf());
    } else {
      gridActor.reportToParentEnabled = true;

      sender.tell(
          new DirectAnswerMessage(gridActor.getCurrentTimeStep(), gridActor.upStreamTrace, 0.0),
          gridActor.getSelf());

      BasicAnswer basicAnswer =
          new BasicAnswer(
              gridActor.getCurrentTimeStep(),
              gridActor.upStreamTrace,
              true,
              false,
              gridActor.getSelf().path().toString(),
              gridActor.answerContent);

      gridActor.getContext().parent().tell(basicAnswer, gridActor.getSelf());
    }
  }
コード例 #2
0
  private static void executeAskSpecificChildrenLogic(
      BasicActor gridActor, SingleReceiverRequestContainer messages) throws Exception {
    // Patterns.ask() returns a Future<Object>
    List<Future<Object>> childrenResponseList = new ArrayList<Future<Object>>();

    for (SingleReceiverRequestContent secondMessage : messages.getRequests()) {
      for (ActorRef child : gridActor.getContext().getChildren()) {
        if (secondMessage.recieverPath.equals(child.path().toString())) {

          BasicRequest request =
              new BasicRequest(
                  gridActor.getCurrentTimeStep(), gridActor.downStreamTrace, secondMessage);
          ConstantLogger.logMessageSendCounter(request);
          // wait x ms for response
          childrenResponseList.add(
              Patterns.ask(child, request, GridArchitectConfiguration.childrenResponseTime));
        }
      }
    }

    Future<Iterable<Object>> childrenFuturesIterable =
        sequence(childrenResponseList, gridActor.getContext().system().dispatcher());
    Iterable<Object> childrenResponsesIterable =
        Await.result(
            childrenFuturesIterable,
            Duration.create(
                (GridArchitectConfiguration.childrenResponseTime),
                TimeUnit.MILLISECONDS)); // childrenResponsesIterableTimeOut

    gridActor.answerListReceived = new ArrayList<BasicAnswer>();
    for (Object receivedAnswer : childrenResponsesIterable) {

      gridActor.answerListReceived.add((BasicAnswer) receivedAnswer);

      ConstantLogger.logMessageSendCounter((BasicAnswer) receivedAnswer);

      if (((BasicAnswer) receivedAnswer).overrideReportToParent) {
        gridActor.reportToParentEnabled = true;
        gridActor.overrideReportToParent = true;
      }

      for (ActorRef actor : ((BasicAnswer) receivedAnswer).upstreamActorTrace) {
        gridActor.upStreamTrace.add(actor);
      }
    }
  }
コード例 #3
0
  private static void executeAskChildrenLogic(BasicActor gridActor, BasicRequest request)
      throws Exception {

    // Patterns.ask() returns a Future<Object>
    List<Future<Object>> childrenResponseList = new ArrayList<Future<Object>>();

    Iterable<ActorRef> children = gridActor.getContext().getChildren();

    for (ActorRef child : children) {
      ConstantLogger.logMessageSendCounter(request);
      // wait x ms for response
      childrenResponseList.add(
          Patterns.ask(
              child,
              request,
              GridArchitectConfiguration.childrenResponseTime)); // childrenResponseListTimeOut
    }

    Future<Iterable<Object>> childrenFuturesIterable =
        sequence(childrenResponseList, gridActor.getContext().system().dispatcher());
    Iterable<Object> childrenResponsesIterable =
        Await.result(
            childrenFuturesIterable,
            Duration.create(
                (GridArchitectConfiguration.childrenResponseTime),
                TimeUnit.MILLISECONDS)); // childrenResponsesIterableTimeOut	

    gridActor.answerListReceived = new ArrayList<BasicAnswer>();
    for (Object iteratorResponses : childrenResponsesIterable) {
      BasicAnswer receivedAnswer = (BasicAnswer) iteratorResponses;

      gridActor.answerListReceived.add(receivedAnswer);
      ConstantLogger.logMessageSendCounter(receivedAnswer);
      if (receivedAnswer.overrideReportToParent) {
        gridActor.reportToParentEnabled = true;
        gridActor.overrideReportToParent = true;
      }

      // if multiple levels of hierarchie exist all actors will be included in the list
      for (ActorRef actor : receivedAnswer.upstreamActorTrace) {
        gridActor.upStreamTrace.add(actor);
      }
    }
  }