Skip to content

Commit

Permalink
fix dotty compile errors ambiguous reference
Browse files Browse the repository at this point in the history
For example:

Reference to context is ambiguous
it is both defined in object TypedActor
and inherited subsequently in class TypedActor
  • Loading branch information
giabao committed Apr 9, 2020
1 parent fbc29f6 commit ebb8527
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object TestKitSettings {

private object Ext extends ExtensionId[Ext] {
override def createExtension(system: ActorSystem[_]): Ext = new Ext(system)
def get(system: ActorSystem[_]): Ext = apply(system)
def get(system: ActorSystem[_]): Ext = this.apply(system)
}

private class Ext(system: ActorSystem[_]) extends Extension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ object ActorSystemSpec {
extends MessageDispatcherConfigurator(_config, _prerequisites) {
private val instance = new Dispatcher(
this,
config.getString("id"),
config.getInt("throughput"),
config.getNanosDuration("throughput-deadline-time"),
this.config.getString("id"),
this.config.getInt("throughput"),
this.config.getNanosDuration("throughput-deadline-time"),
configureExecutor(),
config.getMillisDuration("shutdown-timeout")) {
this.config.getMillisDuration("shutdown-timeout")) {
val doneIt = new Switch
override protected[akka] def registerForExecution(
mbox: Mailbox,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ object SupervisorHierarchySpec {
case object Abort
case object PingOfDeath
case object PongOfDeath
final case class Event(msg: Any, identity: Long) { val time: Long = System.nanoTime }
final case class ErrorLog(msg: String, log: Vector[Event])
final case class MyEvent(msg: Any, identity: Long) { val time: Long = System.nanoTime }
final case class ErrorLog(msg: String, log: Vector[MyEvent])
final case class Failure(
directive: Directive,
stop: Boolean,
Expand Down Expand Up @@ -102,16 +102,17 @@ object SupervisorHierarchySpec {

override def suspend(cell: ActorCell): Unit = {
cell.actor match {
case h: Hierarchy => h.log :+= Event("suspended " + cell.mailbox.suspendCount, identityHashCode(cell.actor))
case _ =>
case h: Hierarchy =>
h.log :+= MyEvent("suspended " + cell.mailbox.suspendCount, identityHashCode(cell.actor))
case _ =>
}
super.suspend(cell)
}

override def resume(cell: ActorCell): Unit = {
super.resume(cell)
cell.actor match {
case h: Hierarchy => h.log :+= Event("resumed " + cell.mailbox.suspendCount, identityHashCode(cell.actor))
case h: Hierarchy => h.log :+= MyEvent("resumed " + cell.mailbox.suspendCount, identityHashCode(cell.actor))
case _ =>
}
}
Expand All @@ -126,17 +127,17 @@ object SupervisorHierarchySpec {
* upon Restart or would have to be managed by the highest supervisor (which
* is undesirable).
*/
final case class HierarchyState(log: Vector[Event], kids: Map[ActorPath, Int], failConstr: Failure)
final case class HierarchyState(log: Vector[MyEvent], kids: Map[ActorPath, Int], failConstr: Failure)
val stateCache = new ConcurrentHashMap[ActorPath, HierarchyState]()
@volatile var ignoreFailConstr = false

class Hierarchy(size: Int, breadth: Int, listener: ActorRef, myLevel: Int, random: Random) extends Actor {

var log = Vector.empty[Event]
var log = Vector.empty[MyEvent]

stateCache.get(self.path) match {
case hs @ HierarchyState(l: Vector[Event], _, f: Failure) if f.failConstr > 0 && !ignoreFailConstr =>
val log = l :+ Event("Failed in constructor", identityHashCode(this))
case hs @ HierarchyState(l: Vector[MyEvent], _, f: Failure) if f.failConstr > 0 && !ignoreFailConstr =>
val log = l :+ MyEvent("Failed in constructor", identityHashCode(this))
stateCache.put(self.path, hs.copy(log = log, failConstr = f.copy(failConstr = f.failConstr - 1)))
throw f
case _ =>
Expand All @@ -147,7 +148,7 @@ object SupervisorHierarchySpec {

def abort(msg: String): Unit = {
listener ! ErrorLog(msg, log)
log = Vector(Event("log sent", identityHashCode(this)))
log = Vector(MyEvent("log sent", identityHashCode(this)))
context.parent ! Abort
context.stop(self)
}
Expand All @@ -161,7 +162,7 @@ object SupervisorHierarchySpec {
def suspendCount = context.asInstanceOf[ActorCell].mailbox.suspendCount

override def preStart(): Unit = {
log :+= Event("started", identityHashCode(this))
log :+= MyEvent("started", identityHashCode(this))
listener ! Ready(self)
val s = size - 1 // subtract myself
val kidInfo: Map[ActorPath, Int] =
Expand All @@ -187,12 +188,12 @@ object SupervisorHierarchySpec {
// do not scrap children
if (preRestartCalled) abort("preRestart called twice")
else {
log :+= Event("preRestart " + cause, identityHashCode(this))
log :+= MyEvent("preRestart " + cause, identityHashCode(this))
preRestartCalled = true
cause match {
case f: Failure =>
context.children.take(f.stopKids).foreach { child =>
log :+= Event("killing " + child, identityHashCode(this))
log :+= MyEvent("killing " + child, identityHashCode(this))
context.unwatch(child)
context.stop(child)
}
Expand All @@ -213,22 +214,22 @@ object SupervisorHierarchySpec {
}
override val supervisorStrategy = OneForOneStrategy()(unwrap.andThen {
case (_: Failure, _) if pongsToGo > 0 =>
log :+= Event("pongOfDeath resuming " + sender(), identityHashCode(this))
log :+= MyEvent("pongOfDeath resuming " + sender(), identityHashCode(this))
Resume
case (f: Failure, orig) =>
if (f.depth > 0) {
setFlags(f.directive)
log :+= Event("escalating " + f + " from " + sender(), identityHashCode(this))
log :+= MyEvent("escalating " + f + " from " + sender(), identityHashCode(this))
throw f.copy(depth = f.depth - 1)
}
val prefix = orig match {
case _: Failure => "applying "
case _ => "re-applying "
}
log :+= Event(prefix + f + " to " + sender(), identityHashCode(this))
log :+= MyEvent(prefix + f + " to " + sender(), identityHashCode(this))
if (myLevel > 3 && f.failPost == 0 && f.stop) Stop else f.directive
case (_, x) =>
log :+= Event("unhandled exception from " + sender() + Logging.stackTraceFor(x), identityHashCode(this))
log :+= MyEvent("unhandled exception from " + sender() + Logging.stackTraceFor(x), identityHashCode(this))
sender() ! Dump(0)
context.system.scheduler.scheduleOnce(1 second, self, Dump(0))(context.dispatcher)
Resume
Expand All @@ -237,7 +238,7 @@ object SupervisorHierarchySpec {
override def postRestart(cause: Throwable): Unit = {
val state = stateCache.get(self.path)
log = state.log
log :+= Event("restarted " + suspendCount + " " + cause, identityHashCode(this))
log :+= MyEvent("restarted " + suspendCount + " " + cause, identityHashCode(this))
state.kids.foreach {
case (childPath, kidSize) =>
val name = childPath.name
Expand Down Expand Up @@ -270,7 +271,7 @@ object SupervisorHierarchySpec {

def check(msg: Any): Boolean = {
suspended = false
log :+= Event(msg, identityHashCode(Hierarchy.this))
log :+= MyEvent(msg, identityHashCode(Hierarchy.this))
if (failed) {
abort("processing message while failed")
failed = false
Expand Down Expand Up @@ -314,13 +315,13 @@ object SupervisorHierarchySpec {
} else {
// WARNING: The Terminated that is logged by this is logged by check() above, too. It is not
// an indication of duplicate Terminate messages
log :+= Event(s"${sender()} terminated while pongOfDeath", identityHashCode(Hierarchy.this))
log :+= MyEvent(s"${sender()} terminated while pongOfDeath", identityHashCode(Hierarchy.this))
}
case Abort => abort("terminating")
case PingOfDeath =>
if (size > 1) {
pongsToGo = context.children.size
log :+= Event("sending " + pongsToGo + " pingOfDeath", identityHashCode(Hierarchy.this))
log :+= MyEvent("sending " + pongsToGo + " pingOfDeath", identityHashCode(Hierarchy.this))
context.children.foreach(_ ! PingOfDeath)
} else {
context.stop(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class MutableScalaBehaviorSpec extends Messages with Become with Stoppable {
override def onMessage(message: Command): Behavior[Command] = {
message match {
case GetSelf =>
monitor ! Self(context.self)
monitor ! Self(this.context.self)
this
case Miss =>
monitor ! Missed
Expand Down
18 changes: 10 additions & 8 deletions akka-actor/src/main/scala/akka/actor/TypedActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,10 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
interfaces: immutable.Seq[Class[_]])
extends Actor {
// if we were remote deployed we need to create a local proxy
if (!context.parent.asInstanceOf[InternalActorRef].isLocal)
TypedActor.get(context.system).createActorRefProxy(TypedProps(interfaces, createInstance), proxyVar, context.self)
if (!this.context.parent.asInstanceOf[InternalActorRef].isLocal)
TypedActor
.get(this.context.system)
.createActorRefProxy(TypedProps(interfaces, createInstance), proxyVar, this.context.self)

private val me = withContext[T](createInstance)

Expand All @@ -293,10 +295,10 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
}
}
} finally {
TypedActor(context.system).invocationHandlerFor(proxyVar.get) match {
TypedActor(this.context.system).invocationHandlerFor(proxyVar.get) match {
case null =>
case some =>
some.actorVar.set(context.system.deadLetters) //Point it to the DLQ
some.actorVar.set(this.context.system.deadLetters) //Point it to the DLQ
proxyVar.set(null.asInstanceOf[R])
}
}
Expand All @@ -305,8 +307,8 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
me match {
case l: PreRestart => l.preRestart(reason, message)
case _ =>
context.children
.foreach(context.stop) //Can't be super.preRestart(reason, message) since that would invoke postStop which would set the actorVar to DL and proxyVar to null
this.context.children
.foreach(this.context.stop) //Can't be super.preRestart(reason, message) since that would invoke postStop which would set the actorVar to DL and proxyVar to null
}
}

Expand All @@ -319,7 +321,7 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi

protected def withContext[U](unitOfWork: => U): U = {
TypedActor.selfReference.set(proxyVar.get)
TypedActor.currentContext.set(context)
TypedActor.currentContext.set(this.context)
try unitOfWork
finally {
TypedActor.selfReference.set(null)
Expand All @@ -336,7 +338,7 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
val s = sender()
m(me) match {
case f: Future[_] if m.returnsFuture =>
implicit val dispatcher = context.dispatcher
implicit val dispatcher = this.context.dispatcher
f.onComplete {
case Success(null) => s ! NullResponse
case Success(result) => s ! result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AkkaSpecSpec extends AnyWordSpec with Matchers {
"akka.stdout-loglevel" -> "DEBUG")
val system = ActorSystem("AkkaSpec1", ConfigFactory.parseMap(conf.asJava).withFallback(AkkaSpec.testConf))
var refs = Seq.empty[ActorRef]
val spec = new AkkaSpec(system) { refs = Seq(testActor, system.actorOf(Props.empty, "name")) }
val spec = new AkkaSpec(system) { refs = Seq(testActor, this.system.actorOf(Props.empty, "name")) }
refs.foreach(_.isTerminated should not be true)
TestKit.shutdownActorSystem(system)
spec.awaitCond(refs.forall(_.isTerminated), 2 seconds)
Expand Down

0 comments on commit ebb8527

Please sign in to comment.