add akka.Main and use that to add Hello World docs
- akka.Main will start an ActorSystem and one actor; when that actor terminates the system is shut down - HelloWorld sample with two actors
This commit is contained in:
parent
a4b485968c
commit
651f699893
11 changed files with 254 additions and 2 deletions
26
akka-docs/rst/java/code/docs/actor/japi/Greeter.java
Normal file
26
akka-docs/rst/java/code/docs/actor/japi/Greeter.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package docs.actor.japi;
|
||||
|
||||
import akka.actor.UntypedActor;
|
||||
import java.io.Serializable;
|
||||
|
||||
//#greeter
|
||||
public class Greeter extends UntypedActor {
|
||||
|
||||
public static enum Msg {
|
||||
GREET, DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Object msg) {
|
||||
if (msg == Msg.GREET) {
|
||||
System.out.println("Hello World!");
|
||||
getSender().tell(Msg.DONE, getSelf());
|
||||
} else unhandled(msg);
|
||||
}
|
||||
|
||||
}
|
||||
//#greeter
|
||||
31
akka-docs/rst/java/code/docs/actor/japi/HelloWorld.java
Normal file
31
akka-docs/rst/java/code/docs/actor/japi/HelloWorld.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package docs.actor.japi;
|
||||
|
||||
//#hello-world
|
||||
import akka.actor.Props;
|
||||
import akka.actor.UntypedActor;
|
||||
import akka.actor.ActorRef;
|
||||
|
||||
public class HelloWorld extends UntypedActor {
|
||||
|
||||
@Override
|
||||
public void preStart() {
|
||||
// create the greeter actor
|
||||
final ActorRef greeter =
|
||||
getContext().actorOf(Props.create(Greeter.class), "greeter");
|
||||
// tell it to perform the greeting
|
||||
greeter.tell(Greeter.Msg.GREET, getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Object msg) {
|
||||
if (msg == Greeter.Msg.DONE) {
|
||||
// when the greeter is done, stop this actor and with it the application
|
||||
getContext().stop(getSelf());
|
||||
} else unhandled(msg);
|
||||
}
|
||||
}
|
||||
//#hello-world
|
||||
Loading…
Add table
Add a link
Reference in a new issue