Removed not used UntypedPropsBehavior (#25054)

Removed unnecessary pattern matching
This commit is contained in:
jorgesg1986 2018-05-07 03:15:52 +01:00 committed by Konrad `ktoso` Malawski
parent e8a955cdef
commit 1b83e339f4
6 changed files with 16 additions and 86 deletions

View file

@ -11,7 +11,6 @@ import akka.actor.InvalidMessageException
import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.Behaviors
import akka.{ Done, NotUsed, actor untyped } import akka.{ Done, NotUsed, actor untyped }
import akka.testkit._ import akka.testkit._
import akka.actor.typed.Behavior.UntypedPropsBehavior
object AdapterSpec { object AdapterSpec {
val untyped1: untyped.Props = untyped.Props(new Untyped1) val untyped1: untyped.Props = untyped.Props(new Untyped1)
@ -297,27 +296,5 @@ class AdapterSpec extends AkkaSpec {
typedRef ! "stop-child" typedRef ! "stop-child"
probe.expectMsg("terminated") probe.expectMsg("terminated")
} }
"spawn untyped behavior anonymously" in {
val probe = TestProbe()
val untypedBehavior: Behavior[String] = new UntypedPropsBehavior[String] {
override def untypedProps(props: akka.actor.typed.Props): akka.actor.Props =
untypedForwarder(probe.ref)
}
val ref = system.spawnAnonymous(untypedBehavior)
ref ! "hello"
probe.expectMsg("hello")
}
"spawn untyped behavior" in {
val probe = TestProbe()
val untypedBehavior: Behavior[String] = new UntypedPropsBehavior[String] {
override def untypedProps(props: akka.actor.typed.Props): akka.actor.Props =
untypedForwarder(probe.ref)
}
val ref = system.spawn(untypedBehavior, "test")
ref ! "hello"
probe.expectMsg("hello")
}
} }
} }

View file

@ -178,16 +178,6 @@ object Behavior {
override def toString = "Unhandled" override def toString = "Unhandled"
} }
/**
* INTERNAL API
* Used to create untyped props from behaviours, or directly returning an untyped props that implements this behavior.
*/
@InternalApi
private[akka] abstract class UntypedPropsBehavior[T] extends Behavior[T] {
/** INTERNAL API */
@InternalApi private[akka] def untypedProps(props: Props): akka.actor.Props
}
/** /**
* INTERNAL API * INTERNAL API
*/ */
@ -328,9 +318,6 @@ object Behavior {
case null throw new InvalidMessageException("[null] is not an allowed behavior") case null throw new InvalidMessageException("[null] is not an allowed behavior")
case SameBehavior | UnhandledBehavior case SameBehavior | UnhandledBehavior
throw new IllegalArgumentException(s"cannot execute with [$behavior] as behavior") throw new IllegalArgumentException(s"cannot execute with [$behavior] as behavior")
case _: UntypedPropsBehavior[_]
throw new IllegalArgumentException(s"cannot wrap behavior [$behavior] in " +
"Behaviors.setup, Behaviors.supervise or similar")
case d: DeferredBehavior[_] throw new IllegalArgumentException(s"deferred [$d] should not be passed to interpreter") case d: DeferredBehavior[_] throw new IllegalArgumentException(s"deferred [$d] should not be passed to interpreter")
case IgnoreBehavior SameBehavior.asInstanceOf[Behavior[T]] case IgnoreBehavior SameBehavior.asInstanceOf[Behavior[T]]
case s: StoppedBehavior[T] s case s: StoppedBehavior[T] s

View file

@ -7,7 +7,6 @@ package internal
package adapter package adapter
import akka.actor.ExtendedActorSystem import akka.actor.ExtendedActorSystem
import akka.actor.typed.Behavior.UntypedPropsBehavior
import akka.annotation.InternalApi import akka.annotation.InternalApi
import akka.util.OptionVal import akka.util.OptionVal
import akka.{ ConfigurationException, actor a } import akka.{ ConfigurationException, actor a }
@ -124,12 +123,6 @@ import scala.concurrent.duration._
} }
def spawnAnonymous[T](ctx: akka.actor.ActorContext, behavior: Behavior[T], props: Props): ActorRef[T] = { def spawnAnonymous[T](ctx: akka.actor.ActorContext, behavior: Behavior[T], props: Props): ActorRef[T] = {
behavior match {
case b: UntypedPropsBehavior[_]
// TODO dispatcher from props
ActorRefAdapter(ctx.actorOf(b.untypedProps(props)))
case _
try { try {
Behavior.validateAsInitial(behavior) Behavior.validateAsInitial(behavior)
ActorRefAdapter(ctx.actorOf(PropsAdapter(() behavior, props))) ActorRefAdapter(ctx.actorOf(PropsAdapter(() behavior, props)))
@ -138,15 +131,8 @@ import scala.concurrent.duration._
throw new ConfigurationException("Remote deployment not allowed for typed actors", ex) throw new ConfigurationException("Remote deployment not allowed for typed actors", ex)
} }
} }
}
def spawn[T](ctx: akka.actor.ActorContext, behavior: Behavior[T], name: String, props: Props): ActorRef[T] = { def spawn[T](ctx: akka.actor.ActorContext, behavior: Behavior[T], name: String, props: Props): ActorRef[T] = {
behavior match {
case b: UntypedPropsBehavior[_]
// TODO dispatcher from props
ActorRefAdapter(ctx.actorOf(b.untypedProps(props), name))
case _
try { try {
Behavior.validateAsInitial(behavior) Behavior.validateAsInitial(behavior)
ActorRefAdapter(ctx.actorOf(PropsAdapter(() behavior, props), name)) ActorRefAdapter(ctx.actorOf(PropsAdapter(() behavior, props), name))
@ -155,6 +141,5 @@ import scala.concurrent.duration._
throw new ConfigurationException("Remote deployment not allowed for typed actors", ex) throw new ConfigurationException("Remote deployment not allowed for typed actors", ex)
} }
} }
}
} }

