Replace WrappingBehavior with directly access of InterceptorImpl
This commit is contained in:
parent
02dc90ff6d
commit
dcb2eeabed
4 changed files with 10 additions and 47 deletions
|
|
@ -6,8 +6,7 @@ package akka.actor.typed
|
|||
|
||||
import scala.annotation.tailrec
|
||||
import akka.actor.InvalidMessageException
|
||||
import akka.actor.typed.internal.BehaviorImpl
|
||||
import akka.actor.typed.internal.WrappingBehavior
|
||||
import akka.actor.typed.internal.{ BehaviorImpl, InterceptorImpl }
|
||||
import akka.actor.typed.internal.BehaviorImpl.OrElseBehavior
|
||||
import akka.util.{ LineNumbers, OptionVal }
|
||||
import akka.annotation.{ ApiMayChange, DoNotInherit, InternalApi }
|
||||
|
|
@ -329,8 +328,8 @@ object Behavior {
|
|||
def start[T](behavior: Behavior[T], ctx: TypedActorContext[T]): Behavior[T] = {
|
||||
// TODO can this be made @tailrec?
|
||||
behavior match {
|
||||
case innerDeferred: DeferredBehavior[T] => start(innerDeferred(ctx), ctx)
|
||||
case wrapped: WrappingBehavior[T, Any] @unchecked =>
|
||||
case innerDeferred: DeferredBehavior[T] => start(innerDeferred(ctx), ctx)
|
||||
case wrapped: InterceptorImpl[T, Any] @unchecked =>
|
||||
// make sure that a deferred behavior wrapped inside some other behavior is also started
|
||||
val startedInner = start(wrapped.nestedBehavior, ctx.asInstanceOf[TypedActorContext[Any]])
|
||||
if (startedInner eq wrapped.nestedBehavior) wrapped
|
||||
|
|
@ -349,7 +348,7 @@ object Behavior {
|
|||
def loop(b: Behavior[T]): Boolean =
|
||||
b match {
|
||||
case _ if p(b) => true
|
||||
case wrappingBehavior: WrappingBehavior[T, T] @unchecked =>
|
||||
case wrappingBehavior: InterceptorImpl[T, T] @unchecked =>
|
||||
loop(wrappingBehavior.nestedBehavior)
|
||||
case d: DeferredBehavior[T] =>
|
||||
throw new IllegalArgumentException(
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ private[akka] object InterceptorImpl {
|
|||
private[akka] final class InterceptorImpl[O, I](
|
||||
val interceptor: BehaviorInterceptor[O, I],
|
||||
val nestedBehavior: Behavior[I])
|
||||
extends ExtensibleBehavior[O]
|
||||
with WrappingBehavior[O, I] {
|
||||
extends ExtensibleBehavior[O] {
|
||||
|
||||
import BehaviorInterceptor._
|
||||
|
||||
|
|
@ -70,7 +69,7 @@ private[akka] final class InterceptorImpl[O, I](
|
|||
deduplicate(started, ctx)
|
||||
}
|
||||
|
||||
override def replaceNested(newNested: Behavior[I]): Behavior[O] =
|
||||
def replaceNested(newNested: Behavior[I]): Behavior[O] =
|
||||
new InterceptorImpl(interceptor, newNested)
|
||||
|
||||
override def receive(ctx: typed.TypedActorContext[O], msg: O): Behavior[O] = {
|
||||
|
|
|
|||
|
|
@ -54,11 +54,11 @@ import scala.collection.immutable.HashMap
|
|||
// eliminate that interceptor
|
||||
loop(i.nestedBehavior)
|
||||
|
||||
case w: WrappingBehavior[T, T] =>
|
||||
val nested = w.nestedBehavior
|
||||
case i: InterceptorImpl[T, T] =>
|
||||
val nested = i.nestedBehavior
|
||||
val inner = loop(nested)
|
||||
if (inner eq nested) w
|
||||
else w.replaceNested(inner)
|
||||
if (inner eq nested) i
|
||||
else i.replaceNested(inner)
|
||||
|
||||
case b => b
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018-2019 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package akka.actor.typed.internal
|
||||
|
||||
import akka.actor.typed.Behavior
|
||||
import akka.annotation.DoNotInherit
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
// FIXME #26504: see if we can completely eliminate this with the help of BehaviorInterceptor instead
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*
|
||||
* Behaviors that wrap other behaviors must sometimes be traversed to look through the stack of behaviors,
|
||||
* for example to deduplicate wrapping behaviors. They should therefore implement this trait (interface).
|
||||
*
|
||||
* Do not implement this, instead reach for [[akka.actor.typed.BehaviorInterceptor]]
|
||||
*/
|
||||
@DoNotInherit
|
||||
@InternalApi
|
||||
private[akka] trait WrappingBehavior[O, I] {
|
||||
|
||||
/**
|
||||
* @return The behavior that is wrapped by this behavior
|
||||
*/
|
||||
def nestedBehavior: Behavior[I]
|
||||
|
||||
/**
|
||||
* Replace the behavior that is wrapped by this behavior with a new nested behavior
|
||||
* @return a new instance of this wrapping behavior with `newNested` as nestedBehavior
|
||||
*/
|
||||
def replaceNested(newNested: Behavior[I]): Behavior[O]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue