Permalink
Browse files

Adding the Actor Migration Kit.

  Kit consists of:
    1) The StashingActor which adopts an interface similar to Akka.
    2) Props mockup for creating Akka like code
    3) Pattern mockup
    4) Test cases for every step in the migration.
    5) MigrationSystem which will paired on the Akka side.

  Review of the code : @phaller
  Review of the build: @jsuereth
  • Loading branch information...
Vojin Jovanovic
Vojin Jovanovic committed May 18, 2012
1 parent ef77088 commit e99fb0c93842d517b8a185458f405bace2bbb46b
Showing with 1,996 additions and 16 deletions.
  1. +43 −1 build.xml
  2. +36 −0 src/actors-migration/scala/actors/MigrationSystem.scala
  3. +25 −0 src/actors-migration/scala/actors/Pattern.scala
  4. +14 −0 src/actors-migration/scala/actors/Props.scala
  5. +261 −0 src/actors-migration/scala/actors/StashingActor.scala
  6. +34 −0 src/actors-migration/scala/actors/Timeout.scala
  7. +119 −0 src/actors/scala/actors/ActorRef.scala
  8. +0 −1 src/actors/scala/actors/ActorTask.scala
  9. +44 −9 src/actors/scala/actors/InternalActor.scala
  10. +14 −0 src/actors/scala/actors/MQueue.scala
  11. +9 −1 src/actors/scala/actors/Reactor.scala
  12. +3 −0 src/build/maven/maven-deploy.xml
  13. +66 −0 src/build/maven/scala-actors-migration.pom
  14. +6 −0 src/build/pack.xml
  15. +11 −0 src/partest/scala/tools/partest/PartestTask.scala
  16. +1 −0 src/partest/scala/tools/partest/nest/AntRunner.scala
  17. +9 −0 src/partest/scala/tools/partest/nest/ConsoleFileManager.scala
  18. +2 −2 src/partest/scala/tools/partest/nest/DirectRunner.scala
  19. +1 −0 src/partest/scala/tools/partest/nest/FileManager.scala
  20. +2 −2 src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
  21. +2 −0 src/partest/scala/tools/partest/nest/SBTRunner.scala
  22. +1 −0 src/partest/scala/tools/partest/nest/Worker.scala
  23. +18 −0 test/files/jvm/actmig-PinS.check
  24. +118 −0 test/files/jvm/actmig-PinS.scala
  25. +18 −0 test/files/jvm/actmig-PinS_1.check
  26. +130 −0 test/files/jvm/actmig-PinS_1.scala
  27. +18 −0 test/files/jvm/actmig-PinS_2.check
  28. +150 −0 test/files/jvm/actmig-PinS_2.scala
  29. +19 −0 test/files/jvm/actmig-PinS_3.check
  30. +159 −0 test/files/jvm/actmig-PinS_3.scala
  31. +2 −0 test/files/jvm/actmig-hierarchy.check
  32. +44 −0 test/files/jvm/actmig-hierarchy.scala
  33. +2 −0 test/files/jvm/actmig-hierarchy_1.check
  34. +41 −0 test/files/jvm/actmig-hierarchy_1.scala
  35. +8 −0 test/files/jvm/actmig-instantiation.check
  36. +91 −0 test/files/jvm/actmig-instantiation.scala
  37. +16 −0 test/files/jvm/actmig-loop-react.check
  38. +170 −0 test/files/jvm/actmig-loop-react.scala
  39. +6 −0 test/files/jvm/actmig-public-methods.check
  40. +69 −0 test/files/jvm/actmig-public-methods.scala
  41. +6 −0 test/files/jvm/actmig-public-methods_1.check
  42. +88 −0 test/files/jvm/actmig-public-methods_1.scala
  43. +16 −0 test/files/jvm/actmig-react-receive.check
  44. +104 −0 test/files/jvm/actmig-react-receive.scala
