나는 akka에서 더 초심하고 교육하는 동안 다음 질문이 있습니다.
예를 들어 다른 두 명의 아역에게 메시지를 보내는 주연이 있습니다. 둘 다 다른 목록을 반환합니다.
ChildActorA return Optional<List<Entity1>>
ChildActorB return Optional<List<Entity2>>
이 답변을 처리하기 위해 주연을 어떻게 매치시킬 수 있습니까?
일부 데모 코드 :
public class MainActor extends AbstractLoggingActor {
@Override
public Receive createReceive() {
return receiveBuilder()
.match(Entity1.class, this::onEntity1)
.match(Entity2.class, this::onEntity2)
//How match to the list of these entities?
.match(Optional<List<Entity1>>, this::onList1)
.match(Optional<List<Entity2>>, this::onList2)
.build();
}
}
private void onEntity1(Entity1 entity1) {
final ActorRef entity1ChildActor = getContext().actorOf(Entity1ChildActor.props());
entity1ChildActor.tell("printIt", getSelf());
}
private void onEntity2(Entity2 entity2) {
final ActorRef entity21ChildActor = getContext().actorOf(Entity2ChildActor.props());
entity2ChildActor.tell("printIt", getSelf());
}
어린이 배우 중 한 명 :
public class Entity1ChildActor extends AbstractLoggingActor {
@Override
public Receive createReceive() {
return receiveBuilder()
.match(String.class, this::onPrint)
.build();
}
private void onPrint(Entity1 entity1) {
System.out.println(entity1);
//Here I want to tell to parent List of something
//namely Optional<List<Entity1>>
//How can I match parent behavior?
getSender().tell(someOptionalList, getSelf());
}
public static Props props(){
return Props.create(Entity1ChildActor.class);
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다