ROT: Signatur für `AdderBusinessLogic` und neue Erwartungen formuliert
[demos/kafka/training] / src / main / java / de / juplo / kafka / ApplicationRecordHandler.java
index d0d385c..ce340a7 100644 (file)
@@ -19,21 +19,15 @@ public class ApplicationRecordHandler implements RecordHandler<String, String>
     Integer partition = record.partition();
     String user = record.key();
     String message = record.value();
-    switch (message)
+
+    if (message.equals("CALCULATE"))
     {
-      case "START":
-        state.get(partition).startSum(user);
-        break;
-
-      case "END":
-        Long result = state.get(partition).endSum(user);
-        log.info("New result for {}: {}", user, result);
-        break;
-
-      default:
-        state.get(partition).addToSum(user, Integer.parseInt(message));
-        break;
+      Long result = state.get(partition).calculate(user);
+      log.info("New result for {}: {}", user, result);
+      return;
     }
+
+    state.get(partition).addToSum(user, Integer.parseInt(message));
   }
 
   protected void addPartition(Integer partition, Map<String, Long> state)