Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
themeEmacs
public class SmartActor extends AbstractActor {
    @Override
    public Receive createReceive() {
        return receiveBuilder()
                .match(Integer.class, tableListnumber -> {    //단순하게 숫자의 입력을 받고 로그를 처리하는 액터이다.
                    Thread.sleep(500);  // delay for test
                    log.info(String.format("===== process msg:%s", name));
                })
                .matchAny(o -> log.info("received unknown message"))
                .build();
    }
}


@Test
public void testIt() throws InterruptedException {
    new TestKit(system) {{
        ActorRef probe = getRef();
        //6가지의 액터(태스크)를 두그룹으로 나누에 비동기 동시처리 진행
        ActorRef fastActor1 = system.actorOf(SmartActor.props("i'am fast").withDispatcher("fast-dispatcher"), "fast1");
        ActorRef fastActor2 = system.actorOf(SmartActor.props("i'am fast").withDispatcher("fast-dispatcher"), "fast2");
        ActorRef fastActor3 = system.actorOf(SmartActor.props("i'am fast").withDispatcher("fast-dispatcher"), "fast3");

        ActorRef slowActor1 = system.actorOf(SmartActor.props("i'am slow").withDispatcher("slow-dispatcher"), "slow1");
        ActorRef slowActor2 = system.actorOf(SmartActor.props("i'am slow").withDispatcher("slow-dispatcher"), "slow2");
        ActorRef slowActor3 = system.actorOf(SmartActor.props("i'am slow").withDispatcher("slow-dispatcher"), "slow3");

        for (int i = 0; i < 1000; i++) {
            fastActor1.tell(i, ActorRef.noSender());
            fastActor2.tell(i, ActorRef.noSender());
            fastActor3.tell(i, ActorRef.noSender());

            slowActor1.tell(i, ActorRef.noSender());
            slowActor2.tell(i, ActorRef.noSender());
            slowActor3.tell(i, ActorRef.noSender());
        }
    }};

...