akka学习教程(六) 路由器Router

akka系列文章目录

  • akka学习教程(十四) akka分布式实战
  • akka学习教程(十三) akka分布式
  • akka学习教程(十二) Spring与Akka的集成
  • akka学习教程(十一) akka持久化
  • akka学习教程(十) agent
  • akka学习教程(九) STM软件事务内存
  • akka学习教程(八) Actor中的Future-询问模式
  • akka学习教程(七) 内置状态转换Procedure
  • akka学习教程(六) 路由器Router
  • akka学习教程(五) inbox消息收件箱
  • akka学习教程(四) actor生命周期
  • akka学习教程(三) 不可变对象
  • akka学习教程(二)HelloWord
  • akka学习教程(一)简介

通常在分布式任务调度系统中会有这样的需求:一组actor提供相同的服务,我们在调用任务的时候只需要选择其中一个actor进行处理即可。
其实这就是一个负载均衡或者说路由策略,akka作为一个高性能支持并发的actor模型,可以用来作为任务调度集群使用,当然负载均衡就是其本职工作了,akka提供了Router来进行消息的调度。

由于负载均衡原理过于简单,既不多说了,直接上代码(这里借用之前章节的InboxTest类):

package akka.router;

import akka.actor.*;
import akka.iInbox.InboxTest;
import akka.routing.*;
import com.typesafe.config.ConfigFactory;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created by liubenlong on 2017/1/12.
 */
public class RouterTest extends UntypedActor {

    public Router router;

    {
        ArrayList routees = new ArrayList<>();
        for(int i = 0; i < 5; i ++) {
            //借用上面的 inboxActor
            ActorRef worker = getContext().actorOf(Props.create(InboxTest.class), "worker_" + i);
            getContext().watch(worker);//监听
            routees.add(new ActorRefRoutee(worker));
        }
        /**
         * RoundRobinRoutingLogic: 轮询
         * BroadcastRoutingLogic: 广播
         * RandomRoutingLogic: 随机
         * SmallestMailboxRoutingLogic: 空闲
         */
        router = new Router(new RoundRobinRoutingLogic(), routees);
    }

    @Override
    public void onReceive(Object o) throws Throwable {
        if(o instanceof InboxTest.Msg){
            router.route(o, getSender());//进行路由转发
        }else if(o instanceof Terminated){
            router = router.removeRoutee(((Terminated)o).actor());//发生中断,将该actor删除。当然这里可以参考之前的actor重启策略,进行优化,为了简单,这里仅进行删除处理
            System.out.println(((Terminated)o).actor().path() + " 该actor已经删除。router.size=" + router.routees().size());

            if(router.routees().size() == 0){//没有可用actor了
                System.out.print("没有可用actor了,系统关闭。");
                flag.compareAndSet(true, false);
                getContext().system().shutdown();
            }
        }else {
            unhandled(o);
        }

    }


    public  static AtomicBoolean flag = new AtomicBoolean(true);

    public static void main(String[] args) throws InterruptedException {
        ActorSystem system = ActorSystem.create("strategy", ConfigFactory.load("akka.config"));
        ActorRef routerTest = system.actorOf(Props.create(RouterTest.class), "RouterTest");

        int i = 1;
        while(flag.get()){
            routerTest.tell(InboxTest.Msg.WORKING, ActorRef.noSender());

            if(i % 10 == 0) routerTest.tell(InboxTest.Msg.CLOSE, ActorRef.noSender());

            Thread.sleep(500);

            i ++;
        }
    }
}

akka提供了几个RoutingLogic各位可以亲自尝试运行一下,看看效果。

运行结果:

