!typ Rename ActorContext#upcast to ActorContext#unsafeUpcast. (#25973)

This commit is contained in:
kerr 2018-11-30 15:52:04 +08:00 committed by Christopher Batey
parent 5c653e1404
commit f7a95b5228
7 changed files with 11 additions and 10 deletions

View file

@ -304,7 +304,7 @@ class InterceptSpec extends ScalaTestWithActorTestKit(
ref ! Msg("hello", probe.ref) ref ! Msg("hello", probe.ref)
probe.expectMessage("hello-1") probe.expectMessage("hello-1")
ref.upcast[Any] ! MyPoisonPill ref.unsafeUpcast[Any] ! MyPoisonPill
probe.expectTerminated(ref, probe.remainingOrDefault) probe.expectTerminated(ref, probe.remainingOrDefault)
} }

View file

@ -49,7 +49,7 @@ object SupervisionSpec {
case IncrementState case IncrementState
targetBehavior(monitor, state.copy(n = state.n + 1)) targetBehavior(monitor, state.copy(n = state.n + 1))
case GetState case GetState
val reply = state.copy(children = context.children.map(c c.path.name c.upcast[Command]).toMap) val reply = state.copy(children = context.children.map(c c.path.name c.unsafeUpcast[Command]).toMap)
monitor ! reply monitor ! reply
Behaviors.same Behaviors.same
case CreateChild(childBehv, childName) case CreateChild(childBehv, childName)

View file

@ -37,9 +37,10 @@ trait ActorRef[-T] extends RecipientRef[T] with java.lang.Comparable[ActorRef[_]
/** /**
* Unsafe utility method for widening the type accepted by this ActorRef; * Unsafe utility method for widening the type accepted by this ActorRef;
* provided to avoid having to use `asInstanceOf` on the full reference type, * provided to avoid having to use `asInstanceOf` on the full reference type,
* which would unfortunately also work on non-ActorRefs. * which would unfortunately also work on non-ActorRefs. Use it with caution,it may cause a [[ClassCastException]] when you send a message
* to the widened [[ActorRef[U]]].
*/ */
def upcast[U >: T @uncheckedVariance]: ActorRef[U] def unsafeUpcast[U >: T @uncheckedVariance]: ActorRef[U]
/** /**
* The hierarchical path name of the referenced Actor. The lifecycle of the * The hierarchical path name of the referenced Actor. The lifecycle of the

View file

@ -46,7 +46,7 @@ import akka.util.JavaDurationConverters._
override def getChild(name: String): Optional[ActorRef[Void]] = override def getChild(name: String): Optional[ActorRef[Void]] =
child(name) match { child(name) match {
case Some(c) Optional.of(c.upcast[Void]) case Some(c) Optional.of(c.unsafeUpcast[Void])
case None Optional.empty() case None Optional.empty()
} }
@ -54,7 +54,7 @@ import akka.util.JavaDurationConverters._
val c = children val c = children
val a = new ArrayList[ActorRef[Void]](c.size) val a = new ArrayList[ActorRef[Void]](c.size)
val i = c.iterator val i = c.iterator
while (i.hasNext) a.add(i.next().upcast[Void]) while (i.hasNext) a.add(i.next().unsafeUpcast[Void])
a a
} }

View file

@ -19,7 +19,7 @@ private[akka] trait ActorRefImpl[-T] extends ActorRef[T] { this: InternalRecipie
final override def narrow[U <: T]: ActorRef[U] = this.asInstanceOf[ActorRef[U]] final override def narrow[U <: T]: ActorRef[U] = this.asInstanceOf[ActorRef[U]]
final override def upcast[U >: T @uncheckedVariance]: ActorRef[U] = this.asInstanceOf[ActorRef[U]] final override def unsafeUpcast[U >: T @uncheckedVariance]: ActorRef[U] = this.asInstanceOf[ActorRef[U]]
/** /**
* Comparison takes path and the unique id of the actor cell into account. * Comparison takes path and the unique id of the actor cell into account.

View file

@ -76,11 +76,11 @@ import scala.concurrent.duration.FiniteDuration
val task = val task =
if (repeat) if (repeat)
ctx.system.scheduler.schedule(timeout, timeout) { ctx.system.scheduler.schedule(timeout, timeout) {
ctx.self.upcast ! timerMsg ctx.self.unsafeUpcast ! timerMsg
}(ExecutionContexts.sameThreadExecutionContext) }(ExecutionContexts.sameThreadExecutionContext)
else else
ctx.system.scheduler.scheduleOnce(timeout) { ctx.system.scheduler.scheduleOnce(timeout) {
ctx.self.upcast ! timerMsg ctx.self.unsafeUpcast ! timerMsg
}(ExecutionContexts.sameThreadExecutionContext) }(ExecutionContexts.sameThreadExecutionContext)
val nextTimer = Timer(key, msg, repeat, nextGen, task) val nextTimer = Timer(key, msg, repeat, nextGen, task)

View file

@ -68,7 +68,7 @@ object ClusterShardingPersistenceSpec {
entityActorRefs.get(entityId) match { entityActorRefs.get(entityId) match {
case null case null
case promise promise.trySuccess(ctx.self.upcast) case promise promise.trySuccess(ctx.self.unsafeUpcast)
} }
PersistentEntity[Command, String, String]( PersistentEntity[Command, String, String](