X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2Fimplementation%2Finmemory%2FSimpleChatHomeService.java;h=8e3cc4305b3df480059eb4d934996f8c36f4bd7e;hb=900422dccb5a92fbceac34caa5e614b0d7f05ad7;hp=371d4a874f221cf9a0de810e531af14a83f5215e;hpb=ed777a6fb33ffc8b2cdb6cf7df9cce51c39d44da;p=demos%2Fkafka%2Fchat diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeService.java index 371d4a87..8e3cc430 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeService.java @@ -18,24 +18,24 @@ public class SimpleChatHomeService implements ChatHomeService private final Map chatRoomInfo; private final Map chatRoomData; private final Clock clock; - private final int bufferSize; + private final int historyLimit; public SimpleChatHomeService( Clock clock, - int bufferSize) + int historyLimit) { this( null, clock, - bufferSize); + historyLimit); } public SimpleChatHomeService( Integer shard, Clock clock, - int bufferSize) + int historyLimit) { log.debug("Creating SimpleChatHomeService"); @@ -43,7 +43,7 @@ public class SimpleChatHomeService implements ChatHomeService this.chatRoomInfo = new HashMap<>(); this.chatRoomData = new HashMap<>(); this.clock = clock; - this.bufferSize = bufferSize; + this.historyLimit = historyLimit; } @@ -76,29 +76,32 @@ public class SimpleChatHomeService implements ChatHomeService new InMemoryChatMessageService(chatRoomId); chatRoomInfo.put(chatRoomId, info); - chatRoomData.put( - info.getId(), + ChatRoomData chatRoomData = new ChatRoomData( clock, chatMessageService, - bufferSize)); + historyLimit); + chatRoomData.activate(); + this.chatRoomData.put(info.getId(), chatRoomData); return chatMessageService.restore(storageStrategy); }) - .then() - .doOnSuccess(empty -> log.info("Restored {}", this)) - .doOnError(throwable -> log.error("Could not restore {}", this)); + .count() + .doOnSuccess(count -> log.info("Restored {} with {} chat-rooms", this, count)) + .doOnError(throwable -> log.error("Could not restore {}", this)) + .then(); } @Override public Mono createChatRoom(UUID id, String name) { - log.info("Creating ChatRoom with buffer-size {}", bufferSize); + log.info("Creating ChatRoom with history-limit {}", historyLimit); ChatMessageService service = new InMemoryChatMessageService(id); ChatRoomInfo chatRoomInfo = new ChatRoomInfo(id, name, shard); this.chatRoomInfo.put(id, chatRoomInfo); - ChatRoomData chatRoomData = new ChatRoomData(clock, service, bufferSize); + ChatRoomData chatRoomData = new ChatRoomData(clock, service, historyLimit); + chatRoomData.activate(); this.chatRoomData.put(id, chatRoomData); return Mono.just(chatRoomInfo); }