"D:\Program Files\Java\jdk1.8.0_111\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=D:\Program Files (x86)\ideaIU-2016.2.5\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\Java\jdk1.8.0_111\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\deploy.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\access-bridge-64.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\cldrdata.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\dnsns.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jaccess.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jfxrt.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\localedata.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\nashorn.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunec.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunjce_provider.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunmscapi.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunpkcs11.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\zipfs.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\javaws.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jce.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jfxswt.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\management-agent.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\plugin.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\rt.jar;D:\workspace_git_idea\luffi-master\luffi\target\test-classes;D:\workspace_git_idea\luffi-master\luffi\target\classes;D:\LocalRepository\commons-fileupload\commons-fileupload\1.3.2\commons-fileupload-1.3.2.jar;D:\LocalRepository\commons-io\commons-io\2.2\commons-io-2.2.jar;D:\LocalRepository\org\apache\httpcomponents\httpmime\4.3.1\httpmime-4.3.1.jar;D:\LocalRepository\org\apache\httpcomponents\httpclient\4.3.1\httpclient-4.3.1.jar;D:\LocalRepository\org\apache\httpcomponents\httpcore\4.3\httpcore-4.3.jar;D:\LocalRepository\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar;D:\LocalRepository\commons-codec\commons-codec\1.6\commons-codec-1.6.jar;D:\LocalRepository\com\alibaba\fastjson\1.2.17\fastjson-1.2.17.jar;D:\LocalRepository\com\letv\openapi\openapi-sdk-java\1.0.0-SNAPSHOT\openapi-sdk-java-1.0.0-20160721.094717-1.jar;D:\LocalRepository\org\slf4j\slf4j-api\1.7.5\slf4j-api-1.7.5.jar;D:\workspace_git_idea\luffi-master\luffi-api\target\classes;D:\workspace_git_idea\luffi-master\luffi-model\target\classes;D:\LocalRepository\org\apache\commons\commons-lang3\3.1\commons-lang3-3.1.jar;D:\LocalRepository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;D:\LocalRepository\javax\el\javax.el-api\2.2.4\javax.el-api-2.2.4.jar;D:\LocalRepository\org\glassfish\web\javax.el\2.2.4\javax.el-2.2.4.jar;D:\LocalRepository\org\hibernate\hibernate-validator\5.2.4.Final\hibernate-validator-5.2.4.Final.jar;D:\LocalRepository\org\projectlombok\lombok-maven-plugin\1.12.2.0\lombok-maven-plugin-1.12.2.0.jar;D:\LocalRepository\com\github\pagehelper\pagehelper\4.1.1\pagehelper-4.1.1.jar;D:\LocalRepository\com\github\jsqlparser\jsqlparser\0.9.4\jsqlparser-0.9.4.jar;D:\LocalRepository\org\apache\thrift\libthrift\0.9.3\libthrift-0.9.3.jar;D:\LocalRepository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;D:\LocalRepository\javax\ws\rs\javax.ws.rs-api\2.0.1\javax.ws.rs-api-2.0.1.jar;D:\LocalRepository\javax\annotation\javax.annotation-api\1.2\javax.annotation-api-1.2.jar;D:\workspace_git_idea\luffi-master\luffi-repository\target\classes;D:\LocalRepository\tk\mybatis\mapper\3.3.8\mapper-3.3.8.jar;D:\LocalRepository\javax\persistence\persistence-api\1.0\persistence-api-1.0.jar;D:\LocalRepository\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.1.1\mybatis-spring-boot-starter-1.1.1.jar;D:\LocalRepository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.1.1\mybatis-spring-boot-autoconfigure-1.1.1.jar;D:\LocalRepository\org\mybatis\mybatis\3.4.0\mybatis-3.4.0.jar;D:\LocalRepository\org\mybatis\mybatis-spring\1.3.0\mybatis-spring-1.3.0.jar;D:\LocalRepository\org\springframework\boot\spring-boot\1.3.6.RELEASE\spring-boot-1.3.6.RELEASE.jar;D:\LocalRepository\org\springframework\boot\spring-boot-autoconfigure\1.3.6.RELEASE\spring-boot-autoconfigure-1.3.6.RELEASE.jar;D:\LocalRepository\org\springframework\boot\spring-boot-starter-jdbc\1.3.3.RELEASE\spring-boot-starter-jdbc-1.3.3.RELEASE.jar;D:\LocalRepository\org\springframework\boot\spring-boot-starter\1.3.6.RELEASE\spring-boot-starter-1.3.6.RELEASE.jar;D:\LocalRepository\org\apache\tomcat\tomcat-jdbc\8.0.32\tomcat-jdbc-8.0.32.jar;D:\LocalRepository\org\apache\tomcat\tomcat-juli\8.0.32\tomcat-juli-8.0.32.jar;D:\LocalRepository\org\springframework\spring-jdbc\4.2.5.RELEASE\spring-jdbc-4.2.5.RELEASE.jar;D:\LocalRepository\org\springframework\spring-beans\4.2.4.RELEASE\spring-beans-4.2.4.RELEASE.jar;D:\LocalRepository\org\springframework\spring-core\4.2.4.RELEASE\spring-core-4.2.4.RELEASE.jar;D:\LocalRepository\org\springframework\spring-tx\4.2.5.RELEASE\spring-tx-4.2.5.RELEASE.jar;D:\workspace_git_idea\luffi-master\luffi-common\target\classes;D:\LocalRepository\org\apache\zookeeper\zookeeper\3.4.8\zookeeper-3.4.8.jar;D:\LocalRepository\jline\jline\0.9.94\jline-0.9.94.jar;D:\LocalRepository\io\netty\netty\3.7.0.Final\netty-3.7.0.Final.jar;D:\LocalRepository\com\101tec\zkclient\0.9\zkclient-0.9.jar;D:\LocalRepository\log4j\log4j\1.2.15\log4j-1.2.15.jar;D:\LocalRepository\javax\mail\mail\1.4\mail-1.4.jar;D:\LocalRepository\javax\activation\activation\1.1\activation-1.1.jar;D:\LocalRepository\com\alibaba\dubbo\2.8.4.lehi\dubbo-2.8.4.lehi.jar;D:\LocalRepository\org\springframework\spring-context\4.2.4.RELEASE\spring-context-4.2.4.RELEASE.jar;D:\LocalRepository\org\springframework\spring-aop\4.2.4.RELEASE\spring-aop-4.2.4.RELEASE.jar;D:\LocalRepository\org\springframework\spring-expression\4.2.4.RELEASE\spring-expression-4.2.4.RELEASE.jar;D:\LocalRepository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\LocalRepository\org\apache\logging\log4j\log4j-core\2.5\log4j-core-2.5.jar;D:\LocalRepository\org\apache\logging\log4j\log4j-api\2.5\log4j-api-2.5.jar;D:\LocalRepository\org\javassist\javassist\3.15.0-GA\javassist-3.15.0-GA.jar;D:\LocalRepository\org\springframework\spring-web\4.2.4.RELEASE\spring-web-4.2.4.RELEASE.jar;D:\LocalRepository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\LocalRepository\commons-pool\commons-pool\1.6\commons-pool-1.6.jar;D:\LocalRepository\org\apache\curator\curator-framework\2.5.0\curator-framework-2.5.0.jar;D:\LocalRepository\org\apache\curator\curator-client\2.5.0\curator-client-2.5.0.jar;D:\LocalRepository\com\google\guava\guava\16.0.1\guava-16.0.1.jar;D:\LocalRepository\org\yaml\snakeyaml\1.16\snakeyaml-1.16.jar;D:\LocalRepository\org\springframework\boot\spring-boot-starter-web\1.3.6.RELEASE\spring-boot-starter-web-1.3.6.RELEASE.jar;D:\LocalRepository\org\springframework\boot\spring-boot-starter-validation\1.3.6.RELEASE\spring-boot-starter-validation-1.3.6.RELEASE.jar;D:\LocalRepository\org\apache\tomcat\embed\tomcat-embed-el\8.0.36\tomcat-embed-el-8.0.36.jar;D:\LocalRepository\com\fasterxml\jackson\core\jackson-databind\2.6.7\jackson-databind-2.6.7.jar;D:\LocalRepository\com\fasterxml\jackson\core\jackson-annotations\2.6.0\jackson-annotations-2.6.0.jar;D:\LocalRepository\com\fasterxml\jackson\core\jackson-core\2.6.7\jackson-core-2.6.7.jar;D:\LocalRepository\org\springframework\spring-webmvc\4.2.7.RELEASE\spring-webmvc-4.2.7.RELEASE.jar;D:\LocalRepository\org\springframework\boot\spring-boot-starter-log4j2\1.3.6.RELEASE\spring-boot-starter-log4j2-1.3.6.RELEASE.jar;D:\LocalRepository\org\apache\logging\log4j\log4j-slf4j-impl\2.4.1\log4j-slf4j-impl-2.4.1.jar;D:\LocalRepository\org\slf4j\jcl-over-slf4j\1.7.21\jcl-over-slf4j-1.7.21.jar;D:\LocalRepository\org\slf4j\jul-to-slf4j\1.7.21\jul-to-slf4j-1.7.21.jar;D:\LocalRepository\mysql\mysql-connector-java\5.1.39\mysql-connector-java-5.1.39.jar;D:\LocalRepository\org\jboss\logging\jboss-logging\3.2.1.Final\jboss-logging-3.2.1.Final.jar;D:\LocalRepository\com\fasterxml\classmate\1.1.0\classmate-1.1.0.jar;D:\LocalRepository\org\jboss\resteasy\resteasy-jaxrs\3.0.9.Final\resteasy-jaxrs-3.0.9.Final.jar;D:\LocalRepository\org\jboss\resteasy\jaxrs-api\3.0.9.Final\jaxrs-api-3.0.9.Final.jar;D:\LocalRepository\org\jboss\spec\javax\annotation\jboss-annotations-api_1.1_spec\1.0.1.Final\jboss-annotations-api_1.1_spec-1.0.1.Final.jar;D:\LocalRepository\net\jcip\jcip-annotations\1.0\jcip-annotations-1.0.jar;D:\LocalRepository\org\jboss\resteasy\resteasy-client\3.0.9.Final\resteasy-client-3.0.9.Final.jar;D:\LocalRepository\org\jboss\resteasy\resteasy-netty\3.0.14.Final\resteasy-netty-3.0.14.Final.jar;D:\LocalRepository\org\jboss\resteasy\resteasy-jdk-http\3.0.14.Final\resteasy-jdk-http-3.0.14.Final.jar;D:\LocalRepository\org\jboss\resteasy\resteasy-jackson-provider\3.0.14.Final\resteasy-jackson-provider-3.0.14.Final.jar;D:\LocalRepository\org\codehaus\jackson\jackson-core-asl\1.9.12\jackson-core-asl-1.9.12.jar;D:\LocalRepository\org\codehaus\jackson\jackson-mapper-asl\1.9.12\jackson-mapper-asl-1.9.12.jar;D:\LocalRepository\org\codehaus\jackson\jackson-jaxrs\1.9.12\jackson-jaxrs-1.9.12.jar;D:\LocalRepository\org\codehaus\jackson\jackson-xc\1.9.12\jackson-xc-1.9.12.jar;D:\LocalRepository\org\jboss\resteasy\resteasy-jaxb-provider\3.0.16.Final\resteasy-jaxb-provider-3.0.16.Final.jar;D:\LocalRepository\com\sun\xml\bind\jaxb-impl\2.2.7\jaxb-impl-2.2.7.jar;D:\LocalRepository\com\sun\xml\bind\jaxb-core\2.2.7\jaxb-core-2.2.7.jar;D:\LocalRepository\javax\xml\bind\jaxb-api\2.2.7\jaxb-api-2.2.7.jar;D:\LocalRepository\com\sun\istack\istack-commons-runtime\2.16\istack-commons-runtime-2.16.jar;D:\LocalRepository\com\sun\xml\fastinfoset\FastInfoset\1.2.12\FastInfoset-1.2.12.jar;D:\LocalRepository\javax\xml\bind\jsr173_api\1.0\jsr173_api-1.0.jar;D:\LocalRepository\org\apache\tomcat\embed\tomcat-embed-core\8.0.11\tomcat-embed-core-8.0.11.jar;D:\LocalRepository\org\apache\tomcat\embed\tomcat-embed-logging-juli\8.0.11\tomcat-embed-logging-juli-8.0.11.jar;D:\LocalRepository\junit\junit\4.12\junit-4.12.jar;D:\LocalRepository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\LocalRepository\org\springframework\spring-test\4.2.4.RELEASE\spring-test-4.2.4.RELEASE.jar;D:\LocalRepository\redis\clients\jedis\2.9.0\jedis-2.9.0.jar;D:\LocalRepository\org\apache\commons\commons-pool2\2.4.2\commons-pool2-2.4.2.jar;D:\LocalRepository\org\springframework\spring-context-support\4.2.4.RELEASE\spring-context-support-4.2.4.RELEASE.jar;D:\LocalRepository\org\quartz-scheduler\quartz\2.2.3\quartz-2.2.3.jar;D:\LocalRepository\c3p0\c3p0\0.9.1.1\c3p0-0.9.1.1.jar;D:\LocalRepository\com\typesafe\akka\akka-actor_2.11\2.4.14\akka-actor_2.11-2.4.14.jar;D:\LocalRepository\org\scala-lang\scala-library\2.11.8\scala-library-2.11.8.jar;D:\LocalRepository\com\typesafe\config\1.3.0\config-1.3.0.jar;D:\LocalRepository\org\scala-lang\modules\scala-java8-compat_2.11\0.7.0\scala-java8-compat_2.11-0.7.0.jar;D:\LocalRepository\org\apache\maven\maven-plugin-api\3.0.4\maven-plugin-api-3.0.4.jar;D:\LocalRepository\org\apache\maven\maven-model\3.0.4\maven-model-3.0.4.jar;D:\LocalRepository\org\codehaus\plexus\plexus-utils\2.0.6\plexus-utils-2.0.6.jar;D:\LocalRepository\org\apache\maven\maven-artifact\3.0.4\maven-artifact-3.0.4.jar;D:\LocalRepository\org\sonatype\sisu\sisu-inject-plexus\2.3.0\sisu-inject-plexus-2.3.0.jar;D:\LocalRepository\org\codehaus\plexus\plexus-component-annotations\1.5.5\plexus-component-annotations-1.5.5.jar;D:\LocalRepository\org\codehaus\plexus\plexus-classworlds\2.4\plexus-classworlds-2.4.jar;D:\LocalRepository\org\sonatype\sisu\sisu-inject-bean\2.3.0\sisu-inject-bean-2.3.0.jar;D:\LocalRepository\org\sonatype\sisu\sisu-guice\3.1.0\sisu-guice-3.1.0-no_aop.jar;D:\LocalRepository\org\sonatype\sisu\sisu-guava\0.9.9\sisu-guava-0.9.9.jar;D:\LocalRepository\org\projectlombok\lombok\1.12.2\lombok-1.12.2.jar;D:\Program Files (x86)\ideaIU-2016.2.5\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain akka.router.RouterTest
[INFO] [01/16/2017 14:46:44.010] [strategy-akka.actor.default-dispatcher-6] [akka://strategy/user/RouterTest/worker_0] i am working.
[INFO] [01/16/2017 14:46:44.481] [strategy-akka.actor.default-dispatcher-9] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:46:44.981] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_2] i am working.
[INFO] [01/16/2017 14:46:45.481] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:46:45.981] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_4] i am working.
[INFO] [01/16/2017 14:46:46.514] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_0] i am working.
[INFO] [01/16/2017 14:46:47.021] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:46:47.492] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_2] i am working.
[INFO] [01/16/2017 14:46:47.992] [strategy-akka.actor.default-dispatcher-10] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:46:48.492] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_4] i am working.
[INFO] [01/16/2017 14:46:48.492] [strategy-akka.actor.default-dispatcher-9] [akka://strategy/user/RouterTest/worker_0] i am close.
[INFO] [01/16/2017 14:46:48.502] [strategy-akka.actor.default-dispatcher-10] [akka://strategy/deadLetters] Message [akka.iInbox.InboxTest$Msg] from Actor[akka://strategy/user/RouterTest/worker_0#-492254864] to Actor[akka://strategy/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
akka://strategy/user/RouterTest/worker_0 该actor已经删除。router.size=4
[INFO] [01/16/2017 14:46:48.992] [strategy-akka.actor.default-dispatcher-9] [akka://strategy/user/RouterTest/worker_4] i am working.
[INFO] [01/16/2017 14:46:49.507] [strategy-akka.actor.default-dispatcher-9] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:46:50.035] [strategy-akka.actor.default-dispatcher-7] [akka://strategy/user/RouterTest/worker_2] i am working.
[INFO] [01/16/2017 14:46:50.507] [strategy-akka.actor.default-dispatcher-9] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:46:51.007] [strategy-akka.actor.default-dispatcher-7] [akka://strategy/user/RouterTest/worker_4] i am working.
[INFO] [01/16/2017 14:46:51.507] [strategy-akka.actor.default-dispatcher-9] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:46:52.011] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_2] i am working.
[INFO] [01/16/2017 14:46:52.536] [strategy-akka.actor.default-dispatcher-7] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:46:53.036] [strategy-akka.actor.default-dispatcher-9] [akka://strategy/user/RouterTest/worker_4] i am working.
akka://strategy/user/RouterTest/worker_2 该actor已经删除。router.size=3
[INFO] [01/16/2017 14:46:53.522] [strategy-akka.actor.default-dispatcher-9] [akka://strategy/user/RouterTest/worker_2] i am close.
[INFO] [01/16/2017 14:46:53.522] [strategy-akka.actor.default-dispatcher-7] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:46:53.522] [strategy-akka.actor.default-dispatcher-9] [akka://strategy/deadLetters] Message [akka.iInbox.InboxTest$Msg] from Actor[akka://strategy/user/RouterTest/worker_2#519939307] to Actor[akka://strategy/deadLetters] was not delivered. [2] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[INFO] [01/16/2017 14:46:54.022] [strategy-akka.actor.default-dispatcher-10] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:46:54.522] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_4] i am working.
[INFO] [01/16/2017 14:46:55.022] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:46:55.522] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:46:56.022] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_4] i am working.
[INFO] [01/16/2017 14:46:56.522] [strategy-akka.actor.default-dispatcher-7] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:46:57.023] [strategy-akka.actor.default-dispatcher-7] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:46:57.523] [strategy-akka.actor.default-dispatcher-7] [akka://strategy/user/RouterTest/worker_4] i am working.
[INFO] [01/16/2017 14:46:58.023] [strategy-akka.actor.default-dispatcher-7] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:46:58.566] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:46:58.566] [strategy-akka.actor.default-dispatcher-10] [akka://strategy/user/RouterTest/worker_4] i am close.
akka://strategy/user/RouterTest/worker_4 该actor已经删除。router.size=2
[INFO] [01/16/2017 14:46:58.566] [strategy-akka.actor.default-dispatcher-10] [akka://strategy/deadLetters] Message [akka.iInbox.InboxTest$Msg] from Actor[akka://strategy/user/RouterTest/worker_4#50964955] to Actor[akka://strategy/deadLetters] was not delivered. [3] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[INFO] [01/16/2017 14:46:59.076] [strategy-akka.actor.default-dispatcher-4] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:46:59.547] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:00.047] [strategy-akka.actor.default-dispatcher-4] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:47:00.547] [strategy-akka.actor.default-dispatcher-4] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:01.047] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:47:01.582] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:02.091] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_3] i am working.
[INFO] [01/16/2017 14:47:02.562] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:03.062] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_3] i am working.
akka://strategy/user/RouterTest/worker_3 该actor已经删除。router.size=1
[INFO] [01/16/2017 14:47:03.562] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:03.562] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/user/RouterTest/worker_3] i am close.
[INFO] [01/16/2017 14:47:03.563] [strategy-akka.actor.default-dispatcher-3] [akka://strategy/deadLetters] Message [akka.iInbox.InboxTest$Msg] from Actor[akka://strategy/user/RouterTest/worker_3#-667250877] to Actor[akka://strategy/deadLetters] was not delivered. [4] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[INFO] [01/16/2017 14:47:04.062] [strategy-akka.actor.default-dispatcher-10] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:04.597] [strategy-akka.actor.default-dispatcher-10] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:05.099] [strategy-akka.actor.default-dispatcher-4] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:05.570] [strategy-akka.actor.default-dispatcher-4] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:06.070] [strategy-akka.actor.default-dispatcher-4] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:06.570] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:07.070] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:07.611] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:08.112] [strategy-akka.actor.default-dispatcher-4] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:08.583] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_1] i am working.
[INFO] [01/16/2017 14:47:08.583] [strategy-akka.actor.default-dispatcher-5] [akka://strategy/user/RouterTest/worker_1] i am close.
[INFO] [01/16/2017 14:47:08.585] [strategy-akka.actor.default-dispatcher-9] [akka://strategy/deadLetters] Message [akka.iInbox.InboxTest$Msg] from Actor[akka://strategy/user/RouterTest/worker_1#255839262] to Actor[akka://strategy/deadLetters] was not delivered. [5] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
akka://strategy/user/RouterTest/worker_1 该actor已经删除。router.size=0
没有可用actor了,系统关闭。
Process finished with exit code 0

参考资料

  • 书籍《java高并发程序设计》
  • AKKA官方文档

你可能感兴趣的:(分布式+高并发,akka学习教程)