abstract class ExtensionId[T <: Extension] extends AnyRef
Identifier and factory for an extension. Is used to look up an extension from the ActorSystem
, and possibly create
an instance if no instance was already registered. The extension can also be listed in the actor system configuration
to have it eagerly loaded and registered on actor system startup.
*Scala API*
The ExtensionId
for an extension written in Scala is best done by letting it be the companion object of the
extension. If the extension will be used from Java special care needs to be taken to provide a get
method with the
concrete extension type as return (as this will not be inferred correctly by the Java compiler with the default
implementation)
Example:
object MyExt extends ExtensionId[Ext] { override def createExtension(system: ActorSystem[_]): MyExt = new MyExt(system) // Java API: retrieve the extension instance for the given system. def get(system: ActorSystem[_]): MyExt = apply(system) } class MyExt(system: ActorSystem[_]) extends Extension { ... } // can be loaded eagerly on system startup through configuration // note that the name is the JVM/Java class name, with a dollar sign in the end // and not the Scala object name akka.actor.typed.extensions = ["com.example.MyExt$"] // Allows access like this from Scala MyExt().someMethodOnTheExtension() // and from Java MyExt.get(system).someMethodOnTheExtension()
*Java API*
To implement an extension in Java you should first create an ExtensionId
singleton by implementing a static method
called getInstance
, this is needed to be able to list the extension among the akka.actor.typed.extensions
in the configuration
and have it loaded when the actor system starts up.
public class MyExt extends AbstractExtensionId<MyExtImpl> { // single instance of the identifier private final static MyExt instance = new MyExt(); // protect against other instances than the singleton private MyExt() {} // This static method singleton accessor is needed to be able to enable the extension through config when // implementing extensions in Java. public static MyExt getInstance() { return instance; } public MyExtImpl createExtension(ActorSystem<?> system) { return new MyExtImpl(); } // convenience accessor public static MyExtImpl get(ActorSystem<?> system) { return instance.apply(system); } } public class MyExtImpl implements Extension { ... } // can be loaded eagerly on system startup through configuration akka.actor.typed.extensions = ["com.example.MyExt"] // Allows access like this from Scala MyExt.someMethodOnTheExtension() // and from Java MyExt.get(system).someMethodOnTheExtension()
For testing purposes extensions typically provide a concrete ExtensionSetup that can be used in akka.actor.setup.ActorSystemSetup when starting the ActorSystem to replace the default implementation of the extension.
- T
The concrete extension type
- Source
- Extensions.scala
- See also
- Alphabetic
- By Inheritance
- ExtensionId
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new ExtensionId()
Abstract Value Members
- abstract def createExtension(system: ActorSystem[_]): T
Create the extension, will be invoked at most one time per actor system where the extension is registered.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- def +(other: String): String
- Implicit
- This member is added by an implicit conversion from ExtensionId[T] toany2stringadd[ExtensionId[T]] performed by method any2stringadd in scala.Predef.
- Definition Classes
- any2stringadd
- def ->[B](y: B): (ExtensionId[T], B)
- Implicit
- This member is added by an implicit conversion from ExtensionId[T] toArrowAssoc[ExtensionId[T]] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def apply(system: ActorSystem[_]): T
Lookup or create an instance of the extension identified by this id.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
- def ensuring(cond: (ExtensionId[T]) => Boolean, msg: => Any): ExtensionId[T]
- Implicit
- This member is added by an implicit conversion from ExtensionId[T] toEnsuring[ExtensionId[T]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: (ExtensionId[T]) => Boolean): ExtensionId[T]
- Implicit
- This member is added by an implicit conversion from ExtensionId[T] toEnsuring[ExtensionId[T]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: Boolean, msg: => Any): ExtensionId[T]
- Implicit
- This member is added by an implicit conversion from ExtensionId[T] toEnsuring[ExtensionId[T]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: Boolean): ExtensionId[T]
- Implicit
- This member is added by an implicit conversion from ExtensionId[T] toEnsuring[ExtensionId[T]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def equals(other: Any): Boolean
- Definition Classes
- ExtensionId → AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def hashCode(): Int
- Definition Classes
- ExtensionId → AnyRef → Any
- def id: ExtensionId[T]
Java API: The identifier of the extension
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)
- def formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from ExtensionId[T] toStringFormat[ExtensionId[T]] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.12.16) Use
formatString.format(value)
instead ofvalue.formatted(formatString)
, or use thef""
string interpolator. In Java 15 and later,formatted
resolves to the new method in String which has reversed parameters.
- def →[B](y: B): (ExtensionId[T], B)
- Implicit
- This member is added by an implicit conversion from ExtensionId[T] toArrowAssoc[ExtensionId[T]] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use
->
instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.