Log akka event - Java Message

Java examples for Message:AKKA

Description

Log akka event

Demo Code



import akka.actor.UntypedActor;
import akka.actor.ActorSystem;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.event.LoggingAdapter;
import akka.event.Logging;


public class UntypedActorDemo {
    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("sys");
        ActorRef actorRef = system.actorOf(Props.create(ActorDemo.class), "actorDemo");
        //from  w w  w.  j  a v  a2s .  c om
        for (int i = 0; i < 10; i++) {
          actorRef.tell("Hello Akka", ActorRef.noSender());
        }
    }
}

class ActorDemo extends UntypedActor {
    private LoggingAdapter log = Logging.getLogger(this.getContext().system(), this);

    @Override
    public void onReceive(Object message) {
        if (message instanceof String) {
            log.info(message.toString());
        } else {
            unhandled(message);
        }
    }
}

Related Tutorials