@Override
 // #pull-accepting
 public void onReceive(Object message) throws Exception {
   if (message instanceof Tcp.Bound) {
     listener = getSender();
     // Accept connections one by one
     listener.tell(TcpMessage.resumeAccepting(1), getSelf());
   } else if (message instanceof Tcp.Connected) {
     ActorRef handler = getContext().actorOf(Props.create(PullEcho.class, getSender()));
     getSender().tell(TcpMessage.register(handler), getSelf());
     // Resume accepting connections
     listener.tell(TcpMessage.resumeAccepting(1), getSelf());
   }
 }
Exemple #2
0
 private void registerCodec(ActorRef connection) {
   final Props codecProps = Props.create(MsgCodec.class, connection, msgHandler);
   final ActorRef codec = getContext().actorOf(codecProps);
   connection.tell(TcpMessage.register(codec), getSelf());
 }