Deprecation of ExtensionKey #22208
This commit is contained in:
parent
8f9b4f203a
commit
cf6d5a4e8a
7 changed files with 78 additions and 14 deletions
|
|
@ -33,9 +33,24 @@ public class JavaExtension extends JUnitSuite {
|
|||
}
|
||||
}
|
||||
|
||||
static class OtherExtensionId extends AbstractExtensionId<OtherExtension> implements ExtensionIdProvider {
|
||||
|
||||
public final static OtherExtensionId OtherExtensionProvider = new OtherExtensionId();
|
||||
|
||||
@Override
|
||||
public ExtensionId<OtherExtension> lookup() {
|
||||
return OtherExtensionId.OtherExtensionProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OtherExtension createExtension(ExtendedActorSystem system) {
|
||||
return new OtherExtension(system);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class OtherExtension implements Extension {
|
||||
static final ExtensionKey<OtherExtension> key = new ExtensionKey<OtherExtension>(OtherExtension.class) {
|
||||
};
|
||||
static final ExtensionId<OtherExtension> key = OtherExtensionId.OtherExtensionProvider;
|
||||
|
||||
public final ExtendedActorSystem system;
|
||||
|
||||
|
|
|
|||
|
|
@ -61,8 +61,6 @@ import scala.reflect.ClassTag
|
|||
* ...
|
||||
* }
|
||||
* }}}
|
||||
*
|
||||
* See also [[akka.actor.ExtensionKey]] for a concise way of formulating extensions.
|
||||
*/
|
||||
trait Extension
|
||||
|
||||
|
|
@ -146,6 +144,7 @@ trait ExtensionIdProvider {
|
|||
* `get` method.
|
||||
*
|
||||
*/
|
||||
@deprecated(message = "Use a regular Extension instead", since = "2.5.0")
|
||||
abstract class ExtensionKey[T <: Extension](implicit m: ClassTag[T]) extends ExtensionId[T] with ExtensionIdProvider {
|
||||
def this(clazz: Class[T]) = this()(ClassTag(clazz))
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@ package akka.event
|
|||
|
||||
import java.util.concurrent.TimeoutException
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.logging
|
||||
|
||||
import akka.actor.ActorSystem.Settings
|
||||
import akka.actor._
|
||||
import akka.dispatch.RequiresMessageQueue
|
||||
import akka.event.Logging.{ Extension ⇒ _, _ }
|
||||
import akka.util.{ OptionVal, ReentrantGuard }
|
||||
import akka.event.Logging._
|
||||
import akka.util.ReentrantGuard
|
||||
import akka.util.Helpers.toRootLowerCase
|
||||
import akka.{ AkkaException, ConfigurationException }
|
||||
|
||||
|
|
@ -175,7 +174,7 @@ trait LoggingBus extends ActorEventBus {
|
|||
* INTERNAL API
|
||||
*/
|
||||
private def addLogger(system: ActorSystemImpl, clazz: Class[_ <: Actor], level: LogLevel, logName: String): ActorRef = {
|
||||
val name = "log" + Extension(system).id() + "-" + simpleName(clazz)
|
||||
val name = "log" + LogExt(system).id() + "-" + simpleName(clazz)
|
||||
val actor = system.systemActorOf(Props(clazz).withDispatcher(system.settings.LoggersDispatcher), name)
|
||||
implicit def timeout = system.settings.LoggerStartTimeout
|
||||
import akka.pattern.ask
|
||||
|
|
@ -409,7 +408,10 @@ object Logging {
|
|||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
private[akka] object Extension extends ExtensionKey[LogExt]
|
||||
private[akka] object LogExt extends ExtensionId[LogExt] {
|
||||
override def createExtension(system: ExtendedActorSystem): LogExt =
|
||||
new LogExt(system)
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
|
|
|
|||
|
|
@ -216,6 +216,30 @@ Actor DSL deprecation
|
|||
Actor DSL is a rarely used feature and thus will be deprecated and removed.
|
||||
Use plain ``system.actorOf`` instead of the DSL to create Actors if you have been using it.
|
||||
|
||||
ExtensionKey Deprecation
|
||||
------------------------
|
||||
|
||||
``ExtensionKey`` is a shortcut for writing :ref:`extending-akka-scala` but extensions created with it
|
||||
cannot be used from Java and it does in fact not save many lines of code over directly implementing ``ExtensionId``.
|
||||
|
||||
|
||||
Old::
|
||||
|
||||
object MyExtension extends ExtensionKey[MyExtension]
|
||||
|
||||
New::
|
||||
|
||||
object MyExtension extends extends ExtensionId[MyExtension] with ExtensionIdProvider {
|
||||
|
||||
override def lookup = MyExtension
|
||||
|
||||
override def createExtension(system: ExtendedActorSystem): MyExtension =
|
||||
new MyExtension(system)
|
||||
|
||||
// needed to get the type right when used from Java
|
||||
override def get(system: ActorSystem): MyExtension = super.get(system)
|
||||
}
|
||||
|
||||
Streams
|
||||
=======
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package docs.serialization {
|
||||
|
||||
import akka.actor.{ExtensionId, ExtensionIdProvider}
|
||||
import akka.testkit._
|
||||
//#imports
|
||||
import akka.actor.{ ActorRef, ActorSystem }
|
||||
|
|
@ -11,7 +12,6 @@ package docs.serialization {
|
|||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
//#imports
|
||||
import akka.actor.ExtensionKey
|
||||
import akka.actor.ExtendedActorSystem
|
||||
import akka.actor.Extension
|
||||
import akka.actor.Address
|
||||
|
|
@ -218,7 +218,14 @@ package docs.serialization {
|
|||
//#actorref-serializer
|
||||
|
||||
//#external-address
|
||||
object ExternalAddress extends ExtensionKey[ExternalAddressExt]
|
||||
object ExternalAddress extends ExtensionId[ExternalAddressExt] with ExtensionIdProvider {
|
||||
override def lookup() = ExternalAddress
|
||||
|
||||
override def createExtension(system: ExtendedActorSystem): ExternalAddressExt =
|
||||
new ExternalAddressExt(system)
|
||||
|
||||
override def get(system: ActorSystem): ExternalAddressExt = super.get(system)
|
||||
}
|
||||
|
||||
class ExternalAddressExt(system: ExtendedActorSystem) extends Extension {
|
||||
def addressFor(remoteAddr: Address): Address =
|
||||
|
|
@ -236,7 +243,14 @@ package docs.serialization {
|
|||
val theActorSystem: ActorSystem = system
|
||||
|
||||
//#external-address-default
|
||||
object ExternalAddress extends ExtensionKey[ExternalAddressExt]
|
||||
object ExternalAddress extends ExtensionId[ExternalAddressExt] with ExtensionIdProvider {
|
||||
override def lookup() = ExternalAddress
|
||||
|
||||
override def createExtension(system: ExtendedActorSystem): ExternalAddressExt =
|
||||
new ExternalAddressExt(system)
|
||||
|
||||
override def get(system: ActorSystem): ExternalAddressExt = super.get(system)
|
||||
}
|
||||
|
||||
class ExternalAddressExt(system: ExtendedActorSystem) extends Extension {
|
||||
def addressForAkka: Address = system.provider.getDefaultAddress
|
||||
|
|
|
|||
|
|
@ -74,7 +74,14 @@ akka.persistence.snapshot-store.plugin = "akka.persistence.no-snapshot-store"
|
|||
}
|
||||
}
|
||||
|
||||
object JournalPuppet extends ExtensionKey[JournalProbe]
|
||||
object JournalPuppet extends ExtensionId[JournalProbe] with ExtensionIdProvider {
|
||||
override def lookup()= JournalPuppet
|
||||
|
||||
override def createExtension(system: ExtendedActorSystem): JournalProbe =
|
||||
new JournalProbe()(system)
|
||||
|
||||
override def get(system: ActorSystem): JournalProbe = super.get(system)
|
||||
}
|
||||
class JournalProbe(implicit private val system: ExtendedActorSystem) extends Extension {
|
||||
val probe = TestProbe()
|
||||
val ref = probe.ref
|
||||
|
|
|
|||
|
|
@ -433,7 +433,10 @@ object MiMa extends AutoPlugin {
|
|||
ProblemFilters.exclude[IncompatibleResultTypeProblem]("akka.cluster.ddata.DurableStore#Store.data"),
|
||||
ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.cluster.ddata.DurableStore#Store.copy"),
|
||||
ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.cluster.ddata.DurableStore#Store.this"),
|
||||
ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.cluster.ddata.LmdbDurableStore.dbPut")
|
||||
ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.cluster.ddata.LmdbDurableStore.dbPut"),
|
||||
|
||||
// #22208 remove extension key
|
||||
ProblemFilters.exclude[MissingClassProblem]("akka.event.Logging$Extension$")
|
||||
|
||||
// NOTE: filters that will be backported to 2.4 should go to the latest 2.4 version below
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue