@Slf4j
class ChatHomeLoader
{
- private final long offsetOfFirstNewMessage;
+ private final long offsetOfFirstUnseenMessage;
private final ZoneId zoneId;
private final Map<UUID, KafkaChatRoomService> kafkaChatRoomServiceMap = new HashMap<>();
*/
boolean handleMessage(ConsumerRecord<UUID, MessageTo> record)
{
- if (record.offset() >= offsetOfFirstNewMessage)
+ Message.MessageKey messageKey = Message.MessageKey.of(
+ record.value().getUser(),
+ record.value().getId());
+
+ if (record.offset() >= offsetOfFirstUnseenMessage)
{
// All messages consumed: DONE!
- log.debug("I");
+ log.trace(
+ "Ignoring unseen message {}: topic={}, partition={}, offset={}",
+ messageKey,
+ record.topic(),
+ record.partition(),
+ record.offset());
return true;
}
});
service.addMessage(new Message(
- Message.MessageKey.of(
- record.value().getUser(),
- record.value().getId()),
+ messageKey,
record.offset(),
time,
record.value().getText()
private final Consumer<String, MessageTo> consumer;
private final String topic;
// private final long[] offsets; Erst mal immer alles neu einlesen
- private final Map<UUID, ChatRoom>[] chatrooms;
+ private final Map<UUID, KafkaChatRoomService>[] kafkaChatRoomServiceMaps;
+ private final Map<UUID, ChatRoom>[] chatRoomMaps;
public KafkaChatHomeService(
// {
// this.offsets[i] = 0l;
// }
- this.chatrooms = new Map[numShards];
+ this.kafkaChatRoomServiceMaps = new Map[numShards];
+ this.chatRoomMaps = new Map[numShards];
}
}
int partition = tp.partition();
+ kafkaChatRoomServiceMaps[partition] = new HashMap<>(); // TODO: reuse! Nicht immer alles neu laden
long unseenOffset = 0; // offsets[partition];
log.info(
currentOffset);
consumer.seek(tp, unseenOffset);
- chatrooms[partition]
+ chatRoomMaps[partition]
.values()
.stream()
handlers[partition] = new ChatRoomLoadingMessageHandlingStrategy(tp, currentOffset, unseenOffset);
(a, b) -> a.addAll(b));
for (int shard = 0; shard < numShards; shard++)
{
- chatrooms[shard] = owned.contains(shard)
+ chatRoomMaps[shard] = owned.contains(shard)
? new HashMap<>()
: null;
}
}
})
.toStream()
- .forEach(chatroom -> chatrooms[chatroom.getShard()].put(chatroom.getId(), chatroom));
+ .forEach(chatroom -> chatRoomMaps[chatroom.getShard()].put(chatroom.getId(), chatroom));
}
@Override
public Mono<ChatRoom> putChatRoom(ChatRoom chatRoom)
{
- chatrooms[chatRoom.getShard()].put(chatRoom.getId(), chatRoom);
+ chatRoomMaps[chatRoom.getShard()].put(chatRoom.getId(), chatRoom);
return Mono.just(chatRoom);
}
@Override
public Mono<ChatRoom> getChatRoom(int shard, UUID id)
{
- return Mono.justOrEmpty(chatrooms[shard].get(id));
+ return Mono.justOrEmpty(chatRoomMaps[shard].get(id));
}
@Override
public Flux<ChatRoom> getChatRooms(int shard)
{
- return Flux.fromStream(chatrooms[shard].values().stream());
+ return Flux.fromStream(chatRoomMaps[shard].values().stream());
}
}