private void setOperational(final ActorIdentity pingResponse) {

    if (mediaQueue == null && IDENTIFY_MEDIA_QUEUE_ID.equals(pingResponse.correlationId())) {
      mediaQueue = pingResponse.getRef();
    }

    if (mediaDecoder == null && IDENTIFY_MEDIA_DECODER_ID.equals(pingResponse.correlationId())) {
      mediaDecoder = pingResponse.getRef();
    }

    if (mediaQueue != null && mediaDecoder != null) {
      getContext()
          .become(
              ReceiveBuilder.match(ImageSegment.class, msg -> build(msg))
                  .match(ImageData.class, msg -> breakDown(msg))
                  .match(AudioData.class, msg -> handleCommon(msg, mediaQueue))
                  .match(FrameRate.class, msg -> handleCommon(msg, mediaQueue))
                  .match(Play.class, msg -> handleCommon(msg, mediaQueue, mediaDecoder))
                  .match(Pause.class, msg -> handleCommon(msg, mediaQueue, mediaDecoder))
                  .match(Connect.class, msg -> handleConnect(msg))
                  .match(JoinRequest.class, msg -> handleRequest(msg))
                  .match(JoinAck.class, msg -> handleAck(msg))
                  .match(NewMember.class, msg -> handleNewMember(msg))
                  .build());
    }
  }
Ejemplo n.º 2
0
 @Test
 public void useAskWithActorSelection() throws Exception {
   ActorRef testActor = system.actorOf(Props.create(JavaAPITestActor.class), "test2");
   ActorSelection selection = system.actorSelection("/user/test2");
   ActorIdentity id =
       (ActorIdentity)
           Await.result(ask(selection, new Identify("yo!"), 3000), Duration.create(3, "seconds"));
   assertEquals("Ask (Identify) should return the proper ActorIdentity", testActor, id.getRef());
 }
Ejemplo n.º 3
0
 @Override
 public void onReceive(Object message) {
   if (message instanceof ActorIdentity) {
     ActorIdentity identity = (ActorIdentity) message;
     if (identity.correlationId().equals(identifyId)) {
       ActorRef ref = identity.getRef();
       if (ref == null) getContext().stop(getSelf());
       else {
         another = ref;
         getContext().watch(another);
         // #test-omitted
         probe.tell(ref, getSelf());
         // #test-omitted
       }
     }
   } else if (message instanceof Terminated) {
     final Terminated t = (Terminated) message;
     if (t.getActor().equals(another)) {
       getContext().stop(getSelf());
     }
   } else {
     unhandled(message);
   }
 }