diff options
Diffstat (limited to 'docs/examples/actors')
-rw-r--r-- | docs/examples/actors/counter.scala | 12 | ||||
-rw-r--r-- | docs/examples/actors/customer.scala | 34 |
2 files changed, 16 insertions, 30 deletions
diff --git a/docs/examples/actors/counter.scala b/docs/examples/actors/counter.scala index 1224853432..e768a8f9ef 100644 --- a/docs/examples/actors/counter.scala +++ b/docs/examples/actors/counter.scala @@ -1,17 +1,15 @@ /** * @author Philipp Haller <philipp.haller@epfl.ch> - * */ package examples.actors -import scala.actors.multi.Pid +import scala.actors.Process import scala.actors.distributed.{RemoteActor,TCP,TcpNode,TcpService} -abstract class CounterMessage -case class Incr() extends CounterMessage -case class Value(p: Pid) extends CounterMessage -case class Result(v: int) extends CounterMessage +case class Incr() +case class Value(p: Process) +case class Result(v: int) class Counter extends RemoteActor { override def run(): unit = @@ -39,7 +37,7 @@ class CounterUser extends RemoteActor { spawn(TcpNode(host, 9090), classOf[Counter].getName()) receive { - case p: Pid => + case p: Process => // communicate with counter Console.println("" + node + ": Sending Incr() to remote Counter (" + p + ")...") p ! Incr() diff --git a/docs/examples/actors/customer.scala b/docs/examples/actors/customer.scala index 80c2664130..58ba55b014 100644 --- a/docs/examples/actors/customer.scala +++ b/docs/examples/actors/customer.scala @@ -7,31 +7,21 @@ package examples.actors -import scala.actors._ -import scala.actors.single._ +import scala.actors.single.Actor -abstract class FactorialMessage -case class Factorial(n: int, resTo: Actor) extends FactorialMessage -case class Value(n: int) extends FactorialMessage +case class Factorial(n: int, resTo: Actor) class FactorialProcess extends Actor { override def run: unit = { receive { case Factorial(n, resTo) => if (n == 0) { - Debug.info("Sending Value(1) to " + resTo) - resTo send Value(1) + resTo ! 1 } else { - // spawn process that multiplies - /*val m = spawnReceive({ - case Value(value) => resTo send Value(n * value) - });*/ - val m = new MultiplyActor(n, resTo) - m.start - Debug.info("Sending Factorial(" + (n-1) + ", " + m + ") to " + this) - this send Factorial(n-1, m) + m.start() + this ! Factorial(n-1, m) } run } @@ -41,28 +31,26 @@ class FactorialProcess extends Actor { class MultiplyActor(factor: int, resTo: Actor) extends Actor { override def run: unit = receive { - case Value(value) => - Debug.info("Sending Value(" + factor * value + ") to " + resTo) - resTo send Value(factor * value) - Debug.info("Done sending.") + case value: int => + resTo ! factor * value } } object CustomerPassing { def main(args: Array[String]): unit = { val fac = new FactorialProcess - fac.start + fac.start() val c = new Actor { override def run: unit = { - fac send Factorial(3, this) + fac ! Factorial(3, this) receive { - case Value(value) => + case value: int => System.out.println("Result: " + value) } } } - c.start + c.start() } } |