summaryrefslogtreecommitdiff
path: root/src/actors-migration
diff options
context:
space:
mode:
authorphaller <hallerp@gmail.com>2012-09-29 18:15:37 +0200
committerphaller <hallerp@gmail.com>2012-09-29 18:19:52 +0200
commitb2211a76a6e537cf2e404d424cb643f171818e92 (patch)
tree0fde859c45025594b7205cffe1c29fc37bf9b483 /src/actors-migration
parentbe49f36154efa78c3dcbeba394aa6ec2b5e764ec (diff)
downloadscala-b2211a76a6e537cf2e404d424cb643f171818e92.tar.gz
scala-b2211a76a6e537cf2e404d424cb643f171818e92.tar.bz2
scala-b2211a76a6e537cf2e404d424cb643f171818e92.zip
SI-6442 - Add ActorDSL object for actor migration kit
Removes MigrationSystem, since ActorDSL replaces it.
Diffstat (limited to 'src/actors-migration')
-rw-r--r--src/actors-migration/scala/actors/migration/ActorDSL.scala56
-rw-r--r--src/actors-migration/scala/actors/migration/MigrationSystem.scala37
-rw-r--r--src/actors-migration/scala/actors/migration/StashingActor.scala10
3 files changed, 61 insertions, 42 deletions
diff --git a/src/actors-migration/scala/actors/migration/ActorDSL.scala b/src/actors-migration/scala/actors/migration/ActorDSL.scala
new file mode 100644
index 0000000000..b8cb8ec998
--- /dev/null
+++ b/src/actors-migration/scala/actors/migration/ActorDSL.scala
@@ -0,0 +1,56 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2005-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.actors
+package migration
+
+import scala.actors.{ Actor, ActorRef, InternalActorRef }
+import scala.collection.immutable
+import scala.reflect.ClassTag
+
+object ActorDSL {
+
+ private[migration] 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("ActorRef can't be 'null'")
+
+ instance
+ } finally {
+ val stackAfter = contextStack.get
+ if (stackAfter.nonEmpty)
+ contextStack.set(if (!stackAfter.head) stackAfter.pop.pop else stackAfter.pop)
+ }
+ }
+
+ /**
+ * Create an actor from the given thunk which must produce an [[scala.actors.Actor]].
+ *
+ * @param ctor is a by-name argument which captures an [[scala.actors.Actor]]
+ * factory; <b>do not make the generated object accessible to code
+ * outside and do not return the same object upon subsequent invocations.</b>
+ */
+ def actor[T <: InternalActor: ClassTag](ctor: ⇒ T): ActorRef = {
+ withCleanContext {
+ val newActor = ctor
+ val newRef = new InternalActorRef(newActor)
+ newActor.start()
+ newRef
+ }
+ }
+
+}
diff --git a/src/actors-migration/scala/actors/migration/MigrationSystem.scala b/src/actors-migration/scala/actors/migration/MigrationSystem.scala
deleted file mode 100644
index 3dcb38e634..0000000000
--- a/src/actors-migration/scala/actors/migration/MigrationSystem.scala
+++ /dev/null
@@ -1,37 +0,0 @@
-package scala.actors.migration
-
-import scala.actors._
-import scala.collection._
-
-object MigrationSystem {
-
- private[migration] 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
- }
-
-} \ No newline at end of file
diff --git a/src/actors-migration/scala/actors/migration/StashingActor.scala b/src/actors-migration/scala/actors/migration/StashingActor.scala
index d0a1432e72..c628035891 100644
--- a/src/actors-migration/scala/actors/migration/StashingActor.scala
+++ b/src/actors-migration/scala/actors/migration/StashingActor.scala
@@ -110,18 +110,18 @@ trait StashingActor extends InternalActor {
private[actors] var behaviorStack = immutable.Stack[PartialFunction[Any, Unit]]()
/*
- * Checks that StashingActor can be created only by MigrationSystem.actorOf method.
+ * Checks that StashingActor instances can only be created using the ActorDSL.
*/
private[this] def creationCheck(): Unit = {
// creation check (see ActorRef)
- val context = MigrationSystem.contextStack.get
+ val context = ActorDSL.contextStack.get
if (context.isEmpty)
- throw new RuntimeException("In order to create StashingActor one must use actorOf.")
+ throw new RuntimeException("In order to create a StashingActor one must use the ActorDSL object")
else {
if (!context.head)
- throw new RuntimeException("Only one actor can be created per actorOf call.")
+ throw new RuntimeException("Cannot create more than one actor")
else
- MigrationSystem.contextStack.set(context.push(false))
+ ActorDSL.contextStack.set(context.push(false))
}
}