From 5a8057d3bbf264df635a077d96b34389563e72fe Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 16 Sep 2022 11:27:42 +0200 Subject: [PATCH] Code an die Version aus 'sumup-adder--springified' angepasst --- .../juplo/kafka/ApplicationRecordHandler.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) 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; } -- 2.20.1