Slide 19
Slide 19 text
Basar Platform - “Hello World “akka style
final ActorSystem actorSystem = ActorSystem.create();
final ActorRef worldActorRef = actorSystem.actorOf(Props.create(World.class));
final ActorRef helloActorRef = actorSystem.actorOf(Props.create(Hello.class, worldActorRef));
Patterns.ask(helloActorRef, “tell”, new Timeout(500, TimeUnit.MILLISECONDS));
public Hello extends UntypedActor {
private final ActorRef worldActorRef;
public Hello(final ActorRef worldActorRef) {
this.worldActorRef = worldActorRef;
}
public onReceive(Object msg) throws Exception {
if(msg instanceof String.class) {
System.out.print(“Hello ”);
this.worldActorRef.tell(“Hello”,getSelf());
}
}
}
public World extends UntypedActor {
public onReceive(Object msg) throws Exception {
if(msg instanceof String.class) {
System.out.println(“World!”);
} else {
unhandledMessag(msg);
}
}
}