Add name to InMemory services
This commit is contained in:
@@ -8,7 +8,7 @@ import java.util.UUID
|
||||
|
||||
class GameEventBusInMemory :
|
||||
GameEventBus,
|
||||
Bus<GameEvent> by BusInMemory(),
|
||||
Bus<GameEvent> by BusInMemory(GameEventBusInMemory::class),
|
||||
Comparable<GameEventBusInMemory> {
|
||||
private val instanceId: UUID = UUID.randomUUID()
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class GameListRepositoryInMemory(
|
||||
) : GameListRepository {
|
||||
private val projectionsSnapshot =
|
||||
ProjectionSnapshotRepositoryInMemory(
|
||||
name = GameListRepositoryInMemory::class,
|
||||
eventStore = eventStore,
|
||||
snapshotCacheConfig = snapshotConfig,
|
||||
applyToProjection = GameList::apply,
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.UUID
|
||||
|
||||
class GameProjectionBusInMemory :
|
||||
GameProjectionBus,
|
||||
Bus<Projection<GameId>> by BusInMemory(),
|
||||
Bus<Projection<GameId>> by BusInMemory(GameProjectionBusInMemory::class),
|
||||
Comparable<GameProjectionBusInMemory> {
|
||||
private val instanceId: UUID = UUID.randomUUID()
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class GameStateRepositoryInMemory(
|
||||
) : GameStateRepository {
|
||||
private val projectionsSnapshot =
|
||||
ProjectionSnapshotRepositoryInMemory(
|
||||
name = GameStateRepositoryInMemory::class,
|
||||
eventStore = eventStore,
|
||||
snapshotCacheConfig = snapshotConfig,
|
||||
applyToProjection = GameState::apply,
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package eventDemo.libs.bus
|
||||
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.github.oshai.kotlinlogging.withLoggingContext
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class BusInMemory<E> : Bus<E> {
|
||||
class BusInMemory<E>(
|
||||
val name: KClass<*> = BusInMemory::class,
|
||||
) : Bus<E> {
|
||||
private val logger = KotlinLogging.logger(name.qualifiedName.toString())
|
||||
private val subscribers: MutableList<Pair<Int, suspend (E) -> Unit>> = mutableListOf()
|
||||
|
||||
override suspend fun publish(item: E) {
|
||||
withLoggingContext("busItem" to item.toString()) {
|
||||
logger.info { "Item sent to the bus: $item" }
|
||||
subscribers
|
||||
.sortedByDescending { (priority, _) -> priority }
|
||||
.forEach { (_, block) ->
|
||||
|
||||
@@ -10,15 +10,17 @@ import kotlinx.datetime.Clock
|
||||
import kotlinx.datetime.Instant
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class ProjectionSnapshotRepositoryInMemory<E : Event<ID>, P : Projection<ID>, ID : AggregateId>(
|
||||
val name: KClass<*> = ProjectionSnapshotRepositoryInMemory::class,
|
||||
private val eventStore: EventStore<E, ID>,
|
||||
private val initialStateBuilder: (aggregateId: ID) -> P,
|
||||
private val snapshotCacheConfig: SnapshotConfig = SnapshotConfig(),
|
||||
private val applyToProjection: P.(event: E) -> P,
|
||||
) : ProjectionSnapshotRepository<E, P, ID> {
|
||||
private val projectionsSnapshot: ConcurrentHashMap<ID, ConcurrentLinkedQueue<Pair<P, Instant>>> = ConcurrentHashMap()
|
||||
private val logger = KotlinLogging.logger { }
|
||||
private val logger = KotlinLogging.logger(name.qualifiedName.toString())
|
||||
|
||||
/**
|
||||
* Create a snapshot for the event
|
||||
|
||||
Reference in New Issue
Block a user