diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2012-09-26 04:19:51 -0700 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2012-09-26 04:19:51 -0700 |
commit | 5691373feb3a99d5429dedfaec994d6421b3286f (patch) | |
tree | 925ecc1bb985081717d1f59676c0ba2fc66b36ed /src | |
parent | 339dd82162526bf2448ce00aebe6c3de3307772a (diff) | |
parent | f362bbb40bd3bffb90efb4e67e52b38452573e3e (diff) | |
download | scala-5691373feb3a99d5429dedfaec994d6421b3286f.tar.gz scala-5691373feb3a99d5429dedfaec994d6421b3286f.tar.bz2 scala-5691373feb3a99d5429dedfaec994d6421b3286f.zip |
Merge pull request #1394 from vjovanov/amk/ActorRef
Moving ActorRef API to scala.concurrent.
Diffstat (limited to 'src')
-rw-r--r-- | src/actors-migration/scala/actors/migration/MigrationSystem.scala (renamed from src/actors-migration/scala/actors/MigrationSystem.scala) | 5 | ||||
-rw-r--r-- | src/actors-migration/scala/actors/migration/Pattern.scala (renamed from src/actors-migration/scala/actors/Pattern.scala) | 11 | ||||
-rw-r--r-- | src/actors-migration/scala/actors/migration/Props.scala (renamed from src/actors-migration/scala/actors/Props.scala) | 4 | ||||
-rw-r--r-- | src/actors-migration/scala/actors/migration/StashingActor.scala (renamed from src/actors-migration/scala/actors/StashingActor.scala) | 4 | ||||
-rw-r--r-- | src/actors-migration/scala/actors/migration/Timeout.scala (renamed from src/actors-migration/scala/actors/Timeout.scala) | 2 | ||||
-rw-r--r-- | src/actors/scala/actors/ActorRef.scala | 23 |
6 files changed, 31 insertions, 18 deletions
diff --git a/src/actors-migration/scala/actors/MigrationSystem.scala b/src/actors-migration/scala/actors/migration/MigrationSystem.scala index ffc93d9c6f..3dcb38e634 100644 --- a/src/actors-migration/scala/actors/MigrationSystem.scala +++ b/src/actors-migration/scala/actors/migration/MigrationSystem.scala @@ -1,10 +1,11 @@ -package scala.actors +package scala.actors.migration +import scala.actors._ import scala.collection._ object MigrationSystem { - private[actors] val contextStack = new ThreadLocal[immutable.Stack[Boolean]] { + private[migration] val contextStack = new ThreadLocal[immutable.Stack[Boolean]] { override def initialValue() = immutable.Stack[Boolean]() } diff --git a/src/actors-migration/scala/actors/Pattern.scala b/src/actors-migration/scala/actors/migration/Pattern.scala index a97ee3ba07..25ba191ce7 100644 --- a/src/actors-migration/scala/actors/Pattern.scala +++ b/src/actors-migration/scala/actors/migration/Pattern.scala @@ -1,11 +1,12 @@ -package scala.actors +package scala.actors.migration +import scala.actors._ import scala.concurrent.duration.Duration -import scala.language.implicitConversions +import language.implicitConversions object pattern { - implicit def askSupport(ar: ActorRef): AskableActorRef = + implicit def ask(ar: ActorRef): AskableActorRef = new AskableActorRef(ar) } @@ -16,9 +17,9 @@ 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) + def ?(message: Any)(implicit timeout: Timeout): scala.concurrent.Future[Any] = ar.?(message, timeout.duration) - private[actors] def ?(message: Any, timeout: Duration): Future[Any] = ar.?(message, timeout) + private[actors] def ?(message: Any, timeout: Duration): scala.concurrent.Future[Any] = ar.?(message, timeout) def forward(message: Any) = ar.forward(message) diff --git a/src/actors-migration/scala/actors/Props.scala b/src/actors-migration/scala/actors/migration/Props.scala index 891e23213a..c12384ea55 100644 --- a/src/actors-migration/scala/actors/Props.scala +++ b/src/actors-migration/scala/actors/migration/Props.scala @@ -1,4 +1,6 @@ -package scala.actors +package scala.actors.migration + +import scala.actors._ /** * ActorRef configuration object. It represents the minimal subset of Akka Props class. diff --git a/src/actors-migration/scala/actors/StashingActor.scala b/src/actors-migration/scala/actors/migration/StashingActor.scala index 775d115d0b..9c3917b65e 100644 --- a/src/actors-migration/scala/actors/StashingActor.scala +++ b/src/actors-migration/scala/actors/migration/StashingActor.scala @@ -1,5 +1,7 @@ -package scala.actors +package scala.actors.migration +import scala.actors._ +import scala.actors.Actor._ import scala.collection._ import scala.concurrent.duration.Duration import java.util.concurrent.TimeUnit diff --git a/src/actors-migration/scala/actors/Timeout.scala b/src/actors-migration/scala/actors/migration/Timeout.scala index c3017d8569..32ea5f20fc 100644 --- a/src/actors-migration/scala/actors/Timeout.scala +++ b/src/actors-migration/scala/actors/migration/Timeout.scala @@ -6,7 +6,7 @@ ** |/ ** \* */ -package scala.actors +package scala.actors.migration import scala.concurrent.duration.Duration import java.util.concurrent.TimeUnit diff --git a/src/actors/scala/actors/ActorRef.scala b/src/actors/scala/actors/ActorRef.scala index 7768f04c2b..5e0ca1554a 100644 --- a/src/actors/scala/actors/ActorRef.scala +++ b/src/actors/scala/actors/ActorRef.scala @@ -2,6 +2,8 @@ package scala.actors import java.util.concurrent.TimeoutException import scala.concurrent.duration.Duration +import scala.concurrent.Promise +import scala.concurrent.ExecutionContext.Implicits.global /** * Trait used for migration of Scala actors to Akka. @@ -28,7 +30,7 @@ trait ActorRef { /** * Sends a message asynchronously, returning a future which may eventually hold the reply. */ - private[actors] def ?(message: Any, timeout: Duration): Future[Any] + private[actors] def ?(message: Any, timeout: Duration): scala.concurrent.Future[Any] /** * Forwards the message and passes the original sender actor as the sender. @@ -43,7 +45,7 @@ trait ActorRef { private[actors] class OutputChannelRef(val actor: OutputChannel[Any]) extends ActorRef { - override private[actors] def ?(message: Any, timeout: Duration): Future[Any] = + override private[actors] def ?(message: Any, timeout: Duration): scala.concurrent.Future[Any] = throw new UnsupportedOperationException("Output channel does not support ?") /** @@ -88,14 +90,19 @@ private[actors] final class InternalActorRef(override val actor: InternalActor) /** * Sends a message asynchronously, returning a future which may eventually hold the reply. */ - override private[actors] def ?(message: Any, timeout: Duration): Future[Any] = - Futures.future { - val dur = if (timeout.isFinite()) timeout.toMillis else (java.lang.Long.MAX_VALUE >> 2) - actor !? (dur, message) match { - case Some(x) => x - case None => new AskTimeoutException("? operation timed out.") + override private[actors] def ?(message: Any, timeout: Duration): scala.concurrent.Future[Any] = { + val dur = if (timeout.isFinite()) timeout.toMillis else (java.lang.Long.MAX_VALUE >> 2) + val replyPromise = Promise[Any] + scala.concurrent.future { + scala.concurrent.blocking { + actor !? (dur, message) + } match { + case Some(x) => replyPromise success x + case None => replyPromise failure new AskTimeoutException("? operation timed out.") } } + replyPromise.future + } override def !(message: Any)(implicit sender: ActorRef = null): Unit = if (message == PoisonPill) |