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

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] to any2stringadd[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] to ArrowAssoc[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( ... ) @native() @HotSpotIntrinsicCandidate()
  9. def ensuring(cond: (ExtensionId[T]) ⇒ Boolean, msg: ⇒ Any): ExtensionId[T]
    Implicit
    This member is added by an implicit conversion from ExtensionId[T] to Ensuring[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] to Ensuring[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] to Ensuring[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] to Ensuring[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. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from ExtensionId[T] to StringFormat[ExtensionId[T]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  16. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  17. final def hashCode(): Int
    Definition Classes
    ExtensionId → AnyRef → Any
  18. def id: ExtensionId[T]

    Java API: The identifier of the extension

  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  23. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  24. def toString(): String
    Definition Classes
    AnyRef → Any
  25. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  27. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. def [B](y: B): (ExtensionId[T], B)
    Implicit
    This member is added by an implicit conversion from ExtensionId[T] to ArrowAssoc[ExtensionId[T]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Deprecated Value Members

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

    (Since version ) see corresponding Javadoc for more information.

Inherited from AnyRef

Inherited from Any

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

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

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

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

Ungrouped