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 scala.annotation.tailrec
|
||||||
import akka.actor.InvalidMessageException
|
import akka.actor.InvalidMessageException
|
||||||
import akka.actor.typed.internal.BehaviorImpl
|
import akka.actor.typed.internal.{ BehaviorImpl, InterceptorImpl }
|
||||||
import akka.actor.typed.internal.WrappingBehavior
|
|
||||||
import akka.actor.typed.internal.BehaviorImpl.OrElseBehavior
|
import akka.actor.typed.internal.BehaviorImpl.OrElseBehavior
|
||||||
import akka.util.{ LineNumbers, OptionVal }
|
import akka.util.{ LineNumbers, OptionVal }
|
||||||
import akka.annotation.{ ApiMayChange, DoNotInherit, InternalApi }
|
import akka.annotation.{ ApiMayChange, DoNotInherit, InternalApi }
|
||||||
|
|
@ -330,7 +329,7 @@ object Behavior {
|
||||||
// TODO can this be made @tailrec?
|
// TODO can this be made @tailrec?
|
||||||
behavior match {
|
behavior match {
|
||||||
case innerDeferred: DeferredBehavior[T] => start(innerDeferred(ctx), ctx)
|
case innerDeferred: DeferredBehavior[T] => start(innerDeferred(ctx), ctx)
|
||||||
case wrapped: WrappingBehavior[T, Any] @unchecked =>
|
case wrapped: InterceptorImpl[T, Any] @unchecked =>
|
||||||
// make sure that a deferred behavior wrapped inside some other behavior is also started
|
// make sure that a deferred behavior wrapped inside some other behavior is also started
|
||||||
val startedInner = start(wrapped.nestedBehavior, ctx.asInstanceOf[TypedActorContext[Any]])
|
val startedInner = start(wrapped.nestedBehavior, ctx.asInstanceOf[TypedActorContext[Any]])
|
||||||
if (startedInner eq wrapped.nestedBehavior) wrapped
|
if (startedInner eq wrapped.nestedBehavior) wrapped
|
||||||
|
|
@ -349,7 +348,7 @@ object Behavior {
|
||||||
def loop(b: Behavior[T]): Boolean =
|
def loop(b: Behavior[T]): Boolean =
|
||||||
b match {
|
b match {
|
||||||
case _ if p(b) => true
|
case _ if p(b) => true
|
||||||
case wrappingBehavior: WrappingBehavior[T, T] @unchecked =>
|
case wrappingBehavior: InterceptorImpl[T, T] @unchecked =>
|
||||||
loop(wrappingBehavior.nestedBehavior)
|
loop(wrappingBehavior.nestedBehavior)
|
||||||
case d: DeferredBehavior[T] =>
|
case d: DeferredBehavior[T] =>
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,7 @@ private[akka] object InterceptorImpl {
|
||||||
private[akka] final class InterceptorImpl[O, I](
|
private[akka] final class InterceptorImpl[O, I](
|
||||||
val interceptor: BehaviorInterceptor[O, I],
|
val interceptor: BehaviorInterceptor[O, I],
|
||||||
val nestedBehavior: Behavior[I])
|
val nestedBehavior: Behavior[I])
|
||||||
extends ExtensibleBehavior[O]
|
extends ExtensibleBehavior[O] {
|
||||||
with WrappingBehavior[O, I] {
|
|
||||||
|
|
||||||
import BehaviorInterceptor._
|
import BehaviorInterceptor._
|
||||||
|
|
||||||
|
|
@ -70,7 +69,7 @@ private[akka] final class InterceptorImpl[O, I](
|
||||||
deduplicate(started, ctx)
|
deduplicate(started, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def replaceNested(newNested: Behavior[I]): Behavior[O] =
|
def replaceNested(newNested: Behavior[I]): Behavior[O] =
|
||||||
new InterceptorImpl(interceptor, newNested)
|
new InterceptorImpl(interceptor, newNested)
|
||||||
|
|
||||||
override def receive(ctx: typed.TypedActorContext[O], msg: O): Behavior[O] = {
|
override def receive(ctx: typed.TypedActorContext[O], msg: O): Behavior[O] = {
|
||||||
|
|
|
||||||
|
|
@ -54,11 +54,11 @@ import scala.collection.immutable.HashMap
|
||||||
// eliminate that interceptor
|
// eliminate that interceptor
|
||||||
loop(i.nestedBehavior)
|
loop(i.nestedBehavior)
|
||||||
|
|
||||||
case w: WrappingBehavior[T, T] =>
|
case i: InterceptorImpl[T, T] =>
|
||||||
val nested = w.nestedBehavior
|
val nested = i.nestedBehavior
|
||||||
val inner = loop(nested)
|
val inner = loop(nested)
|
||||||
if (inner eq nested) w
|
if (inner eq nested) i
|
||||||
else w.replaceNested(inner)
|
else i.replaceNested(inner)
|
||||||
|
|
||||||
case b => b
|
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