update cache-module

This commit is contained in:
2025-09-03 23:29:37 +02:00
parent 63a1b97db7
commit 2eefe24a4f
6 changed files with 93 additions and 93 deletions
@@ -4,73 +4,73 @@ import at.mocode.core.domain.event.DomainEvent
import java.util.UUID
/**
* Interface for serializing and deserializing domain events.
* Schnittstelle für die Serialisierung und Deserialisierung von Domain-Events.
*/
interface EventSerializer {
/**
* Serializes a domain event to a map of strings to strings.
* This format is suitable for storage in Redis Streams.
* Serialisiert ein Domain-Event zu einer Map von Strings zu Strings.
* Dieses Format ist für die Speicherung in Redis Streams geeignet.
*
* @param event The event to serialize
* @return A map of strings to strings representing the event
* @param event Das zu serialisierende Event
* @return Eine Map von Strings zu Strings, die das Event repräsentiert
*/
fun serialize(event: DomainEvent): Map<String, String>
/**
* Deserializes a map of strings to a domain event.
* Deserialisiert eine Map von Strings zu einem Domain-Event.
*
* @param data The map of strings to deserialize
* @return The deserialized domain event
* @param data Die zu deserialisierende Map von Strings
* @return Das deserialisierte Domain-Event
*/
fun deserialize(data: Map<String, String>): DomainEvent
/**
* Gets the type of domain event.
* This is used to determine the type of event when deserializing.
* Ermittelt den Typ des Domain-Events.
* Dies wird verwendet, um den Typ des Events bei der Deserialisierung zu bestimmen.
*
* @param event The event to get the type of
* @return The type of the event as a string
* @param event Das Event, dessen Typ ermittelt werden soll
* @return Der Typ des Events als String
*/
fun getEventType(event: DomainEvent): String
/**
* Gets the type of domain event from a serialized map.
* Ermittelt den Typ des Domain-Events aus einer serialisierten Map.
*
* @param data The serialized event data
* @return The type of the event as a string
* @param data Die serialisierten Event-Daten
* @return Der Typ des Events als String
*/
fun getEventType(data: Map<String, String>): String
/**
* Registers a domain event class with the serializer.
* This is used to map event types to their corresponding classes.
* Registriert eine Domain-Event-Klasse beim Serializer.
* Dies wird verwendet, um Event-Typen auf ihre entsprechenden Klassen abzubilden.
*
* @param eventClass The class of the event to register
* @param eventType The type of the event as a string
* @param eventClass Die Klasse des zu registrierenden Events
* @param eventType Der Typ des Events als String
*/
fun registerEventType(eventClass: Class<out DomainEvent>, eventType: String)
/**
* Gets the aggregate ID from a serialized event.
* Ermittelt die Aggregat-ID aus einem serialisierten Event.
*
* @param data The serialized event data
* @return The aggregate ID
* @param data Die serialisierten Event-Daten
* @return Die Aggregat-ID
*/
fun getAggregateId(data: Map<String, String>): UUID
/**
* Gets the event ID from a serialized event.
* Ermittelt die Event-ID aus einem serialisierten Event.
*
* @param data The serialized event data
* @return The event ID
* @param data Die serialisierten Event-Daten
* @return Die Event-ID
*/
fun getEventId(data: Map<String, String>): UUID
/**
* Gets the version from a serialized event.
* Ermittelt die Version aus einem serialisierten Event.
*
* @param data The serialized event data
* @return The version
* @param data Die serialisierten Event-Daten
* @return Die Version
*/
fun getVersion(data: Map<String, String>): Long
}
@@ -4,96 +4,96 @@ import at.mocode.core.domain.event.DomainEvent
import java.util.UUID
/**
* Interface for an event store that persists domain events.
* Schnittstelle für einen Event Store, der Domain-Events persistiert.
*/
interface EventStore {
/**
* Appends an event to the event store.
* Fügt ein Event zum Event Store hinzu.
*
* @param event The event to append
* @param streamId The ID of the event stream (typically the aggregate ID)
* @param expectedVersion The expected version of the stream (for optimistic concurrency)
* @return The new version of the stream
* @throws ConcurrencyException if the expected version doesn't match the actual version
* @param event Das hinzuzufügende Event
* @param streamId Die ID des Event-Streams (normalerweise die Aggregat-ID)
* @param expectedVersion Die erwartete Version des Streams (für optimistische Nebenläufigkeitskontrolle)
* @return Die neue Version des Streams
* @throws ConcurrencyException wenn die erwartete Version nicht mit der tatsächlichen Version übereinstimmt
*/
fun appendToStream(event: DomainEvent, streamId: UUID, expectedVersion: Long): Long
/**
* Appends multiple events to the event store.
* Fügt mehrere Events zum Event Store hinzu.
*
* @param events The events to append
* @param streamId The ID of the event stream (typically the aggregate ID)
* @param expectedVersion The expected version of the stream (for optimistic concurrency)
* @return The new version of the stream
* @throws ConcurrencyException if the expected version doesn't match the actual version
* @param events Die hinzuzufügenden Events
* @param streamId Die ID des Event-Streams (normalerweise die Aggregat-ID)
* @param expectedVersion Die erwartete Version des Streams (für optimistische Nebenläufigkeitskontrolle)
* @return Die neue Version des Streams
* @throws ConcurrencyException wenn die erwartete Version nicht mit der tatsächlichen Version übereinstimmt
*/
fun appendToStream(events: List<DomainEvent>, streamId: UUID, expectedVersion: Long): Long
/**
* Reads events from a stream.
* Liest Events aus einem Stream.
*
* @param streamId The ID of the event stream to read from
* @param fromVersion The version to start reading from (inclusive)
* @param toVersion The version to read to (inclusive), or null to read all events
* @return The events in the stream
* @param streamId Die ID des Event-Streams, aus dem gelesen werden soll
* @param fromVersion Die Version, ab der gelesen werden soll (inklusive)
* @param toVersion Die Version, bis zu der gelesen werden soll (inklusive), oder null um alle Events zu lesen
* @return Die Events im Stream
*/
fun readFromStream(streamId: UUID, fromVersion: Long = 0, toVersion: Long? = null): List<DomainEvent>
/**
* Reads all events from all streams.
* Liest alle Events aus allen Streams.
*
* @param fromPosition The position to start reading from (inclusive)
* @param maxCount The maximum number of events to read, or null to read all events
* @return The events in all streams
* @param fromPosition Die Position, ab der gelesen werden soll (inklusive)
* @param maxCount Die maximale Anzahl der zu lesenden Events, oder null um alle Events zu lesen
* @return Die Events in allen Streams
*/
fun readAllEvents(fromPosition: Long = 0, maxCount: Int? = null): List<DomainEvent>
/**
* Gets the current version of a stream.
* Ermittelt die aktuelle Version eines Streams.
*
* @param streamId The ID of the event stream
* @return The current version of the stream, or -1 if the stream doesn't exist
* @param streamId Die ID des Event-Streams
* @return Die aktuelle Version des Streams, oder -1 wenn der Stream nicht existiert
*/
fun getStreamVersion(streamId: UUID): Long
/**
* Subscribes to events from a specific stream.
* Abonniert Events von einem spezifischen Stream.
*
* @param streamId The ID of the event stream to subscribe to
* @param fromVersion The version to start subscribing from (inclusive)
* @param handler The handler to call for each event
* @return A subscription that can be used to unsubscribe
* @param streamId Die ID des Event-Streams, der abonniert werden soll
* @param fromVersion Die Version, ab der abonniert werden soll (inklusive)
* @param handler Der Handler, der für jedes Event aufgerufen wird
* @return Ein Abonnement, das zum Abbestellen verwendet werden kann
*/
fun subscribeToStream(streamId: UUID, fromVersion: Long = 0, handler: (DomainEvent) -> Unit): Subscription
/**
* Subscribes to all events from all streams.
* Abonniert alle Events von allen Streams.
*
* @param fromPosition The position to start subscribing from (inclusive)
* @param handler The handler to call for each event
* @return A subscription that can be used to unsubscribe
* @param fromPosition Die Position, ab der abonniert werden soll (inklusive)
* @param handler Der Handler, der für jedes Event aufgerufen wird
* @return Ein Abonnement, das zum Abbestellen verwendet werden kann
*/
fun subscribeToAll(fromPosition: Long = 0, handler: (DomainEvent) -> Unit): Subscription
}
/**
* Interface for a subscription to an event stream.
* Schnittstelle für ein Abonnement eines Event-Streams.
*/
interface Subscription {
/**
* Unsubscribes from the event stream.
* Beendet das Abonnement des Event-Streams.
*/
fun unsubscribe()
/**
* Checks if the subscription is active.
* Überprüft, ob das Abonnement aktiv ist.
*
* @return true if the subscription is active, false otherwise
* @return true wenn das Abonnement aktiv ist, false andernfalls
*/
fun isActive(): Boolean
}
/**
* Exception thrown when there is a concurrency conflict in the event store.
* Exception, die bei einem Nebenläufigkeitskonflikt im Event Store ausgelöst wird.
*/
class ConcurrencyException(message: String) : RuntimeException(message)