diff --git a/akka-docs/rst/java/lambda-persistence.rst b/akka-docs/rst/java/lambda-persistence.rst index 074bfaf6a9..2f7549fd0a 100644 --- a/akka-docs/rst/java/lambda-persistence.rst +++ b/akka-docs/rst/java/lambda-persistence.rst @@ -787,6 +787,11 @@ Plugin development requires the following imports: .. includecode:: code/docs/persistence/LambdaPersistencePluginDocTest.java#plugin-imports +By default, persistence plugins are started on-demand, as they are used. In some case, however, it might be beneficial +to start a certain plugin eagerly. In order to do that, you should first add the ``akka.persistence.Persistence`` +under the ``akka.extensions`` key. Then, specify the IDs of plugins you wish to start automatically under +``akka.persistence.journal.auto-start-journals`` and ``akka.persistence.snapshot-store.auto-start-snapshot-stores``. + Journal plugin API ------------------ diff --git a/akka-docs/rst/java/persistence.rst b/akka-docs/rst/java/persistence.rst index ff5ec1bc27..eeda6b173e 100644 --- a/akka-docs/rst/java/persistence.rst +++ b/akka-docs/rst/java/persistence.rst @@ -738,6 +738,11 @@ Plugin development requires the following imports: .. includecode:: code/docs/persistence/PersistencePluginDocTest.java#plugin-imports +By default, persistence plugins are started on-demand, as they are used. In some case, however, it might be beneficial +to start a certain plugin eagerly. In order to do that, you should first add the ``akka.persistence.Persistence`` +under the ``akka.extensions`` key. Then, specify the IDs of plugins you wish to start automatically under +``akka.persistence.journal.auto-start-journals`` and ``akka.persistence.snapshot-store.auto-start-snapshot-stores``. + .. _journal-plugin-api-java: Journal plugin API diff --git a/akka-docs/rst/scala/persistence.rst b/akka-docs/rst/scala/persistence.rst index 4dc6c3ded0..3551a34bc8 100644 --- a/akka-docs/rst/scala/persistence.rst +++ b/akka-docs/rst/scala/persistence.rst @@ -797,6 +797,11 @@ Plugin development requires the following imports: .. includecode:: code/docs/persistence/PersistencePluginDocSpec.scala#plugin-imports +By default, persistence plugins are started on-demand, as they are used. In some case, however, it might be beneficial +to start a certain plugin eagerly. In order to do that, you should first add the ``akka.persistence.Persistence`` +under the ``akka.extensions`` key. Then, specify the IDs of plugins you wish to start automatically under +``akka.persistence.journal.auto-start-journals`` and ``akka.persistence.snapshot-store.auto-start-snapshot-stores``. + .. _journal-plugin-api: Journal plugin API diff --git a/akka-persistence/src/main/resources/reference.conf b/akka-persistence/src/main/resources/reference.conf index f8422c7a10..07b674e475 100644 --- a/akka-persistence/src/main/resources/reference.conf +++ b/akka-persistence/src/main/resources/reference.conf @@ -16,6 +16,8 @@ akka.persistence { # Persistent actor or view can override `journalPluginId` method # in order to rely on a different journal plugin. plugin = "" + # List of journal plugins to start automatically. Use "" for the default journal plugin. + auto-start-journals = [] } snapshot-store { # Absolute path to the snapshot plugin configuration entry used by @@ -27,6 +29,8 @@ akka.persistence { # Note that Cluster Sharding is using snapshots, so if you # use Cluster Sharding you need to define a snapshot store plugin. plugin = "" + # List of snapshot stores to start automatically. Use "" for the default snapshot store. + auto-start-snapshot-stores = [] } # used as default-snapshot store if no plugin configured # (see `akka.persistence.snapshot-store`) diff --git a/akka-persistence/src/main/scala/akka/persistence/Persistence.scala b/akka-persistence/src/main/scala/akka/persistence/Persistence.scala index 03be4acba7..a638de919d 100644 --- a/akka-persistence/src/main/scala/akka/persistence/Persistence.scala +++ b/akka-persistence/src/main/scala/akka/persistence/Persistence.scala @@ -5,15 +5,14 @@ package akka.persistence import java.util.concurrent.atomic.AtomicReference +import java.util.function.Consumer import akka.actor._ -import akka.dispatch.Dispatchers import akka.event.{ Logging, LoggingAdapter } -import akka.persistence.journal.{ AsyncWriteJournal, EventAdapters, IdentityEventAdapters, ReplayFilter } +import akka.persistence.journal.{ EventAdapters, IdentityEventAdapters } import akka.util.Helpers.ConfigOps import com.typesafe.config.Config import scala.annotation.tailrec import scala.concurrent.duration._ -import java.util.Locale import akka.util.Reflect import scala.util.control.NonFatal @@ -168,6 +167,20 @@ class Persistence(val system: ExtendedActorSystem) extends Extension { private val journalFallbackConfigPath = "akka.persistence.journal-plugin-fallback" private val snapshotStoreFallbackConfigPath = "akka.persistence.snapshot-store-plugin-fallback" + + config.getStringList("journal.auto-start-journals").forEach(new Consumer[String] { + override def accept(id: String): Unit = { + log.info(s"Auto-starting journal plugin `$id`") + journalFor(id) + } + }) + config.getStringList("snapshot-store.auto-start-snapshot-stores").forEach(new Consumer[String] { + override def accept(id: String): Unit = { + log.info(s"Auto-starting snapshot store `$id`") + snapshotStoreFor(id) + } + }) + /** * Returns an [[akka.persistence.journal.EventAdapters]] object which serves as a per-journal collection of bound event adapters. * If no adapters are registered for a given journal the EventAdapters object will simply return the identity diff --git a/akka-persistence/src/test/scala/akka/persistence/journal/leveldb/PersistencePluginProxySpec.scala b/akka-persistence/src/test/scala/akka/persistence/journal/leveldb/PersistencePluginProxySpec.scala index 8c11e7e1b4..66bfa8b96d 100644 --- a/akka-persistence/src/test/scala/akka/persistence/journal/leveldb/PersistencePluginProxySpec.scala +++ b/akka-persistence/src/test/scala/akka/persistence/journal/leveldb/PersistencePluginProxySpec.scala @@ -9,7 +9,6 @@ import akka.persistence._ import akka.persistence.journal.PersistencePluginProxy import akka.testkit.{ TestProbe, AkkaSpec } import com.typesafe.config.ConfigFactory -import scala.concurrent.duration._ object PersistencePluginProxySpec { lazy val config = ConfigFactory.parseString( @@ -54,6 +53,8 @@ object PersistencePluginProxySpec { def targetAddressConfig(system: ActorSystem) = ConfigFactory.parseString( s""" + |akka.extensions = ["akka.persistence.Persistence"] + |akka.persistence.journal.auto-start-journals = [""] |akka.persistence.journal.proxy.target-journal-address = "${system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress}" |akka.persistence.snapshot-store.proxy.target-snapshot-store-address = "${system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress}" """.stripMargin)