2016-07-20 2 views
1

신참 ..자바 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는 본질적으로 시스템 전체의 단일 인스턴스이므로 순차적으로 (하나씩) 실행해야합니다. 그러나 나는 그런 일이 일어나지 않는다고 본다. 동시에 요청을 처리하는 여러 액터가 있습니다.

나는 근본적인 것이 빠져 있다고 생각합니다.

답변

0

당신의 경우에 어떤 일이 일어나는가는 자신이 만든 라우터에 자신의 라우터가 있다는 것입니다.하지만 그렇지 않은 경우에는 독립적입니다. 따라서 그들은 병렬로 실행됩니다.

요청을 순차적으로 실행하려면 각 요청을 하나씩 실행하는 하나의 "작업자/경로"가있는 라우터가 있어야합니다.

mypriority-mailbox { 
     mailbox-type = "com.x.y.config.PriorityMailbox" 
     mailbox-capacity = 500 #some stuff - you may want to check what you want here - if you want something 
     mailbox-push-timeout-time = 100s #some other stuff - check if it makes sense for you 
} 

actor { 
    /pdfRouter{ 
     router = round-robin-pool 
     nr-of-instances = 1 
     mailbox = mypriority-mailbox 
     } 
} 

코드에서 : 다음의 conf의

:

(물론 당신이 병렬로 실행할 요청 수를 구성 할 수 있습니다)

그래서 당신이 뭔가를 할 것이다 또한

system.actorOf(
      FromConfig.getInstance().props(PdfGeneratorActor.class), 
      "pdfRouter"); 
} 

체크 mailboxesrouters

에 대한 설명서