GRÜN: Implementierung der Erwartungen inkl. Anpassungen an der Anwendung
[demos/kafka/training] / src / main / java / de / juplo / kafka / ApplicationRecordHandler.java
index d0d385c..93e1297 100644 (file)
@@ -19,29 +19,23 @@ 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;
+      AdderResult 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)
+  protected void addPartition(Integer partition, Map<String, AdderResult> state)
   {
     this.state.put(partition, new AdderBusinessLogic(state));
   }
 
-  protected Map<String, Long> removePartition(Integer partition)
+  protected Map<String, AdderResult> removePartition(Integer partition)
   {
     return this.state.remove(partition).getState();
   }