!per #18050 Make event adapter lookup more efficient
This commit is contained in:
parent
a22b3be9da
commit
b3fedb4cf8
3 changed files with 15 additions and 14 deletions
|
|
@ -5,12 +5,11 @@
|
|||
package akka.persistence.query
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.persistence.journal.{ EventAdapter, EventSeq }
|
||||
import akka.persistence.journal.EventSeq
|
||||
import akka.persistence.journal.ReadEventAdapter
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpecLike }
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
|
||||
|
|
@ -73,9 +72,6 @@ object ExampleQueryModels {
|
|||
case class NewModel(value: String)
|
||||
}
|
||||
|
||||
class PrefixStringWithPAdapter extends EventAdapter {
|
||||
class PrefixStringWithPAdapter extends ReadEventAdapter {
|
||||
override def fromJournal(event: Any, manifest: String) = EventSeq.single("p-" + event)
|
||||
|
||||
override def manifest(event: Any) = ""
|
||||
override def toJournal(event: Any) = throw new Exception("toJournal should not be called by query side")
|
||||
}
|
||||
|
|
@ -16,8 +16,10 @@ import scala.collection.mutable.ArrayBuffer
|
|||
import scala.reflect.ClassTag
|
||||
import scala.util.Try
|
||||
|
||||
/** INTERNAL API */
|
||||
private[akka] class EventAdapters(
|
||||
/**
|
||||
* `EventAdapters` serves as a per-journal collection of bound event adapters.
|
||||
*/
|
||||
class EventAdapters(
|
||||
map: ConcurrentHashMap[Class[_], EventAdapter],
|
||||
bindings: immutable.Seq[(Class[_], EventAdapter)],
|
||||
log: LoggingAdapter) {
|
||||
|
|
@ -62,6 +64,9 @@ private[akka] object EventAdapters {
|
|||
def apply(system: ExtendedActorSystem, config: Config): EventAdapters = {
|
||||
val adapters = configToMap(config, "event-adapters")
|
||||
val adapterBindings = configToListMap(config, "event-adapter-bindings")
|
||||
if (adapters.isEmpty && adapterBindings.isEmpty)
|
||||
IdentityEventAdapters
|
||||
else
|
||||
apply(system, adapters, adapterBindings)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import akka.persistence.AtomicWrite
|
|||
private[akka] trait WriteJournalBase {
|
||||
this: Actor ⇒
|
||||
|
||||
lazy val persistence = Persistence(context.system)
|
||||
private def eventAdapters = persistence.adaptersFor(self)
|
||||
val persistence = Persistence(context.system)
|
||||
private val eventAdapters = persistence.adaptersFor(self)
|
||||
|
||||
protected def preparePersistentBatch(rb: immutable.Seq[PersistentEnvelope]): immutable.Seq[AtomicWrite] =
|
||||
rb.collect { // collect instead of flatMap to avoid Some allocations
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue