c

akka.actor.typed

ExtensionId

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

ExtensionSetup

Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ExtensionId
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new ExtensionId()

Abstract Value Members

  1. 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

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. 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
  4. 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()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. final def apply(system: ActorSystem[_]): T

    Lookup or create an instance of the extension identified by this id.

  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
  9. 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
  10. 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
  11. 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
  12. 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
  13. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def equals(other: Any): Boolean
    Definition Classes
    ExtensionId → AnyRef → Any
  15. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  16. final def hashCode(): Int
    Definition Classes
    ExtensionId → AnyRef → Any
  17. def id: ExtensionId[T]

    Java API: The identifier of the extension

  18. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  19. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  21. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  22. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  23. def toString(): String
    Definition Classes
    AnyRef → Any
  24. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  25. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  26. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

  2. 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 of value.formatted(formatString), or use the f"" string interpolator. In Java 15 and later, formatted resolves to the new method in String which has reversed parameters.

  3. 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.

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd fromExtensionId[T] to any2stringadd[ExtensionId[T]]

Inherited by implicit conversion StringFormat fromExtensionId[T] to StringFormat[ExtensionId[T]]

Inherited by implicit conversion Ensuring fromExtensionId[T] to Ensuring[ExtensionId[T]]

Inherited by implicit conversion ArrowAssoc fromExtensionId[T] to ArrowAssoc[ExtensionId[T]]

Ungrouped