Skip to content

Commit 0f198a6

Browse files
author
Adriaan Moors
committed
Merge pull request scala#575 from vjovanov/actors-migration-kit
Adding the Actor Migration Kit.
2 parents cebf241 + 033463f commit 0f198a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1996
-21
lines changed

build.xml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ QUICK BUILD (QUICK)
682682
<include name="continuations/**"/>
683683
<include name="swing/**"/>
684684
<include name="actors/**"/>
685+
<include name="actors-migration/**"/>
685686
</srcfiles>
686687
</uptodate>
687688
</target>
@@ -879,7 +880,32 @@ QUICK BUILD (QUICK)
879880
<stopwatch name="quick.plugins.timer" action="total"/>
880881
</target>
881882

882-
<target name="quick.pre-scalacheck" depends="quick.plugins">
883+
<target name="quick.pre-actors-migration" depends="quick.plugins">
884+
<uptodate property="quick.actors-migration.available" targetfile="${build-quick.dir}/actors-migration.complete">
885+
<srcfiles dir="${src.dir}/actors-migration"/>
886+
</uptodate>
887+
</target>
888+
889+
<target name="quick.actors-migration" depends="quick.pre-actors-migration" unless="quick.actors-migration.available">
890+
<stopwatch name="quick.actors-migration.timer"/>
891+
<mkdir dir="${build-quick.dir}/classes/actors-migration"/>
892+
<scalacfork
893+
destdir="${build-quick.dir}/classes/actors-migration"
894+
compilerpathref="quick.classpath"
895+
params="${scalac.args.quick}"
896+
srcdir="${src.dir}/actors-migration"
897+
jvmargs="${scalacfork.jvmargs}">
898+
<include name="**/*.scala"/>
899+
<compilationpath>
900+
<pathelement location="${build-quick.dir}/classes/library"/>
901+
<pathelement location="${build-quick.dir}/classes/actors-migration"/>
902+
</compilationpath>
903+
</scalacfork>
904+
<touch file="${build-quick.dir}/actors-migration.complete" verbose="no"/>
905+
<stopwatch name="quick.actors-migration.timer" action="total"/>
906+
</target>
907+
908+
<target name="quick.pre-scalacheck" depends="quick.actors-migration">
883909
<uptodate property="quick.scalacheck.available" targetfile="${build-quick.dir}/scalacheck.complete">
884910
<srcfiles dir="${src.dir}/scalacheck"/>
885911
</uptodate>
@@ -1083,6 +1109,9 @@ PACKED QUICK BUILD (PACK)
10831109
<include name="scala/actors/**"/>
10841110
</fileset>
10851111
</jar>
1112+
<jar destfile="${build-pack.dir}/lib/scala-actors-migration.jar">
1113+
<fileset dir="${build-quick.dir}/classes/actors-migration"/>
1114+
</jar>
10861115
</target>
10871116

10881117
<target name="pack.pre-comp" depends="pack.lib">
@@ -1213,6 +1242,7 @@ PACKED QUICK BUILD (PACK)
12131242
<pathelement location="${build-pack.dir}/lib/scala-partest.jar"/>
12141243
<pathelement location="${build-pack.dir}/lib/scalap.jar"/>
12151244
<pathelement location="${build-pack.dir}/lib/scala-actors.jar"/>
1245+
<pathelement location="${build-pack.dir}/lib/scala-actors-migration.jar"/>
12161246
<pathelement location="${ant.jar}"/>
12171247
<pathelement location="${jline.jar}"/>
12181248
<path refid="lib.extra"/>
@@ -1685,6 +1715,7 @@ DOCUMENTATION
16851715
<include name="library/**"/>
16861716
<include name="swing/**"/>
16871717
<include name="actors/**"/>
1718+
<include name="actors-migration/**"/>
16881719
</source-includes>
16891720
</doc-uptodate-check>
16901721
</target>
@@ -1705,6 +1736,7 @@ DOCUMENTATION
17051736
docRootContent="${src.dir}/library/rootdoc.txt"
17061737
implicits="on" diagrams="on">
17071738
<src>
1739+
<files includes="${src.dir}/actors-migration"/>
17081740
<files includes="${src.dir}/actors"/>
17091741
<files includes="${src.dir}/library/scala"/>
17101742
<files includes="${src.dir}/swing"/>
@@ -1901,6 +1933,7 @@ BOOTRAPING TEST AND TEST SUITE
19011933
<exclude name="bin/**"/>
19021934
<exclude name="*.complete"/>
19031935
<exclude name="misc/scala-devel/plugins/*.jar"/>
1936+
<exclude name="classes/actors-migration/**"/>
19041937
</same>
19051938
</target>
19061939

