diff options
author | Aleksandar Prokopec <axel22@gmail.com> | 2012-06-28 19:48:31 +0200 |
---|---|---|
committer | Aleksandar Prokopec <axel22@gmail.com> | 2012-06-28 19:48:31 +0200 |
commit | b379ff4f59c139ff7d2b77e7e808f0b74aa9f268 (patch) | |
tree | d531663cc08c71cc2631c119403af3032c71b543 /test/files/jvm/actmig-react-receive.scala | |
parent | 2f0d94c02ab328a3f8da25b5ab8f402a68143af3 (diff) | |
parent | 6f08c06a35a0b70c49e23a296b13ac391a460584 (diff) | |
download | scala-b379ff4f59c139ff7d2b77e7e808f0b74aa9f268.tar.gz scala-b379ff4f59c139ff7d2b77e7e808f0b74aa9f268.tar.bz2 scala-b379ff4f59c139ff7d2b77e7e808f0b74aa9f268.zip |
Merge branch 'master' into issue/5846,4597,4027,4112
Conflicts:
src/library/scala/collection/MapLike.scala
src/library/scala/collection/SortedMapLike.scala
Diffstat (limited to 'test/files/jvm/actmig-react-receive.scala')
-rw-r--r-- | test/files/jvm/actmig-react-receive.scala | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/test/files/jvm/actmig-react-receive.scala b/test/files/jvm/actmig-react-receive.scala new file mode 100644 index 0000000000..8464a2af79 --- /dev/null +++ b/test/files/jvm/actmig-react-receive.scala @@ -0,0 +1,111 @@ +import scala.actors.MigrationSystem._ +import scala.actors.Actor._ +import scala.actors.{ Actor, StashingActor, ActorRef, Props, MigrationSystem, PoisonPill } +import java.util.concurrent.{ TimeUnit, CountDownLatch } +import scala.collection.mutable.ArrayBuffer +import scala.concurrent.util.duration._ +import scala.concurrent.{ Promise, Await } + +object Test { + val finishedRS, finishedRS1, finishedRSC, finishedRSC1 = Promise[Boolean] + def testComposition() = { + // Snippet showing composition of receives + // React Snippet - before + val myActor = actor { + // do before + println("do before") + receive { + case x: Int => + // do task + println("do task") + } + println("do in between") + receive { + case x: String => + // do string now + println("do string") + } + println("do after") + finishedRSC1.success(true) + } + myActor.start() + myActor ! 1 + myActor ! "1" + Await.ready(finishedRSC1.future, 5 seconds) + + // React Snippet - migrated + val myAkkaActor = MigrationSystem.actorOf(Props(() => new StashingActor { + override def preStart() = { + println("do before") + } + + def receive = ({ + case x: Int => + // do task + println("do task") + }: Receive) andThen { v => + context.become { + case x: String => + //do string + println("do string") + context.stop(self) + } + println("do in between") + } + + override def postStop() = { + println("do after") + finishedRSC.success(true) + } + + }, "default-stashing-dispatcher")) + myAkkaActor ! 1 + myAkkaActor ! "1" + Await.ready(finishedRSC.future, 5 seconds) + } + + def main(args: Array[String]) = { + // React Snippet - before + val myActor = actor { + // do before + println("do before") + receive { + case x: Int => + // do task + println("do task") + } + println("do after") + finishedRS1.success(true) + } + myActor.start() + myActor ! 1 + + Await.ready(finishedRS1.future, 5 seconds) + + // React Snippet - migrated + val myAkkaActor = MigrationSystem.actorOf(Props(() => new StashingActor { + override def preStart() = { + println("do before") + } + + def receive = { + case x: Int => + // do task + println("do task") + context.stop(self) + } + + override def postStop() = { + println("do after") + finishedRS.success(true) + } + + }, "default-stashing-dispatcher")) + myAkkaActor ! 1 + + Await.ready(finishedRS.future, 5 seconds) + // Starting composition test + testComposition() + + } +} |