Create akka ActorRef - Java Message

Java examples for Message:AKKA

Description

Create akka ActorRef

Demo Code



import akka.actor.UntypedActor;
import akka.actor.ActorSystem;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.japi.Procedure;

class BecomeActor extends UntypedActor
{
    Procedure<Object> procedure = new Procedure<Object>() {
        public void apply(Object message) throws Exception {
            System.out.println("become: " + message);
        }/*w ww. jav a  2s. c  o  m*/
    };

    @Override
    public void onReceive(Object message) throws Exception {
        System.out.println("Receive Message: " + message);

        getContext().become(procedure);
        System.out.println("---------------------------------------");
    }
}

public class BecomeActorDemo {
    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("sys");
        ActorRef ref = system.actorOf(Props.create(BecomeActor.class), "becomeActor");
        ref.tell("hello",ActorRef.noSender());
        ref.tell("hi",ActorRef.noSender());
        ref.tell("hi",ActorRef.noSender());
        ref.tell("hi",ActorRef.noSender());
        system.terminate();
    }
}

Related Tutorials