::::::::::::::
test1.sh
::::::::::::::
#!/bin/sh
# $Id: test1.sh,v 1.1 2009/10/19 16:45:09 kishi Exp kishi $
scala -classpath ActorTest.jar com.ykishi.scala.Main
::::::::::::::
src/Main.scala
::::::::::::::
import scala.actors.Actor._
package com.ykishi.scala
{
object Main extends Application {
case class MetaInfo(key: Int, value: String)
override def main(args: Array[String]){
val a = actor {
loop {
receive {
case s: String => println("received: " + s)
case m: MetaInfo => println("received: " + m.key + "," + m.value)
case -1 => {
reply("complete")
exit()
}
}
}
}
//--------------------------------------------
// Send messages to actor repeatedly
//--------------------------------------------
a ! "HELLO!"
a ! MetaInfo(1123, "KISHI Yasuhiro")
val retval = a !? -1
println("Actor's reply: " + retval)
}
}
}
■ 実行結果
$ ./test1.sh
received: HELLO!
received: 1123,KISHI Yasuhiro
Actor's reply: complete
Tidak ada komentar:
Posting Komentar