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>
Fri, 22 Mar 2024 10:33:32 +0000 (11:33 +0100)
commit8dbdc24311780e8d3829197975b3f20dbfa82616
treea135739a07ed701a3adf41dc4f041216108f3e6c
parentb1da0ca0f149cbff67962d05193048a17bd6ee4f
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