(转)akka Router实例
通常在分布式任务调度系统中会有这样的需求:一组actor提供相同的服务,我们在调用任务的时候只需要选择其中一个actor进行处理即可。
其实这就是一个负载均衡或者说路由策略,akka作为一个高性能支持并发的actor模型,可以用来作为任务调度集群使用,当然负载均衡就是其本职工作了,akka提供了Router
来进行消息的调度。
由于负载均衡原理过于简单,既不多说了,直接上代码(这里借用之前章节的InboxTest类):
import akka.actor.*;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import com.typesafe.config.ConfigFactory;
import scala.concurrent.duration.Duration; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; /**
* Created by liubenlong on 2017/1/12.
*/
public class InboxTest extends UntypedActor { private final LoggingAdapter log = Logging.getLogger(getContext().system(), this); public enum Msg{
WORKING, DONE, CLOSE;
} @Override
public void onReceive(Object o) {
if(o == Msg.WORKING){
log.info("i am working.");
}else if(o == Msg.DONE){
log.info("i am done");
}else if(o == Msg.CLOSE){
log.info("i am close.");
getSender().tell(Msg.CLOSE, getSelf());//告诉消息发送者我要关闭了。
getContext().stop(getSelf());//关闭自己
}else{
unhandled(o);
}
} public static void main(String [] args){
ActorSystem system = ActorSystem.create("inbox", ConfigFactory.load("akka.conf"));
ActorRef inboxTest = system.actorOf(Props.create(InboxTest.class), "InboxTest"); Inbox inbox = Inbox.create(system);
inbox.watch(inboxTest);//监听一个actor //通过inbox来发送消息
inbox.send(inboxTest, Msg.WORKING);
inbox.send(inboxTest, Msg.DONE);
inbox.send(inboxTest, Msg.CLOSE); while(true){
try {
Object receive = inbox.receive(Duration.create(1, TimeUnit.SECONDS));
if(receive == Msg.CLOSE){//收到的inbox的消息
System.out.println("inboxTextActor is closing");
}else if(receive instanceof Terminated){//中断 ,和线程一个概念
System.out.println("inboxTextActor is closed");
system.shutdown();
break;
}else {
System.out.println(receive);
}
} catch (TimeoutException e) {
e.printStackTrace();
}
}
}
}
import akka.actor.*;
import akka.routing.*;
import com.typesafe.config.ConfigFactory; import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean; public class RouterTest extends UntypedActor { public Router router; {
ArrayList<Routee> 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) {
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
原文地址:http://blog.csdn.net/liubenlong007/article/details/54574064
(转)akka Router实例的更多相关文章
- Akka入门实例
Akka入门实例 Akka 是一个用 Scala 编写的库,用于简化编写容错的.高可伸缩性的 Java 和 Scala 的 Actor 模型应用. Actor模型并非什么新鲜事物,它由Carl Hew ...
- express 将 Router 实例模块化
为了更好的组织代码,将 Router 实例进行模块化,将 get / post 等快捷方式放在Router上,而不是 App 上,然后将该 Router 作为中间件,use 到 server.js 上 ...
- AKKA Router路由
路由概念 大量的actor在并行工作的时候,处理到来的消息流,这时候就需要一个组件或者东西来引导消息从源到目的地Actor,这个组件或者东西就是Router在Akka中,router也是一种actor ...
- 链接(跳转)<router-link> 和 路由实例Router
<router-link>和<router-link>传入的对象参数中包含path路径.name命名路由.params路径参数.query ?查询,并且如果提供了 path,p ...
- vue路由的简单实例
vue2.0 和 vue1.0 路由的语法还是有点稍微的差别,下面介绍一下vue-router 2的简单实例: <!DOCTYPE html> <html lang="en ...
- Router和History (路由控制)-backbone
Router和History (路由控制) Backbone.Router担任了一部分Controller(控制器)的工作,它一般运行在单页应用中,能将特定的URL或锚点规则绑定到一个指定的方法(后文 ...
- vue router 只需要这么几步
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Vue.js—组件快速入门以及实例应用
上次我们学习了Vue.js的基础,并且通过综合的小实例进一步的熟悉了Vue.js的基础应用.今天我们就继续讲讲Vue.js的组件,更加深入的了解Vue,js的使用.首先我们先了解一下什么是Vue.js ...
- 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 二十二║Vue实战:个人博客第一版(axios+router)
前言 今天正式开始写代码了,之前铺垫了很多了,包括 6 篇基础文章,一篇正式环境搭建,就是为了今天做准备,想温习的小伙伴可以再看看<Vue 基础入门+详细的环境搭建>,内容很多,这里就暂时 ...
随机推荐
- 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array
题目描述 Given an array A with length n a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integ ...
- JavaScript三种数据类型之间的互转
一:number<===>string 数字类型和字符串类型之间的互相转换 number===>string 数字转字符串有三种方式: 1.在数字后面 +“ ”; 2.利用字符串的 ...
- PHP设置会话(Session)超时过期时间实现登录时间限制[转]
用户登录系统60分钟后如果没有操作就自动退出 第一种方法即设置php.ini配置文件,设置session.gc_maxlifetime和session.cookie_lifetime节点属性值,当然也 ...
- 【BZOJ 2510】 2510: 弱题 (矩阵乘法、循环矩阵的矩阵乘法)
2510: 弱题 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 374 Solved: 196 Description 有M个球,一开始每个球均有一 ...
- 2017-2018-1 JAVA实验站 第四、五周作业
2017-2018-1 JAVA实验站 第四.五周作业 JAVA实验站小组成员 学号 名字 职务 20162318 张泰毓 组长 20162303 石亚鑫 组员 20162304 张浩林 组员 201 ...
- python3-开发进阶Flask的基础
一.概述 最大的特点:短小精悍.可拓展强的一个Web框架.注意点:上下文管理机制,依赖wsgi:werkzurg 模块 二.前奏学习werkzurg 先来回顾一个知识点:一个类加括号会执行__init ...
- Java并发(十三):并发工具类——同步屏障CyclicBarrier
先做总结 1.CyclicBarrier 是什么? CyclicBarrier 的字面意思是可循环使用(Cyclic)的屏障(Barrier).它要做的事情是,让一组线程到达一个屏障(也可以叫同步点) ...
- hdu 1711
读入优化有3s多. #include <cstdio> #include <cctype> #define maxn 1000010 #define maxm 10010 in ...
- ExtJs2.0学习系列(12)--Ext.TreePanel之第一式
今天开始,我们就开始一起学习TreePanel了,道个歉,上篇的代码很乱阿. 我总是喜欢用最简单的例子开始,去理解最基本的使用方法,减少对i后面高级使用的干扰! TreePanel是继承自Panel, ...
- Get just enough boost voltage - current-mirror circuit - VOUT tracks VIN varies
Adding a current-mirror circuit to a typical boost circuit allows you to select the amount of boost ...