Skip to content

Commit

Permalink
Fix for Actor.self in Scala actors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vojin Jovanovic committed Oct 26, 2012
1 parent 2c55424 commit 626bd15
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/actors/scala/actors/remote/NetKernel.scala
Expand Up @@ -60,7 +60,7 @@ private[remote] class NetKernel(service: Service) {
send(node, name, msg, 'nosession)

def send(node: Node, name: Symbol, msg: AnyRef, session: Symbol) {
val senderLoc = Locator(service.node, getOrCreateName(Actor.self))
val senderLoc = Locator(service.node, getOrCreateName(Actor.self(Scheduler)))
val receiverLoc = Locator(node, name)
namedSend(senderLoc, receiverLoc, msg, session)
}
Expand Down
10 changes: 5 additions & 5 deletions src/actors/scala/actors/remote/RemoteActor.scala
Expand Up @@ -40,7 +40,7 @@ package remote
*/
object RemoteActor {

private val kernels = new scala.collection.mutable.HashMap[Actor, NetKernel]
private val kernels = new scala.collection.mutable.HashMap[InternalActor, NetKernel]

/* If set to <code>null</code> (default), the default class loader
* of <code>java.io.ObjectInputStream</code> is used for deserializing
Expand All @@ -62,7 +62,7 @@ object RemoteActor {
private def createNetKernelOnPort(port: Int): NetKernel = {
val serv = TcpService(port, cl)
val kern = serv.kernel
val s = Actor.self
val s = Actor.self(Scheduler)
kernels += Pair(s, kern)

s.onTerminate {
Expand All @@ -86,18 +86,18 @@ object RemoteActor {
* node.
*/
def register(name: Symbol, a: Actor): Unit = synchronized {
val kernel = kernels.get(Actor.self) match {
val kernel = kernels.get(Actor.self(Scheduler)) match {
case None =>
val serv = TcpService(TcpService.generatePort, cl)
kernels += Pair(Actor.self, serv.kernel)
kernels += Pair(Actor.self(Scheduler), serv.kernel)
serv.kernel
case Some(k) =>
k
}
kernel.register(name, a)
}

private def selfKernel = kernels.get(Actor.self) match {
private def selfKernel = kernels.get(Actor.self(Scheduler)) match {
case None =>
// establish remotely accessible
// return path (sender)
Expand Down
1 change: 1 addition & 0 deletions test/files/jvm/actmig-remote-actor-self.check
@@ -0,0 +1 @@
registered
36 changes: 36 additions & 0 deletions test/files/jvm/actmig-remote-actor-self.scala
@@ -0,0 +1,36 @@
/**
* NOTE: Code snippets from this test are included in the Actor Migration Guide. In case you change
* code in these tests prior to the 2.10.0 release please send the notification to @vjovanov.
*/
import scala.actors.Actor._
import scala.actors._
import scala.actors.migration._
import scala.actors.remote._
import scala.actors.remote.RemoteActor._

import java.util.concurrent.{ TimeUnit, CountDownLatch }
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.duration._
import scala.concurrent.{ Promise, Await }

object Test {
val finished = Promise[Boolean]

def main(args: Array[String]): Unit = {
// Can fail with class cast exception in alive
val myAkkaActor = ActorDSL.actor(new StashingActor {
override def preStart() = {
alive(2013)
println("registered")
finished success true
context.stop(self)
}

def receive = {
case x: Int =>
}
})

}

}

0 comments on commit 626bd15

Please sign in to comment.