MasterActor作用:
1 , 由ActorContext 实例化MapActor、ReduceActor、AggregateActor
2,接收消息,以及消息转发给各个Actor
1 , 由ActorContext 实例化MapActor、ReduceActor、AggregateActor
2,接收消息,以及消息转发给各个Actor
点击(此处)折叠或打开
- /**
- * 管理各个Actor,以及作为消息的入口、进行消息的转发
- *
- */
- public class MasterActor extends UntypedActor {
- //由ActorContext创建Actor
- private ActorRef aggregateActor = getContext().actorOf(new Props(AggregateActor.class),"aggregate");
- private ActorRef reduceActor = getContext().actorOf(new Props(new UntypedActorFactory(){public Actor create() {return new ReduceActor(aggregateActor);}}),"reduce");
- private ActorRef mapActor = getContext().actorOf(new Props(new UntypedActorFactory(){public Actor create() {return new MapActor(reduceActor);}}),"map");
-
- @Override
- public void onReceive(Object message) throws Exception {
- if(message instanceof String){
- mapActor.tell(message);//fire-and-forget.非阻塞
- }else if(message instanceof Result){
- aggregateActor.tell(message);//让aggregateActor返回最终结果
- }else{
- unhandled(message);
- }
- }
- }
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28912557/viewspace-2089928/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28912557/viewspace-2089928/