public
Created

  • Download Gist
akka.kt
Kotlin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
package sample.hello
 
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor.UntypedActor
import akka.actor.UntypedActorContext
import akka.actor.ActorPath
import scala.concurrent.duration.Duration
import java.util.HashMap
import akka.actor.ActorSystem
import akka.actor.ActorRef
 
object start {}
 
fun main(args: Array<String>) {
val system = ActorSystem.create();
val helloActor = system.actorOf(Props(javaClass<HelloActor>()));
helloActor.tell(start)
}
 
class HelloActor: UntypedActor() {
 
var worldActor: ActorRef = getContext().actorOf(Props(javaClass<WorldActor>()))
 
public override fun onReceive(msg: Any?) {
when (msg) {
start -> worldActor.tell("Hello", self())
is String-> {
println("Received message: $msg")
getContext().system().shutdown()
}
else -> unhandled(msg)
}
}
 
}
 
class WorldActor: UntypedActor() {
 
public override fun onReceive(msg: Any?) {
when (msg) {
is String -> getSender().tell(msg.toUpperCase() + " world");
else -> unhandled(msg);
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.