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); } } }
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); } } }