View
@@ -682,6 +682,7 @@ QUICK BUILD (QUICK)
<include name="continuations/**"/>
<include name="swing/**"/>
<include name="actors/**"/>
+ <include name="actors-migration/**"/>
</srcfiles>
</uptodate>
</target>
@@ -879,7 +880,32 @@ QUICK BUILD (QUICK)
<stopwatch name="quick.plugins.timer" action="total"/>
</target>
- <target name="quick.pre-scalacheck" depends="quick.plugins">
+ <target name="quick.pre-actors-migration" depends="quick.plugins">
+ <uptodate property="quick.actors-migration.available" targetfile="${build-quick.dir}/actors-migration.complete">
+ <srcfiles dir="${src.dir}/actors-migration"/>
+ </uptodate>
+ </target>
+
+ <target name="quick.actors-migration" depends="quick.pre-actors-migration" unless="quick.actors-migration.available">
+ <stopwatch name="quick.actors-migration.timer"/>
+ <mkdir dir="${build-quick.dir}/classes/actors-migration"/>
+ <scalacfork
+ destdir="${build-quick.dir}/classes/actors-migration"
+ compilerpathref="quick.classpath"
+ params="${scalac.args.quick}"
+ srcdir="${src.dir}/actors-migration"
+ jvmargs="${scalacfork.jvmargs}">
+ <include name="**/*.scala"/>
+ <compilationpath>
+ <pathelement location="${build-quick.dir}/classes/library"/>
+ <pathelement location="${build-quick.dir}/classes/actors-migration"/>
+ </compilationpath>
+ </scalacfork>
+ <touch file="${build-quick.dir}/actors-migration.complete" verbose="no"/>
+ <stopwatch name="quick.actors-migration.timer" action="total"/>
+ </target>
+
+ <target name="quick.pre-scalacheck" depends="quick.actors-migration">
<uptodate property="quick.scalacheck.available" targetfile="${build-quick.dir}/scalacheck.complete">
<srcfiles dir="${src.dir}/scalacheck"/>
</uptodate>
@@ -1083,6 +1109,9 @@ PACKED QUICK BUILD (PACK)
<include name="scala/actors/**"/>
</fileset>
</jar>
+ <jar destfile="${build-pack.dir}/lib/scala-actors-migration.jar">
+ <fileset dir="${build-quick.dir}/classes/actors-migration"/>
+ </jar>
</target>
<target name="pack.pre-comp" depends="pack.lib">
@@ -1213,6 +1242,7 @@ PACKED QUICK BUILD (PACK)
<pathelement location="${build-pack.dir}/lib/scala-partest.jar"/>
<pathelement location="${build-pack.dir}/lib/scalap.jar"/>
<pathelement location="${build-pack.dir}/lib/scala-actors.jar"/>
+ <pathelement location="${build-pack.dir}/lib/scala-actors-migration.jar"/>
<pathelement location="${ant.jar}"/>
<pathelement location="${jline.jar}"/>
<path refid="lib.extra"/>
@@ -1685,6 +1715,7 @@ DOCUMENTATION
<include name="library/**"/>
<include name="swing/**"/>
<include name="actors/**"/>
+ <include name="actors-migration/**"/>
</source-includes>
</doc-uptodate-check>
</target>
@@ -1705,6 +1736,7 @@ DOCUMENTATION
docRootContent="${src.dir}/library/rootdoc.txt"
implicits="on" diagrams="on">
<src>
+ <files includes="${src.dir}/actors-migration"/>
<files includes="${src.dir}/actors"/>
<files includes="${src.dir}/library/scala"/>
<files includes="${src.dir}/swing"/>
@@ -1901,6 +1933,7 @@ BOOTRAPING TEST AND TEST SUITE
<exclude name="bin/**"/>
<exclude name="*.complete"/>
<exclude name="misc/scala-devel/plugins/*.jar"/>
+ <exclude name="classes/actors-migration/**"/>
</same>
</target>
@@ -2079,6 +2112,9 @@ DISTRIBUTION
<jar destfile="${dist.dir}/src/scala-actors-src.jar">
<fileset dir="${src.dir}/actors"/>
</jar>
+ <jar destfile="${dist.dir}/src/scala-actors-migration-src.jar">
+ <fileset dir="${src.dir}/actors-migration"/>
+ </jar>
<jar destfile="${dist.dir}/src/scalap-src.jar">
<fileset dir="${src.dir}/scalap"/>
</jar>
@@ -2258,6 +2294,12 @@ POSITIONS
<antcall target="test.positions.sub" inheritRefs="true">
<param name="test.srcs" value="${src.dir}/actors"/>
</antcall>
+ <antcall target="test.positions.sub" inheritRefs="true">
+ <param name="test.srcs" value="${src.dir}/actors-migration"/>
+ </antcall>
+ <antcall target="test.positions.sub" inheritRefs="true">
+ <param name="test.srcs" value="${src.dir}/dbc"/>
+ </antcall>
<antcall target="test.positions.sub" inheritRefs="true">
<param name="test.srcs" value="${src.dir}/swing"/>
</antcall>
@@ -0,0 +1,36 @@
+package scala.actors
+
+import scala.collection._
+
+object MigrationSystem {
+
+ private[actors] val contextStack = new ThreadLocal[immutable.Stack[Boolean]] {
+ override def initialValue() = immutable.Stack[Boolean]()
+ }
+
+ private[this] def withCleanContext(block: => ActorRef): ActorRef = {
+ // push clean marker
+ val old = contextStack.get
+ contextStack.set(old.push(true))
+ try {
+ val instance = block
+
+ if (instance eq null)
+ throw new Exception("Actor instance passed to actorOf can't be 'null'")
+
+ instance
+ } finally {
+ val stackAfter = contextStack.get
+ if (stackAfter.nonEmpty)
+ contextStack.set(if (!stackAfter.head) stackAfter.pop.pop else stackAfter.pop)
+ }
+ }
+
+ def actorOf(props: Props): ActorRef = withCleanContext {
+ val creator = props.creator()
+ val r = new InternalActorRef(creator)
+ creator.start()
+ r
+ }
+
+}
@@ -0,0 +1,25 @@
+package scala.actors
+
+import scala.concurrent.util.Duration
+
+object pattern {
+
+ implicit def askSupport(ar: ActorRef): AskableActorRef =
+ new AskableActorRef(ar)
+}
+
+/**
+ * ActorRef with support for ask(?) operation.
+ */
+class AskableActorRef(val ar: ActorRef) extends ActorRef {
+
+ def !(message: Any)(implicit sender: ActorRef = null): Unit = ar.!(message)(sender)
+
+ def ?(message: Any)(timeout: Timeout): Future[Any] = ar.?(message, timeout.duration)
+
+ private[actors] def ?(message: Any, timeout: Duration): Future[Any] = ar.?(message, timeout)
+
+ def forward(message: Any) = ar.forward(message)
+
+ private[actors] def localActor: AbstractActor = ar.localActor
+}
@@ -0,0 +1,14 @@
+package scala.actors
+
+/**
+ * ActorRef configuration object. It represents the minimal subset of Akka Props class.
+ */
+case class Props(creator: () InternalActor, dispatcher: String) {
+
+ /**
+ * Returns a new Props with the specified creator set
+ * Scala API
+ */
+ def withCreator(c: InternalActor) = copy(creator = () c)
+
+}
Oops, something went wrong.

0 comments on commit e99fb0c

Please sign in to comment.