Kai Moritz [Sun, 8 Jan 2023 20:30:57 +0000 (21:30 +0100)]
refactor: Moved business-logic from `ChatRoomService` into `ChatRoom`
- Some essential business-logic -- the identification of mutated messages --
was buried in `InMemoryChatRoomService`.
- This business-logic was moved into `ChatRoom`, becaus otherwise, it
would have been necessary, to reproduce this logic in each and every
new implementation of `ChatRoomService`, which would have been exhausting
and errorprone.
- This allowed also cleaner code in `InMemoryChatRoomService`, that
can focus on the persistence-logic.
- The implementation of `MessageMutationException` and the look of the
accompanying problem-details hat to be refined accordingly.
Kai Moritz [Sun, 8 Jan 2023 15:28:17 +0000 (16:28 +0100)]
refactor: Streamlined the API of the services
- `ChatRoomService` and `ChatHomeService` both return only reactive types.
- The decission stems from the wish, to become reactive all the way from
the client to the technical implementation of the backend-services.
- This faciliates the mapping of the results in `ChatBackendController`.
- The refactoring already simplified lots of code, where a `Flux` has
to derived from the `Stream`, yielding a good feeling about the plan,
that is pursued with this refactoring.
- The refactoring also lead to the decision that `UnknownChatroomException`
realy is a business-logic-exception (that according refactoring was
already performed in the previous commits, to ceap this commit clean).
Kai Moritz [Sun, 8 Jan 2023 16:14:56 +0000 (17:14 +0100)]
feat: Implemented problem-details for `UnknownChatroomException`
- Implemented an `@ExceptionHandler` for `UnknownChatroomException`.
- Implemented `ChatBackendControllerTest`
- Asserted, that the problem-details are generated as expected
- Pinned down problems, that yield a refactoring and have to
be resolved afterwards.
Kai Moritz [Sat, 7 Jan 2023 01:16:57 +0000 (02:16 +0100)]
fix: The sink is recreated, if it gets canceled
- The sink is automatically cancelled, if the last consumer leaves.
- Turning auto-cancel of, is not an option, because this buffers new
messages, until the buffer overflows, after which new messages are
droped. Hence, if a new subscriber arrives, it would see some old
messages and then, after a gap, current messages.
- Because of that, the sink is now automatically recreated, if the
last subscriber leaves and triggers the automatically cancelation
of the sink.
- The sink can be recreated without conflicts, because all methods,
that may access the sink are synchronized.
Kai Moritz [Wed, 28 Dec 2022 16:23:30 +0000 (17:23 +0100)]
refactor: Refined field-names of `Message` and `MessageTo`
- Choosed longer and more descriptive field-names for the domain-class
`Message`.
- Choosed short names for the TO-class `MessageTO`, which is serialized as
JSON.
Kai Moritz [Wed, 21 Dec 2022 17:57:23 +0000 (18:57 +0100)]
feat: implemented a listen-method for the chat-service based on a Flux
- Switched the return-type of `Chatroom.addMessage()` to `Mono<Message>`.
- Added an inner method, that "persists" the message and also returns
`Mono<Message>`.
- `addMessage()` calls `persistMessage()`, peeks into the subscription and
emits the `Message` to an internal `Sink.multy()` of the `Chatroom`.
- `Chatroom.listen()` creates a `Flux` from the internal Sink, so that
multiple subscribers can listen on the sink and all retrieve the current
messages in parallel.