11package com.trendyol.kediatr
22
33/* *
4- * Mediator interface for sending queries, commands, and notifications.
4+ * Mediator interface for sending requests and publishing notifications.
55 *
66 * The Mediator pattern encapsulates how objects interact with each other, promoting loose coupling
77 * by preventing objects from referring to each other explicitly. This implementation provides
88 * a centralized way to handle:
9- * - Queries: Request-response operations that return data
10- * - Commands: Operations that modify state and may return results
9+ * - Requests: Unified interface for both queries and commands that return responses
1110 * - Notifications: Fire-and-forget messages that can have multiple handlers
1211 *
13- * @see Query
14- * @see Command
12+ * @see Request
1513 * @see Notification
1614 * @see PublishStrategy
1715 */
1816interface Mediator {
1917 /* *
20- * Sends a query and returns the response.
18+ * Sends a request and returns the response.
2119 *
22- * Queries are typically used for read operations that return data without side effects.
23- * Each query type should have exactly one handler that processes it.
20+ * Requests represent both queries and commands in a unified way. Each request type
21+ * should have exactly one handler that processes it. Requests are typically used for:
22+ * - Queries: Read operations that return data without side effects
23+ * - Commands: Operations that modify state and may return results
2424 *
25- * @param TQuery The type of query that extends Query<TResponse>
26- * @param TResponse The type of response that the query handler will return
27- * @param query The query instance to send
28- * @return The response of the query as returned by its handler
29- * @throws IllegalStateException if no handler is found for the query type
30- * @throws Exception any exception thrown by the query handler
25+ * @param TResponse The type of response that the request handler will return
26+ * @param TRequest The type of request that extends Request<TResponse>
27+ * @return The response of the request as returned by its handler
28+ * @throws HandlerNotFoundException if no handler is found for the request type
29+ * @throws Exception any exception thrown by the request handler
3130 */
32- suspend fun <TQuery : Query <TResponse >, TResponse > send (query : TQuery ): TResponse
33-
34- /* *
35- * Sends a command and returns the result.
36- *
37- * Commands are typically used for write operations that modify state.
38- * Each command type should have exactly one handler that processes it.
39- *
40- * @param TCommand The type of command that extends Command<TResult>
41- * @param TResult The type of result that the command handler will return
42- * @param command The command instance to send
43- * @return The result of the command as returned by its handler
44- * @throws IllegalStateException if no handler is found for the command type
45- * @throws Exception any exception thrown by the command handler
46- */
47- suspend fun <TCommand : Command <TResult >, TResult > send (command : TCommand ): TResult
31+ suspend fun <TRequest : Request <TResponse >, TResponse > send (request : TRequest ): TResponse
4832
4933 /* *
5034 * Publishes a notification using the specified publish strategy.
5135 *
5236 * Notifications are fire-and-forget messages that can have zero, one, or multiple handlers.
53- * The publish strategy determines how multiple handlers are executed (sequentially, in parallel, etc.)
37+ * The publishing strategy determines how multiple handlers are executed (sequentially, in parallel, etc.)
5438 * and how exceptions are handled.
5539 *
5640 * @param T The type of notification that extends Notification
5741 * @param notification The notification instance to publish
5842 * @param publishStrategy The strategy to use for publishing the notification.
5943 * Defaults to [PublishStrategy.DEFAULT] which stops on first exception.
60- * @throws Exception depending on the publish strategy:
44+ * @throws Exception depending on the publishing strategy:
6145 * - DEFAULT/StopOnException: throws the first exception encountered
6246 * - ContinueOnException: throws AggregateException if any handlers failed
6347 * - Parallel strategies: may throw exceptions from handlers
@@ -73,18 +57,17 @@ interface Mediator {
7357 /* *
7458 * Creates a new Mediator instance with the provided dependency provider.
7559 *
76- * The dependency provider is used to resolve handlers for queries, commands, and notifications.
60+ * The dependency provider is used to resolve handlers for requests and notifications.
7761 * It should be configured to provide instances of:
78- * - QueryHandler implementations for each query type
79- * - CommandHandler implementations for each command type
62+ * - RequestHandler implementations for each request type (queries and commands)
8063 * - NotificationHandler implementations for each notification type
64+ * - PipelineBehavior implementations for cross-cutting concerns
8165 *
8266 * @param dependencyProvider The dependency provider that will resolve handler instances
8367 * @return A configured Mediator instance ready for use
8468 *
8569 * @see DependencyProvider
86- * @see QueryHandler
87- * @see CommandHandler
70+ * @see RequestHandler
8871 * @see NotificationHandler
8972 */
9073 fun build (dependencyProvider : DependencyProvider ): Mediator = MediatorImpl (RegistryImpl (dependencyProvider))
0 commit comments