From: Kai Moritz Date: Fri, 16 Sep 2022 09:27:42 +0000 (+0200) Subject: Code an die Version aus 'sumup-adder--springified' angepasst X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fsumup-adder--json;p=demos%2Fkafka%2Ftraining Code an die Version aus 'sumup-adder--springified' angepasst --- diff --git a/src/main/java/de/juplo/kafka/ApplicationRecordHandler.java b/src/main/java/de/juplo/kafka/ApplicationRecordHandler.java index 829ab0e..2829157 100644 --- a/src/main/java/de/juplo/kafka/ApplicationRecordHandler.java +++ b/src/main/java/de/juplo/kafka/ApplicationRecordHandler.java @@ -21,6 +21,24 @@ public class ApplicationRecordHandler implements RecordHandler private final Map state = new HashMap<>(); + public void addNumber( + Integer partition, + String user, + MessageAddNumber message) + { + state.get(partition).addToSum(user, message.getNext()); + } + + public void calculateSum( + Integer partition, + String user, + MessageCalculateSum message) + { + AdderResult result = state.get(partition).calculate(user); + log.info("{} - New result for {}: {}", id, user, result); + results.addResults(partition, user, result); + } + @Override public void accept(ConsumerRecord record) { @@ -31,14 +49,11 @@ public class ApplicationRecordHandler implements RecordHandler switch(message.getType()) { case ADD: - MessageAddNumber addNumber = (MessageAddNumber)message; - state.get(partition).addToSum(user, addNumber.getNext()); + addNumber(partition, user, (MessageAddNumber) message); break; case CALC: - AdderResult result = state.get(partition).calculate(user); - log.info("{} - New result for {}: {}", id, user, result); - results.addResults(partition, user, result); + calculateSum(partition, user, (MessageCalculateSum) message); break; }