DSL ActorContext extends typed ActorContext #24823 (#24829)

* DSL ActorContext extends typed ActorContext #24823

* remove unnecessary casts for ActorContext
This commit is contained in:
Roland Kuhn 2018-04-11 11:28:19 +02:00 committed by Patrik Nordwall
parent 6baa2b676e
commit eac0467407
7 changed files with 15 additions and 13 deletions

View file

@ -70,6 +70,13 @@ abstract class ActorContextSpec extends ActorTestKit with TypedAkkaSpecWithShutd
"An ActorContext" must {
"be usable from Behavior.interpretMessage" in {
// compilation only
lazy val b: Behavior[String] = Behaviors.receive { (ctx, msg)
Behavior.interpretMessage(b, ctx, msg)
}
}
"canonicalize behaviors" in {
val probe = TestProbe[Event]()

View file

@ -27,10 +27,9 @@ import scala.reflect.ClassTag
def widened[T, U](behavior: Behavior[T], matcher: PartialFunction[U, T]): Behavior[U] = {
behavior match {
case d: DeferredBehavior[T]
case d: DeferredBehavior[t]
DeferredBehavior[U] { ctx
val c = ctx.asInstanceOf[akka.actor.typed.ActorContext[T]]
val b = Behavior.validateAsInitial(Behavior.start(d, c))
val b = Behavior.validateAsInitial(Behavior.start(d, ctx.as[t]))
Widened(b, matcher)
}
case _
@ -129,8 +128,7 @@ import scala.reflect.ClassTag
behavior match {
case d: DeferredBehavior[T]
DeferredBehavior[T] { ctx
val c = ctx.asInstanceOf[akka.actor.typed.ActorContext[T]]
val b = Behavior.validateAsInitial(Behavior.start(d, c))
val b = Behavior.validateAsInitial(Behavior.start(d, ctx))
Intercept(beforeMessage, beforeSignal, afterMessage, afterSignal, b, toStringPrefix)
}
case _

View file

@ -24,7 +24,6 @@ import scala.util.control.NonFatal
@InternalApi private[akka] object Supervisor {
def apply[T, Thr <: Throwable: ClassTag](initialBehavior: Behavior[T], strategy: SupervisorStrategy): Behavior[T] =
Behaviors.setup[T] { ctx
val c = ctx.asInstanceOf[akka.actor.typed.ActorContext[T]]
val supervisor: Supervisor[T, Thr] = strategy match {
case Restart(-1, _, loggingEnabled)
new Restarter(initialBehavior, initialBehavior, loggingEnabled)
@ -42,7 +41,7 @@ import scala.util.control.NonFatal
.asInstanceOf[Supervisor[T, Thr]]
}
supervisor.init(c)
supervisor.init(ctx)
}
}

View file

@ -95,13 +95,12 @@ import akka.util.ConstantFun
override def unstashAll(ctx: javadsl.ActorContext[T], behavior: Behavior[T]): Behavior[T] =
unstashAll(ctx.asScala, behavior)
override def unstash(scaladslCtx: scaladsl.ActorContext[T], behavior: Behavior[T],
override def unstash(ctx: scaladsl.ActorContext[T], behavior: Behavior[T],
numberOfMessages: Int, wrap: T T): Behavior[T] = {
val iter = new Iterator[T] {
override def hasNext: Boolean = StashBufferImpl.this.nonEmpty
override def next(): T = wrap(StashBufferImpl.this.dropHead())
}.take(numberOfMessages)
val ctx = scaladslCtx.asInstanceOf[ActorContext[T]]
Behavior.interpretMessages[T](behavior, ctx, iter)
}

View file

@ -25,8 +25,7 @@ import akka.annotation.InternalApi
behavior match {
case d: DeferredBehavior[T]
DeferredBehavior[T] { ctx
val c = ctx.asInstanceOf[akka.actor.typed.ActorContext[T]]
val started = Behavior.validateAsInitial(Behavior.start(d, c))
val started = Behavior.validateAsInitial(Behavior.start(d, ctx))
chooseOutermostOrWrap(staticMdc, mdcForMessage, started)
}
case b

View file

@ -37,7 +37,7 @@ import scala.concurrent.ExecutionContextExecutor
*/
@DoNotInherit
@ApiMayChange
trait ActorContext[T] {
trait ActorContext[T] extends akka.actor.typed.ActorContext[T] {
// this must be a pure interface, i.e. only abstract methods
/**

View file

@ -36,7 +36,7 @@ import akka.annotation.InternalApi
*/
@DoNotInherit
@ApiMayChange
trait ActorContext[T] { this: akka.actor.typed.javadsl.ActorContext[T]
trait ActorContext[T] extends akka.actor.typed.ActorContext[T] { this: akka.actor.typed.javadsl.ActorContext[T]
/**
* Get the `javadsl` of this `ActorContext`.