GRÜN: Erwartungen implementiert
[demos/kafka/training] / src / main / java / de / juplo / kafka / SumBusinessLogic.java
1 package de.juplo.kafka;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6
7 public class SumBusinessLogic
8 {
9   private final Map<String, Long> state;
10
11
12   public SumBusinessLogic()
13   {
14     this(new HashMap<>());
15   }
16
17   public SumBusinessLogic(Map<String, Long> state)
18   {
19     this.state = state;
20   }
21
22
23   public synchronized void startSum(String user)
24   {
25     if (state.containsKey(user))
26       throw new IllegalStateException("Sumation for " + user + " already in progress, state: " + state.get(user));
27
28     state.put(user, 0l);
29   }
30 }