fix: Fixed `ConcurrentModificationException` when accessing a chat-room
authorKai Moritz <kai@juplo.de>
Wed, 28 Feb 2024 10:50:11 +0000 (11:50 +0100)
committerKai Moritz <kai@juplo.de>
Wed, 28 Feb 2024 16:45:32 +0000 (17:45 +0100)
commit0f13dc5e88722ca7c238258747041d9663251356
tree72b4c174b5780e308a6dfca245c430df15ef0584
parent300fb309b42aefecd475a75c946958e9b9316f7e
fix: Fixed `ConcurrentModificationException` when accessing a chat-room

* If a new chat-room was created, `InfoChannel` only reacted with the
  creation of the according `ChatRoomInfo`-instance.
* The creation of the accompanying `ChatRoomData`-instance through
  `DataChannel` was posponed until the new chat-room was accessed the
  first time.
* That way, `InfoChannel` did not need to know `DataChannel`, so that a
  cyclic dependency could be avoided.
* As a downside, this approach was open to a race-condition: if several
  accesses to the newly created chat-room happend in parallel, a
  `ConcurrentModificationException` was thrown, since the instance of
  `ChatRoomData` was created multiple times in parallel.
* To circumvent the locking, that would be necesarry to evade this race
  condition, the approach was refactored, so that `InfoChannel` now
  explicitly triggers the creation of the `ChatRoomData`-instance.
* To do so without introducing a cyclic dependency, the class
  `ChannelMediator` was introduced, so that `InfoChannel` and `DataChannel`
  need not to know each other.
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/ChannelMediator.java
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/DataChannel.java
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/InfoChannel.java
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java