2016-07-20 4 views
1

初心者..のJavaアッカ俳優 - メッセージの調整と優先順位ここ

アッカバージョンの使用:Java APIを介して、アッカ・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" 
} 

My 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を見ることができません。私は優先順位を比較するためにそこに来なければならないと思います。

第2に、PdfGenerationActorは本質的にシステム全体の単一のインスタンスであるため、順次(1つずつ)実行されると思います。しかし、私はそれが起こっているとは思わない。私は同時に複数のアクターが要求を処理しているのを見る。

私はここで何か根本的な欠点があると思う。

答えて

0

あなたのケースでは、作成する各アクタは独自のルータを持っていますが、それ以外の場合は独立しているため、並列に実行されます。

リクエストを順番に実行したい場合は、各リクエストを1つずつ実行する1つの "ワーカー/ルート"を持つ1つのルータを持つことが考えられます。コード内

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

のドキュメント