View file

@ -5,7 +5,6 @@
package akka.actor.typed package akka.actor.typed
package scaladsl package scaladsl
import akka.actor.typed.Behavior.UntypedPropsBehavior
import akka.actor.typed.internal.adapter._ import akka.actor.typed.internal.adapter._
/** /**
@ -38,22 +37,12 @@ package object adapter {
implicit class UntypedActorSystemOps(val sys: akka.actor.ActorSystem) extends AnyVal { implicit class UntypedActorSystemOps(val sys: akka.actor.ActorSystem) extends AnyVal {
def spawnAnonymous[T](behavior: Behavior[T], props: Props = Props.empty): ActorRef[T] = { def spawnAnonymous[T](behavior: Behavior[T], props: Props = Props.empty): ActorRef[T] = {
behavior match {
case b: UntypedPropsBehavior[_]
ActorRefAdapter(sys.actorOf(b.untypedProps(props)))
case _
ActorRefAdapter(sys.actorOf(PropsAdapter(Behavior.validateAsInitial(behavior), props))) ActorRefAdapter(sys.actorOf(PropsAdapter(Behavior.validateAsInitial(behavior), props)))
} }
}
def spawn[T](behavior: Behavior[T], name: String, props: Props = Props.empty): ActorRef[T] = { def spawn[T](behavior: Behavior[T], name: String, props: Props = Props.empty): ActorRef[T] = {
behavior match {
case b: UntypedPropsBehavior[_]
ActorRefAdapter(sys.actorOf(b.untypedProps(props), name))
case _
ActorRefAdapter(sys.actorOf(PropsAdapter(Behavior.validateAsInitial(behavior), props), name)) ActorRefAdapter(sys.actorOf(PropsAdapter(Behavior.validateAsInitial(behavior), props), name))
} }
}
def toTyped: ActorSystem[Nothing] = AdapterExtension(sys).adapter def toTyped: ActorSystem[Nothing] = AdapterExtension(sys).adapter
} }

View file

@ -15,7 +15,6 @@ import akka.actor.{ InternalActorRef, Scheduler }
import akka.actor.typed.ActorRef import akka.actor.typed.ActorRef
import akka.actor.typed.ActorSystem import akka.actor.typed.ActorSystem
import akka.actor.typed.Behavior import akka.actor.typed.Behavior
import akka.actor.typed.Behavior.UntypedPropsBehavior
import akka.actor.typed.Props import akka.actor.typed.Props
import akka.actor.typed.internal.adapter.ActorRefAdapter import akka.actor.typed.internal.adapter.ActorRefAdapter
import akka.actor.typed.internal.adapter.ActorSystemAdapter import akka.actor.typed.internal.adapter.ActorSystemAdapter
@ -142,10 +141,7 @@ import akka.japi.function.{ Function ⇒ JFunction }
log.info("Starting Shard Region [{}]...", typeKey.name) log.info("Starting Shard Region [{}]...", typeKey.name)
val untypedEntityPropsFactory: String akka.actor.Props = { entityId val untypedEntityPropsFactory: String akka.actor.Props = { entityId
behavior(entityId) match { PropsAdapter(behavior(entityId), entityProps)
case u: UntypedPropsBehavior[_] u.untypedProps(Props.empty) // PersistentBehavior
case b PropsAdapter(b, entityProps)
}
} }
untypedSharding.internalStart( untypedSharding.internalStart(

View file

@ -10,7 +10,6 @@ import java.util.function.{ Function ⇒ JFunction }
import akka.actor.{ ExtendedActorSystem, InvalidActorNameException } import akka.actor.{ ExtendedActorSystem, InvalidActorNameException }
import akka.annotation.InternalApi import akka.annotation.InternalApi
import akka.cluster.singleton.{ ClusterSingletonProxy, ClusterSingletonManager OldSingletonManager } import akka.cluster.singleton.{ ClusterSingletonProxy, ClusterSingletonManager OldSingletonManager }
import akka.actor.typed.Behavior.UntypedPropsBehavior
import akka.cluster.typed.{ Cluster, ClusterSingleton, ClusterSingletonImpl, ClusterSingletonSettings } import akka.cluster.typed.{ Cluster, ClusterSingleton, ClusterSingletonImpl, ClusterSingletonSettings }
import akka.actor.typed.internal.adapter.ActorSystemAdapter import akka.actor.typed.internal.adapter.ActorSystemAdapter
import akka.actor.typed.{ ActorRef, ActorSystem, Behavior, Props } import akka.actor.typed.{ ActorRef, ActorSystem, Behavior, Props }
@ -41,10 +40,7 @@ private[akka] final class AdaptedClusterSingletonImpl(system: ActorSystem[_]) ex
if (settings.shouldRunManager(cluster)) { if (settings.shouldRunManager(cluster)) {
val managerName = managerNameFor(singletonName) val managerName = managerNameFor(singletonName)
// start singleton on this node // start singleton on this node
val untypedProps = behavior match { val untypedProps = PropsAdapter(behavior, props)
case u: UntypedPropsBehavior[_] u.untypedProps(props) // PersistentBehavior
case _ PropsAdapter(behavior, props)
}
try { try {
untypedSystem.systemActorOf( untypedSystem.systemActorOf(
OldSingletonManager.props(untypedProps, terminationMessage, settings.toManagerSettings(singletonName)), OldSingletonManager.props(untypedProps, terminationMessage, settings.toManagerSettings(singletonName)),