@@ -2079,6 +2112,9 @@ DISTRIBUTION
20792112
<jar destfile="${dist.dir}/src/scala-actors-src.jar">
20802113
<fileset dir="${src.dir}/actors"/>
20812114
</jar>
2115+
<jar destfile="${dist.dir}/src/scala-actors-migration-src.jar">
2116+
<fileset dir="${src.dir}/actors-migration"/>
2117+
</jar>
20822118
<jar destfile="${dist.dir}/src/scalap-src.jar">
20832119
<fileset dir="${src.dir}/scalap"/>
20842120
</jar>
@@ -2258,6 +2294,12 @@ POSITIONS
22582294
<antcall target="test.positions.sub" inheritRefs="true">
22592295
<param name="test.srcs" value="${src.dir}/actors"/>
22602296
</antcall>
2297+
<antcall target="test.positions.sub" inheritRefs="true">
2298+
<param name="test.srcs" value="${src.dir}/actors-migration"/>
2299+
</antcall>
2300+
<antcall target="test.positions.sub" inheritRefs="true">
2301+
<param name="test.srcs" value="${src.dir}/dbc"/>
2302+
</antcall>
22612303
<antcall target="test.positions.sub" inheritRefs="true">
22622304
<param name="test.srcs" value="${src.dir}/swing"/>
22632305
</antcall>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package scala.actors
2+
3+
import scala.collection._
4+
5+
object MigrationSystem {
6+
7+
private[actors] val contextStack = new ThreadLocal[immutable.Stack[Boolean]] {
8+
override def initialValue() = immutable.Stack[Boolean]()
9+
}
10+
11+
private[this] def withCleanContext(block: => ActorRef): ActorRef = {
12+
// push clean marker
13+
val old = contextStack.get
14+
contextStack.set(old.push(true))
15+
try {
16+
val instance = block
17+
18+
if (instance eq null)
19+
throw new Exception("Actor instance passed to actorOf can't be 'null'")
20+
21+
instance
22+
} finally {
23+
val stackAfter = contextStack.get
24+
if (stackAfter.nonEmpty)
25+
contextStack.set(if (!stackAfter.head) stackAfter.pop.pop else stackAfter.pop)
26+
}
27+
}
28+
29+
def actorOf(props: Props): ActorRef = withCleanContext {
30+
val creator = props.creator()
31+
val r = new InternalActorRef(creator)
32+
creator.start()
33+
r
34+
}
35+
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package scala.actors
2+
3+
import scala.concurrent.util.Duration
4+
5+
object pattern {
6+
7+
implicit def askSupport(ar: ActorRef): AskableActorRef =
8+
new AskableActorRef(ar)
9+
}
10+
11+
/**
12+
* ActorRef with support for ask(?) operation.
13+
*/
14+
class AskableActorRef(val ar: ActorRef) extends ActorRef {
15+
16+
def !(message: Any)(implicit sender: ActorRef = null): Unit = ar.!(message)(sender)
17+
18+
def ?(message: Any)(timeout: Timeout): Future[Any] = ar.?(message, timeout.duration)
19+
20+
private[actors] def ?(message: Any, timeout: Duration): Future[Any] = ar.?(message, timeout)
21+
22+
def forward(message: Any) = ar.forward(message)
23+
24+
private[actors] def localActor: AbstractActor = ar.localActor
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package scala.actors
2+
3+
/**
4+
* ActorRef configuration object. It represents the minimal subset of Akka Props class.
5+
*/
6+
case class Props(creator: () InternalActor, dispatcher: String) {
7+
8+
/**
9+
* Returns a new Props with the specified creator set
10+
*/
11+
def withCreator(c: InternalActor) = copy(creator = () c)
12+
13+
}

0 commit comments

Comments
 (0)