Trying to write an alternative Hello World using Scala and Akka -


i have little previous experience deprecated scala actor, started learn akka actor, seem quite different.

i completed tutorial http://doc.akka.io/docs/akka/2.2.0/scala/hello-world.html

next, trying write alternative hello world, using paradigm similar deprecated scala actor. have difficulties (see in-line comments):

class echo extends actor {   override def receive = {     case a: => println(a)     case "end" => context.stop(self)   } }  object main {   def main(args: array[string]): unit = {     val echo = new echo()      // explicit actor.start() ?      // "! not member", akka's official hello world used ! send message     echo ! "hello"     echo ! "end"   } } 

there couple of things wrong code.

1) cannot create actor instantiating class. need obtain actorref using actorof. need start actorsystem manage creation of actors.

def main(args: array[string]): unit = {   val system = actorsystem("mysystem")   val echo = system.actorof(props[echo], "myactor2")   echo ! "hello"   echo ! "end" } 

2) receive method wrong too. pattern of type any match including "end". try this:

   override def receive = {     case "end" => context.stop(self)     case a:string => println(a)   } 

here message printed if not "end" in case not match first case , falls of second one.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -