신참 ..자바 Akka 배우 - 메시지 제한 및 우선 순위 여기
akka 버전 사용 : 자바 API를 통해 akka-actor_2.11 (2.4.8 참조).
PDF 문서를 생성하기위한 액터를 개발하려고합니다. 이러한 PDF 문서는 크기가 클 수 있으므로 배우가 요청을 처리하는 속도를 조절하고 싶습니다. 또한 측면 요구 사항으로, PDF 생성 요청을 기본 액터의 우선 순위에 따라 처리 할 수있는 "우선 순위 지정 가능"수신함이 필요합니다. 내 응용 프로그램 시작에서
,이 같은 글로벌 소품을 만들 : 다음
Props.create(PdfGeneratorActor.class).withDispatcher("prio-dispatcher").withRouter(new RoundRobinPool(1))
내가 같이 PDF의 요청에 따라 배우를 만듭니다
actorSystem.actorOf(propsObjShownAbove, actorType.getCanonicalName() + "_" + UUID.randomUUID());
내 application.conf은 다음과 같습니다
prio-dispatcher {
mailbox-type = "com.x.y.config.PriorityMailbox"
}
내 PriorityMailbox는 다음과 같습니다.
public class PriorityMailbox extends UnboundedPriorityMailbox {
// needed for reflective instantiation
public PriorityMailbox(final ActorSystem.Settings settings, final Config config) {
super(new PriorityGenerator() {
@Override
public int gen(final Object message) {
System.out.println("Here is my message to be prioritized: "+message);
if (message instanceof Prioritizable) {
Prioritizable prioritizable = (Prioritizable) message;
if (prioritizable.getReportPriorityType() == ReportPriorityType.HIGH) {
return 0;
} else if (prioritizable.getReportPriorityType() == ReportPriorityType.LOW) {
return 2;
} else if (message.equals(PoisonPill.getInstance())) {
return 3; // PoisonPill when no other left
} else {
return 1;
}
} else {
// Default priority for any other messages.
return 1;
}
}
});
}
}
내가 원하는 것을 달성하기위한 올바른 구성입니까? 내가 뭔가를 놓치고 있는지 확실하지 않습니다. 첫째, 내 사서함 구현에서 System.out.prints를 볼 수 없습니다. 나는 우선 순위를 비교하기 위해 그곳에 와야한다고 생각한다.
두 번째로, PdfGenerationActor는 본질적으로 시스템 전체의 단일 인스턴스이므로 순차적으로 (하나씩) 실행해야합니다. 그러나 나는 그런 일이 일어나지 않는다고 본다. 동시에 요청을 처리하는 여러 액터가 있습니다.
나는 근본적인 것이 빠져 있다고 생각합니다.