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